}
/**
- * Return the preferred Data field with the given name, or NULL if none.
+ * Return the preferred Data field with the given name, the first one if
+ * none is preferred, or NULL if none at all.
*
* @param name
* the name to look for
- * @return the Data field, or NULL
+ *
+ * @return the {@link Data} field, or NULL
*/
public Data getPreferredData(String name) {
- Data first = null;
+ Data pref = null;
+ int ipref = Integer.MAX_VALUE;
for (Data data : getData(name)) {
- if (first == null)
- first = data;
+ if (pref == null)
+ pref = data;
- if (data.isPreferred())
- return data;
+ if (data.getPreferred() < ipref)
+ pref = data;
}
- return first;
+ return pref;
}
/**
}
/**
- * Check if this {@link Data} has the "preferred" flag.
+ * Return the preferred value of this {@link Data}, or
+ * {@link Integer#MAX_VALUE} if none.
*
- * @return TRUE if it has
+ * @return the preferred value
*/
- public boolean isPreferred() {
+ public int getPreferred() {
for (TypeInfo type : this) {
- if (type.getName().equals("TYPE") && type.getValue().equals("pref")) {
- return true;
+ if (type.getName().equals("PRE")) {
+ try {
+ return Integer.parseInt(type.getValue());
+ } catch (NumberFormatException e) {
+ e.printStackTrace();
+ }
}
}
- return false;
+ return Integer.MAX_VALUE;
}
/**
String field = info.substring(index + 1);
if (all) {
+ Data pref = contact.getPreferredData(field);
for (Data data : contact.getData(field)) {
- if (data.isPreferred()) {
+ if (data == pref) {
infoPanel.addComponent(UiColors.createLabel(el,
StringUtils.padString(label, labelSize)
+ data.toString()));