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.utgenome.gwt.utgb.client.util.xml;
26
27 import java.util.ArrayList;
28
29 public class XMLAttribute {
30 class Pair {
31 private String name;
32 private String value;
33
34 Pair(String name, String value) {
35 this.name = name;
36 this.value = value;
37 }
38
39 @Override
40 public String toString() {
41 return name + "=\"" + XMLWriter.escape(value) + "\"";
42 }
43 }
44
45 private ArrayList<Pair> attributeTable = new ArrayList<Pair>();
46
47 public XMLAttribute() {
48
49 }
50
51 public XMLAttribute(String name, String value) {
52 attributeTable.add(new Pair(name, value));
53 }
54
55 public XMLAttribute add(String name, String value) {
56 attributeTable.add(new Pair(name, value));
57 return this;
58 }
59
60 public XMLAttribute add(String name, int value) {
61 attributeTable.add(new Pair(name, Integer.toString(value)));
62 return this;
63 }
64
65 public XMLAttribute add(String name, long value) {
66 attributeTable.add(new Pair(name, Long.toString(value)));
67 return this;
68 }
69
70 public XMLAttribute add(String name, boolean value) {
71 attributeTable.add(new Pair(name, value ? "true" : "false"));
72 return this;
73 }
74
75 @Override
76 public String toString() {
77 StringBuffer buffer = new StringBuffer();
78 int i = 0;
79 for (; i < attributeTable.size() - 1; i++) {
80 Pair pair = attributeTable.get(i);
81 buffer.append(pair.toString());
82 buffer.append(" ");
83 }
84 if (i < attributeTable.size())
85 buffer.append(attributeTable.get(i).toString());
86 return buffer.toString();
87 }
88
89 }