New SAVE_TO option
[jvcard.git] / src / be / nikiroo / jvcard / Data.java
index ba5fde5df13a9d86381b965aa1487d702ff61be8..fa9e7c25223d5563ce12693708b24f36b90bcbe9 100644 (file)
@@ -9,7 +9,7 @@ import java.util.List;
  * basically a key/value pair with optional types and an optional group name.
  * 
  * @author niki
- *
+ * 
  */
 public class Data extends BaseClass<TypeInfo> {
        public enum DataPart {
@@ -186,18 +186,23 @@ public class Data extends BaseClass<TypeInfo> {
        }
 
        /**
-        * 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;
        }
 
        /**
@@ -288,4 +293,17 @@ public class Data extends BaseClass<TypeInfo> {
        public String getState() {
                return ("" + name + value + group).replace(' ', '_');
        }
+
+       @Override
+       public String toString() {
+               String out = name + ": " + value;
+               if (group != null && !group.isEmpty()) {
+                       out += " (" + group + ")";
+               }
+               if (b64 >= 0) {
+                       out += " [" + b64 + "]";
+               }
+
+               return out;
+       }
 }