X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Fjvcard%2FData.java;h=5c09a13419c1177167f4b2b1cb7bcea1fab68dbb;hb=e4444b0bc462544629d9e7e7ab62b96a4d9cab10;hp=3f62b7e8f0f6158aff806a4baa06ff2b59ef8dc2;hpb=ce822a7cd8ff95a031e477e37d23c114228cc5b6;p=jvcard.git diff --git a/src/be/nikiroo/jvcard/Data.java b/src/be/nikiroo/jvcard/Data.java index 3f62b7e..5c09a13 100644 --- a/src/be/nikiroo/jvcard/Data.java +++ b/src/be/nikiroo/jvcard/Data.java @@ -1,30 +1,50 @@ package be.nikiroo.jvcard; import java.security.InvalidParameterException; -import java.util.LinkedList; import java.util.List; -public class Data { +/** + * A 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. + * + * @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 + ADR_PBOX, ADR_EXTENDED, ADR_STREET, ADR_CITY, ADR_REGION, ADR_POSTAL_CODE, ADR_COUNTRY + // Address + } + private String name; private String value; private String group; private int b64; // -1 = no, 0 = still not ordered, the rest is order - private List types; - private boolean dirty; - private Contact parent; + /** + * Create a new {@link Data} with the given values. + * + * @param types + * the types of this {@link Data} + * @param name + * its name (MUST NOT be NULL) + * @param value + * its value (MUST NOT be NULL) + * @param group + * its group if any (or NULL if none) + */ public Data(List types, String name, String value, String group) { - if (types == null) { - types = new LinkedList(); - } + super(types); - this.types = types; - this.name = name; - this.value = value; + this.name = name.toUpperCase(); + this.value = value.toString(); // crash NOW if null this.group = group; b64 = -1; - for (TypeInfo type : types) { + for (TypeInfo type : this) { if (type.getName().equals("ENCODING") && type.getValue().equals("b")) { b64 = 0; @@ -33,18 +53,30 @@ public class Data { } } - public List getTypes() { - return types; - } - + /** + * Return the name of this {@link Data} + * + * @return the name + */ public String getName() { return name; } + /** + * Return the value of this {@link Data} + * + * @return the value + */ public String getValue() { return value; } + /** + * Change the value of this {@link Data} + * + * @param value + * the new value + */ public void setValue(String value) { if ((value == null && this.value != null) || (value != null && !value.equals(this.value))) { @@ -53,14 +85,47 @@ public class Data { } } + /** + * Return the group of this {@link Data} + * + * @return the group + */ public String getGroup() { return group; } + /** + * Change the group of this {@link Data} + * + * @param group + * the new group + */ + public void setGroup(String group) { + if ((group == null && this.group != null) + || (group != null && !group.equals(this.group))) { + this.group = group; + setDirty(); + } + } + + /** + * Return the bkey number of this {@link Data} or -1 if it is not binary. + * + * @return the bkey or -1 + */ public int getB64Key() { return b64; } + /** + * Change the bkey of this {@link Data} + * + * @param i + * the new bkey + * + * @throw InvalidParameterException if the {@link Data} is not binary or if + * it is but you try to set a negative bkey + */ void resetB64Key(int i) { if (!isBinary()) throw new InvalidParameterException( @@ -72,37 +137,22 @@ public class Data { b64 = i; } - public boolean isBinary() { - return b64 >= 0; - } - - public boolean isDirty() { - return dirty; - } - /** - * Notify that this element has unsaved changes, and notify its parent of - * the same if any. + * Check if this {@link Data} is binary + * + * @return TRUE if it is */ - protected void setDirty() { - this.dirty = true; - if (this.parent != null) - this.parent.setDirty(); + public boolean isBinary() { + return b64 >= 0; } - /** - * Notify this element and all its descendants that it is in pristine - * state (as opposed to dirty). - */ - void setPristine() { - dirty = false; - for (TypeInfo type : types) { - // TODO ? - } + @Override + public String getId() { + return "" + name; } - void setParent(Contact parent) { - this.parent = parent; + @Override + public String getState() { + return ("" + name + value + group).replace(' ', '_'); } - }