TabularTypepublic class TabularType extends OpenType implements SerializableThe TabularType class is the open type class
whose instances describe the types of {@link TabularData TabularData } values. |
Fields Summary |
---|
static final long | serialVersionUID | private CompositeType | rowType | private List | indexNames | private transient Integer | myHashCode | private transient String | myToString |
Constructors Summary |
---|
public TabularType(String typeName, String description, CompositeType rowType, String[] indexNames)Constructs a TabularType instance, checking for the validity of the given parameters.
The validity constraints are described below for each parameter.
The Java class name of tabular data values this tabular type represents
(ie the class name returned by the {@link OpenType#getClassName() getClassName} method)
is set to the string value returned by TabularData.class.getName() .
// need only be calculated once.
/* *** Constructor *** */
// Check and initialize state defined by parent.
//
super(TabularData.class.getName(), typeName, description);
// Check rowType is not null
//
if (rowType == null) {
throw new IllegalArgumentException("Argument rowType cannot be null.");
}
// Check indexNames is neither null nor empty and does not contain any null element or empty string
//
checkForNullElement(indexNames, "indexNames");
checkForEmptyString(indexNames, "indexNames");
// Check all indexNames values are valid item names for rowType
//
for (int i=0; i<indexNames.length; i++) {
if ( ! rowType.containsKey(indexNames[i]) ) {
throw new OpenDataException("Argument's element value indexNames["+ i +"]=\""+ indexNames[i] +
"\" is not a valid item name for rowType.");
}
}
// initialize rowType
//
this.rowType = rowType;
// initialize indexNames
// (copy content so that subsequent modif to the array referenced by the indexNames parameter have no impact)
//
ArrayList tmpList = new ArrayList(indexNames.length + 1);
for (int i=0; i<indexNames.length; i++) {
tmpList.add(indexNames[i]);
}
this.indexNames = Collections.unmodifiableList(tmpList);
|
Methods Summary |
---|
private static void | checkForEmptyString(java.lang.String[] arg, java.lang.String argName)Checks that String[] does not contain any empty (or blank characters only) string.
for (int i=0; i<arg.length; i++) {
if (arg[i].trim().equals("")) {
throw new IllegalArgumentException("Argument's element "+ argName +"["+ i +"] cannot be an empty string.");
}
}
| private static void | checkForNullElement(java.lang.Object[] arg, java.lang.String argName)Checks that Object[] arg is neither null nor empty (ie length==0)
and that it does not contain any null element.
if ( (arg == null) || (arg.length == 0) ) {
throw new IllegalArgumentException("Argument "+ argName +"[] cannot be null or empty.");
}
for (int i=0; i<arg.length; i++) {
if (arg[i] == null) {
throw new IllegalArgumentException("Argument's element "+ argName +"["+ i +"] cannot be null.");
}
}
| public boolean | equals(java.lang.Object obj)Compares the specified obj parameter with this TabularType instance for equality.
Two TabularType instances are equal if and only if all of the following statements are true:
- their type names are equal
- their row types are equal
- they use the same index names, in the same order
// if obj is null, return false
//
if (obj == null) {
return false;
}
// if obj is not a TabularType, return false
//
TabularType other;
try {
other = (TabularType) obj;
} catch (ClassCastException e) {
return false;
}
// Now, really test for equality between this TabularType instance and the other:
//
// their names should be equal
if ( ! this.getTypeName().equals(other.getTypeName()) ) {
return false;
}
// their row types should be equal
if ( ! this.rowType.equals(other.rowType) ) {
return false;
}
// their index names should be equal and in the same order (ensured by List.equals())
if ( ! this.indexNames.equals(other.indexNames) ) {
return false;
}
// All tests for equality were successfull
//
return true;
| public java.util.List | getIndexNames()Returns, in the same order as was given to this instance's
constructor, an unmodifiable List of the names of the items the
values of which are used to uniquely index each row element of
tabular data values described by this TabularType
instance.
return indexNames;
| public javax.management.openmbean.CompositeType | getRowType()Returns the type of the row elements of tabular data values
described by this TabularType instance.
return rowType;
| public int | hashCode()Returns the hash code value for this TabularType instance.
The hash code of a TabularType instance is the sum of the hash codes
of all elements of information used in equals comparisons
(ie: name, row type, index names).
This ensures that t1.equals(t2) implies that t1.hashCode()==t2.hashCode()
for any two TabularType instances t1 and t2 ,
as required by the general contract of the method
{@link Object#hashCode() Object.hashCode()}.
As TabularType instances are immutable, the hash code for this instance is calculated once,
on the first call to hashCode , and then the same value is returned for subsequent calls.
// Calculate the hash code value if it has not yet been done (ie 1st call to hashCode())
//
if (myHashCode == null) {
int value = 0;
value += this.getTypeName().hashCode();
value += this.rowType.hashCode();
for (Iterator k = indexNames.iterator(); k.hasNext(); ) {
value += k.next().hashCode();
}
myHashCode = new Integer(value);
}
// return always the same hash code for this instance (immutable)
//
return myHashCode.intValue();
| public boolean | isValue(java.lang.Object obj)Tests whether obj is a value which could be described by this TabularType instance.
If obj is null or is not an instance of javax.management.openmbean.TabularData ,
isValue returns false .
If obj is an instance of javax.management.openmbean.TabularData ,
its tabular type is tested for equality with this tabular type instance, and isValue
returns true if and only if {@link #equals(java.lang.Object) equals }
returns true .
// if obj is null, return false
//
if (obj == null) {
return false;
}
// if obj is not a TabularData, return false
//
TabularData value;
try {
value = (TabularData) obj;
} catch (ClassCastException e) {
return false;
}
// test value's TabularType for equality with this TabularType instance
//
return this.equals(value.getTabularType());
| public java.lang.String | toString()Returns a string representation of this TabularType instance.
The string representation consists of the name of this class (ie javax.management.openmbean.TabularType ),
the type name for this instance, the row type string representation of this instance,
and the index names of this instance.
As TabularType instances are immutable, the string representation for this instance is calculated once,
on the first call to toString , and then the same value is returned for subsequent calls.
// Calculate the string representation if it has not yet been done (ie 1st call to toString())
//
if (myToString == null) {
StringBuffer result = new StringBuffer()
.append(this.getClass().getName())
.append("(name=")
.append(getTypeName())
.append(",rowType=")
.append(rowType.toString())
.append(",indexNames=(");
int i=0;
Iterator k = indexNames.iterator();
while( k.hasNext() ) {
if (i > 0) result.append(",");
result.append(k.next().toString());
i++;
}
result.append("))");
myToString = result.toString();
}
// return always the same string representation for this instance (immutable)
//
return myToString;
|
|