1 7 8 9 package javax.management.openmbean; 10 11 12 import java.io.Serializable ; 15 import java.util.List ; 16 import java.util.Iterator ; 17 import java.util.Arrays ; 18 import java.util.ArrayList ; 19 import java.util.Collections ; 20 21 24 25 35 public class TabularType 36 extends OpenType 37 implements Serializable { 38 39 40 41 static final long serialVersionUID = 6554071860220659261L; 42 43 44 47 private CompositeType rowType; 48 49 53 private List indexNames; 54 55 56 private transient Integer myHashCode = null; private transient String myToString = null; 59 60 61 62 95 public TabularType(String typeName, 96 String description, 97 CompositeType rowType, 98 String [] indexNames) throws OpenDataException { 99 100 super(TabularData .class.getName(), typeName, description); 103 104 if (rowType == null) { 107 throw new IllegalArgumentException ("Argument rowType cannot be null."); 108 } 109 110 checkForNullElement(indexNames, "indexNames"); 113 checkForEmptyString(indexNames, "indexNames"); 114 115 for (int i=0; i<indexNames.length; i++) { 118 if ( ! rowType.containsKey(indexNames[i]) ) { 119 throw new OpenDataException ("Argument's element value indexNames["+ i +"]=\""+ indexNames[i] + 120 "\" is not a valid item name for rowType."); 121 } 122 } 123 124 this.rowType = rowType; 127 128 ArrayList tmpList = new ArrayList (indexNames.length + 1); 132 for (int i=0; i<indexNames.length; i++) { 133 tmpList.add(indexNames[i]); 134 } 135 this.indexNames = Collections.unmodifiableList(tmpList); 136 } 137 138 142 private static void checkForNullElement(Object [] arg, String argName) { 143 if ( (arg == null) || (arg.length == 0) ) { 144 throw new IllegalArgumentException ("Argument "+ argName +"[] cannot be null or empty."); 145 } 146 for (int i=0; i<arg.length; i++) { 147 if (arg[i] == null) { 148 throw new IllegalArgumentException ("Argument's element "+ argName +"["+ i +"] cannot be null."); 149 } 150 } 151 } 152 153 156 private static void checkForEmptyString(String [] arg, String argName) { 157 for (int i=0; i<arg.length; i++) { 158 if (arg[i].trim().equals("")) { 159 throw new IllegalArgumentException ("Argument's element "+ argName +"["+ i +"] cannot be an empty string."); 160 } 161 } 162 } 163 164 165 166 167 173 public CompositeType getRowType() { 174 175 return rowType; 176 } 177 178 189 public List getIndexNames() { 190 191 return indexNames; 192 } 193 194 208 public boolean isValue(Object obj) { 209 210 if (obj == null) { 213 return false; 214 } 215 216 TabularData value; 219 try { 220 value = (TabularData ) obj; 221 } catch (ClassCastException e) { 222 return false; 223 } 224 225 return this.equals(value.getTabularType()); 228 } 229 230 231 232 233 248 public boolean equals(Object obj) { 249 250 if (obj == null) { 253 return false; 254 } 255 256 TabularType other; 259 try { 260 other = (TabularType ) obj; 261 } catch (ClassCastException e) { 262 return false; 263 } 264 265 268 if ( ! this.getTypeName().equals(other.getTypeName()) ) { 270 return false; 271 } 272 273 if ( ! this.rowType.equals(other.rowType) ) { 275 return false; 276 } 277 278 if ( ! this.indexNames.equals(other.indexNames) ) { 280 return false; 281 } 282 283 return true; 286 } 287 288 304 public int hashCode() { 305 306 if (myHashCode == null) { 309 int value = 0; 310 value += this.getTypeName().hashCode(); 311 value += this.rowType.hashCode(); 312 for (Iterator k = indexNames.iterator(); k.hasNext(); ) { 313 value += k.next().hashCode(); 314 } 315 myHashCode = new Integer (value); 316 } 317 318 return myHashCode.intValue(); 321 } 322 323 335 public String toString() { 336 337 if (myToString == null) { 340 StringBuffer result = new StringBuffer () 341 .append(this.getClass().getName()) 342 .append("(name=") 343 .append(getTypeName()) 344 .append(",rowType=") 345 .append(rowType.toString()) 346 .append(",indexNames=("); 347 int i=0; 348 Iterator k = indexNames.iterator(); 349 while( k.hasNext() ) { 350 if (i > 0) result.append(","); 351 result.append(k.next().toString()); 352 i++; 353 } 354 result.append("))"); 355 myToString = result.toString(); 356 } 357 358 return myToString; 361 } 362 363 } 364 | Popular Tags |