1 7 8 package javax.accessibility; 9 10 import java.util.Vector ; 11 import java.util.Locale ; 12 import java.util.MissingResourceException ; 13 import java.util.ResourceBundle ; 14 15 25 public class AccessibleRelationSet { 26 27 38 protected Vector <AccessibleRelation > relations = null; 39 40 43 public AccessibleRelationSet() { 44 relations = null; 45 } 46 47 54 public AccessibleRelationSet(AccessibleRelation [] relations) { 55 if (relations.length != 0) { 56 this.relations = new Vector (relations.length); 57 for (int i = 0; i < relations.length; i++) { 58 add(relations[i]); 59 } 60 } 61 } 62 63 73 public boolean add(AccessibleRelation relation) { 74 if (relations == null) { 75 relations = new Vector (); 76 } 77 78 AccessibleRelation existingRelation = get(relation.getKey()); 80 if (existingRelation == null) { 81 relations.addElement(relation); 82 return true; 83 } else { 84 Object [] existingTarget = existingRelation.getTarget(); 85 Object [] newTarget = relation.getTarget(); 86 int mergedLength = existingTarget.length + newTarget.length; 87 Object [] mergedTarget = new Object [mergedLength]; 88 for (int i = 0; i < existingTarget.length; i++) { 89 mergedTarget[i] = existingTarget[i]; 90 } 91 for (int i = existingTarget.length, j = 0; 92 i < mergedLength; 93 i++, j++) { 94 mergedTarget[i] = newTarget[j]; 95 } 96 existingRelation.setTarget(mergedTarget); 97 } 98 return true; 99 } 100 101 107 public void addAll(AccessibleRelation [] relations) { 108 if (relations.length != 0) { 109 if (this.relations == null) { 110 this.relations = new Vector (relations.length); 111 } 112 for (int i = 0; i < relations.length; i++) { 113 add(relations[i]); 114 } 115 } 116 } 117 118 129 public boolean remove(AccessibleRelation relation) { 130 if (relations == null) { 131 return false; 132 } else { 133 return relations.removeElement(relation); 134 } 135 } 136 137 140 public void clear() { 141 if (relations != null) { 142 relations.removeAllElements(); 143 } 144 } 145 146 149 public int size() { 150 if (relations == null) { 151 return 0; 152 } else { 153 return relations.size(); 154 } 155 } 156 157 163 public boolean contains(String key) { 164 return get(key) != null; 165 } 166 167 173 public AccessibleRelation get(String key) { 174 if (relations == null) { 175 return null; 176 } else { 177 int len = relations.size(); 178 for (int i = 0; i < len; i++) { 179 AccessibleRelation relation = 180 (AccessibleRelation )relations.elementAt(i); 181 if (relation != null && relation.getKey().equals(key)) { 182 return relation; 183 } 184 } 185 return null; 186 } 187 } 188 189 193 public AccessibleRelation [] toArray() { 194 if (relations == null) { 195 return new AccessibleRelation [0]; 196 } else { 197 AccessibleRelation [] relationArray 198 = new AccessibleRelation [relations.size()]; 199 for (int i = 0; i < relationArray.length; i++) { 200 relationArray[i] = (AccessibleRelation ) relations.elementAt(i); 201 } 202 return relationArray; 203 } 204 } 205 206 213 public String toString() { 214 String ret = ""; 215 if ((relations != null) && (relations.size() > 0)) { 216 ret = ((AccessibleRelation ) (relations.elementAt(0))).toDisplayString(); 217 for (int i = 1; i < relations.size(); i++) { 218 ret = ret + "," 219 + ((AccessibleRelation ) (relations.elementAt(i))). 220 toDisplayString(); 221 } 222 } 223 return ret; 224 } 225 } 226
| Popular Tags
|