| 1 | package be.nikiroo.jvcard; |
| 2 | |
| 3 | import java.security.InvalidParameterException; |
| 4 | import java.util.LinkedList; |
| 5 | import java.util.List; |
| 6 | |
| 7 | public class Data { |
| 8 | private String name; |
| 9 | private String value; |
| 10 | private String group; |
| 11 | private int b64; // -1 = no, 0 = still not ordered, the rest is order |
| 12 | private List<TypeInfo> types; |
| 13 | private boolean dirty; |
| 14 | private Contact parent; |
| 15 | |
| 16 | public Data(List<TypeInfo> types, String name, String value, String group) { |
| 17 | if (types == null) { |
| 18 | types = new LinkedList<TypeInfo>(); |
| 19 | } |
| 20 | |
| 21 | this.types = types; |
| 22 | this.name = name; |
| 23 | this.value = value; |
| 24 | this.group = group; |
| 25 | |
| 26 | b64 = -1; |
| 27 | for (TypeInfo type : types) { |
| 28 | if (type.getName().equals("ENCODING") |
| 29 | && type.getValue().equals("b")) { |
| 30 | b64 = 0; |
| 31 | break; |
| 32 | } |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | public List<TypeInfo> getTypes() { |
| 37 | return types; |
| 38 | } |
| 39 | |
| 40 | public String getName() { |
| 41 | return name; |
| 42 | } |
| 43 | |
| 44 | public String getValue() { |
| 45 | return value; |
| 46 | } |
| 47 | |
| 48 | public String getGroup() { |
| 49 | return group; |
| 50 | } |
| 51 | |
| 52 | public int getB64Key() { |
| 53 | return b64; |
| 54 | } |
| 55 | |
| 56 | void resetB64Key(int i) { |
| 57 | if (!isBinary()) |
| 58 | throw new InvalidParameterException( |
| 59 | "Cannot add a BKey on a non-binary object"); |
| 60 | if (i < 0) |
| 61 | throw new InvalidParameterException( |
| 62 | "Cannot remove the BKey on a binary object"); |
| 63 | |
| 64 | b64 = i; |
| 65 | } |
| 66 | |
| 67 | public boolean isBinary() { |
| 68 | return b64 >= 0; |
| 69 | } |
| 70 | |
| 71 | public boolean isDirty() { |
| 72 | return dirty; |
| 73 | } |
| 74 | |
| 75 | public void setParent(Contact parent) { |
| 76 | this.parent = parent; |
| 77 | } |
| 78 | } |