1 package be
.nikiroo
.jvcard
;
3 import java
.security
.InvalidParameterException
;
4 import java
.util
.LinkedList
;
8 * A data is a piece of information present in a {@link Contact}. It is
9 * basically a key/value pair with optional types and an optional group name.
15 public enum DataPart
{
16 FN_FAMILY
, FN_GIVEN
, FN_ADDITIONAL
, // Name
17 FN_PRE
, FN_POST
, // Pre/Post
18 BDAY_YYYY
, BDAY_MM
, BDAY_DD
, // BDay
19 ADR_PBOX
, ADR_EXTENDED
, ADR_STREET
, ADR_CITY
, ADR_REGION
, ADR_POSTAL_CODE
, ADR_COUNTRY
26 private int b64
; // -1 = no, 0 = still not ordered, the rest is order
27 private List
<TypeInfo
> types
;
28 private boolean dirty
;
29 private Contact parent
;
32 * Create a new {@link Data} with the given values.
35 * the types of this {@link Data}
43 public Data(List
<TypeInfo
> types
, String name
, String value
, String group
) {
45 types
= new LinkedList
<TypeInfo
>();
54 for (TypeInfo type
: types
) {
56 if (type
.getName().equals("ENCODING")
57 && type
.getValue().equals("b")) {
65 * Return the number of {@link TypeInfo} present in this {@link Data}.
67 * @return the number of {@link TypeInfo}s
74 * Return the {@link TypeInfo} at index <i>index</i>.
77 * the index of the {@link TypeInfo} to find
79 * @return the {@link TypeInfo}
81 * @throws IndexOutOfBoundsException
82 * if the index is < 0 or >= {@link Data#size()}
84 public TypeInfo
get(int index
) {
85 return types
.get(index
);
89 * Return the name of this {@link Data}
93 public String
getName() {
98 * Return the value of this {@link Data}
102 public String
getValue() {
107 * Change the value of this {@link Data}
112 public void setValue(String value
) {
113 if ((value
== null && this.value
!= null)
114 || (value
!= null && !value
.equals(this.value
))) {
121 * Return the group of this {@link Data}
125 public String
getGroup() {
130 * Return the bkey number of this {@link Data} or -1 if it is not binary.
132 * @return the bkey or -1
134 public int getB64Key() {
139 * Change the bkey of this {@link Data}
144 * @throw InvalidParameterException if the {@link Data} is not binary or if
145 * it is but you try to set a negative bkey
147 void resetB64Key(int i
) {
149 throw new InvalidParameterException(
150 "Cannot add a BKey on a non-binary object");
152 throw new InvalidParameterException(
153 "Cannot remove the BKey on a binary object");
159 * Check if this {@link Data} is binary
161 * @return TRUE if it is
163 public boolean isBinary() {
168 * Check if this {@link Data} has unsaved changes.
170 * @return TRUE if it has
172 public boolean isDirty() {
177 * Notify that this element has unsaved changes, and notify its parent of
180 protected void setDirty() {
182 if (this.parent
!= null)
183 this.parent
.setDirty();
187 * Notify this element <i>and all its descendants</i> that it is in pristine
188 * state (as opposed to dirty).
192 for (TypeInfo type
: types
) {
198 * Set the parent of this {@link Data}.
203 void setParent(Contact parent
) {
204 this.parent
= parent
;