X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Fjvcard%2FData.java;h=0484adef9c5b339d270c7b8ad6256a80625299d3;hb=HEAD;hp=ba5fde5df13a9d86381b965aa1487d702ff61be8;hpb=30a4aa17f2141ad80a23447ee2e6303f6c9ef995;p=jvcard.git diff --git a/src/be/nikiroo/jvcard/Data.java b/src/be/nikiroo/jvcard/Data.java index ba5fde5..0484ade 100644 --- a/src/be/nikiroo/jvcard/Data.java +++ b/src/be/nikiroo/jvcard/Data.java @@ -5,19 +5,21 @@ import java.util.LinkedList; import java.util.List; /** - * A data is a piece of information present in a {@link Contact}. It is + * A {@link Data} is a piece of information present in a {@link Contact}. It is * basically a key/value pair with optional types and an optional group name. + *

+ * A {@link Data} can also be binary encoded: in this case, it has an associated + * BKey number to identify it. * * @author niki - * */ public class Data extends BaseClass { public enum DataPart { FN_FAMILY, FN_GIVEN, FN_ADDITIONAL, // Name FN_PRE, FN_POST, // Pre/Post BDAY_YYYY, BDAY_MM, BDAY_DD, // BDay + // Address: ADR_PBOX, ADR_EXTENDED, ADR_STREET, ADR_CITY, ADR_REGION, ADR_POSTAL_CODE, ADR_COUNTRY - // Address } private String name; @@ -169,15 +171,18 @@ public class Data extends BaseClass { /** * Return the bkey number of this {@link Data} or -1 if it is not binary. + *

+ * For binary data, as long as the BKey is not processed, it will be 0. * - * @return the bkey or -1 + * @return the bkey, 0 or -1 */ public int getB64Key() { return b64; } /** - * Check if this {@link Data} is binary + * Check if this {@link Data} is binary (in this case, the BKey will be + * present). * * @return TRUE if it is */ @@ -186,18 +191,23 @@ public class Data extends BaseClass { } /** - * 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; } /** @@ -223,6 +233,9 @@ public class Data extends BaseClass { /** * Return the {@link List} of sep-listed values from this {@link String} * data. + *

+ * Will take the backslash character into account (i.e., a backslash can + * escape the given separator). * * @param value * the data @@ -288,4 +301,17 @@ public class Data extends BaseClass { 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; + } }