X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Fjvcard%2FData.java;h=4d3da7e4c7d37f0aa3bd1754065cfbcbdc0e4872;hb=7671a2499e6f0d6c8e0765b36c18c1e89bc457c5;hp=d6ba628d3353fa2f1b22d0f1440790a06c268631;hpb=aecb3399b756d2ba04223bc6f553999fce73f9fb;p=jvcard.git diff --git a/src/be/nikiroo/jvcard/Data.java b/src/be/nikiroo/jvcard/Data.java index d6ba628..4d3da7e 100644 --- a/src/be/nikiroo/jvcard/Data.java +++ b/src/be/nikiroo/jvcard/Data.java @@ -71,25 +71,33 @@ public class Data extends BaseClass { public String getValue() { return unescape(value); } - + /** - * Return the RAW value of this {@link Data} + * Change the value of this {@link Data} * - * @return the RAW value + * @param value + * the new value + */ + public void setValue(String value) { + setRawValue(escape(value)); + } + + /** + * Return the raw value of this {@link Data} + * + * @return the raw value */ public String getRawValue() { return value; } /** - * Change the value of this {@link Data} + * Change the raw value of this {@link Data} * * @param value - * the new value + * the new raw value */ - public void setValue(String value) { - value = escape(value); - + public void setRawValue(String value) { if ((value == null && this.value != null) || (value != null && !value.equals(this.value))) { this.value = value; @@ -178,18 +186,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; } /** @@ -232,11 +245,13 @@ public class Data extends BaseClass { for (int i = 0; i < value.length(); i++) { if (value.charAt(i) == sep && (i == 0 || value.charAt(i - 1) != '\\')) { - rep.add(value.substring(last, i - last)); + rep.add(value.substring(last, i)); + last = i + 1; } } - rep.add(value.substring(last)); + if (last < value.length()) + rep.add(value.substring(last)); } return rep;