1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 package org.archive.util.anvl;
26
27
28 /***
29 * ANVL 'data element'.
30 * Made of a lone {@link Label}, or a {@link Label} plus {@link Value}.
31 *
32 * @author stack
33 * @see <a
34 * href="http://www.cdlib.org/inside/diglib/ark/anvlspec.pdf">A Name-Value
35 * Language (ANVL)</a>
36 */
37 class Element {
38 private final SubElement [] subElements;
39
40 public Element(final Label l) {
41 this.subElements = new SubElement [] {l};
42 }
43
44 public Element(final Label l, final Value v) {
45 this.subElements = new SubElement [] {l, v};
46 }
47
48 public boolean isValue() {
49 return this.subElements.length > 1;
50 }
51
52 public Label getLabel() {
53 return (Label)this.subElements[0];
54 }
55
56 public Value getValue() {
57 if (!isValue()) {
58 return null;
59 }
60 return (Value)this.subElements[1];
61 }
62
63 @Override
64 public String toString() {
65 StringBuilder sb = new StringBuilder();
66 for (int i = 0; i < subElements.length; i++) {
67 sb.append(subElements[i].toString());
68 if (i == 0) {
69
70 sb.append(':');
71 if (isValue()) {
72
73 sb.append(' ');
74 }
75 }
76 }
77 return sb.toString();
78 }
79 }