APIdia Launch Partner
Top Description Fields Constructors Methods
javax.management

public Class ImmutableDescriptor

extends Object
implements Descriptor
Class Inheritance
All Implemented Interfaces
javax.management.Descriptor, java.lang.Cloneable, java.io.Serializable
Imports
com.sun.jmx.mbeanserver.Util, java.io.InvalidObjectException, java.lang.reflect.Array, java.util.Arrays, .Comparator, .Map, .SortedMap, .TreeMap

An immutable descriptor.
Since
1.6

Field Summary

Modifier and TypeField and Description
public static final ImmutableDescriptor
EMPTY_DESCRIPTOR

An empty descriptor.

private transient int
private final String[]
private static final long
private final Object[]

Constructor Summary

AccessConstructor and Description
public
ImmutableDescriptor(String[]
the field names
fieldNames
,
Object[]
the field values
fieldValues
)

Construct a descriptor containing the given fields and values.

public
ImmutableDescriptor(String...
the field names
fields
)

Construct a descriptor containing the given fields.

public
ImmutableDescriptor(Map<String, ?>
the field names and values
fields
)

Construct a descriptor where the names and values of the fields are the keys and values of the given Map.

Method Summary

Modifier and TypeMethod and Description
private static void
public Descriptor
clone()

Overrides java.lang.Object.clone.

Implements javax.management.Descriptor.clone.

Returns a descriptor which is equal to this descriptor.

public boolean
equals(Object o)

Overrides java.lang.Object.equals.

Implements javax.management.Descriptor.equals.

Compares this descriptor to the given object.

private int
private static int
findNonEmpty(Descriptor[] ds, int start)

public final String[]
getFieldNames()

Implements javax.management.Descriptor.getFieldNames.

Returns all the field names in the descriptor.

public final String[]
getFields()

Implements javax.management.Descriptor.getFields.

Returns all of the fields contained in this descriptor as a string array.

public final Object
getFieldValue(String fieldName)

Implements javax.management.Descriptor.getFieldValue.

Returns the value for a specific field name, or null if no value is present for that name.

public final Object[]
getFieldValues(String... fieldNames)

Implements javax.management.Descriptor.getFieldValues.

Returns all the field values in the descriptor as an array of Objects.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Implements javax.management.Descriptor.hashCode.

Returns the hash code value for this descriptor.

private static void
illegal(String message)

private static boolean
public boolean

Returns:

true if the values are legal.
isValid
()

Implements javax.management.Descriptor.isValid.

Returns true if all of the fields have legal values given their names.

private static SortedMap<String, ?>
makeMap(String[] fieldNames, Object[] fieldValues)

private static SortedMap<String, ?>
makeMap(String[] fields)

pack-priv static Descriptor
private Object

Returns:

the replacement object, which may be this.
readResolve
()

This method can replace a deserialized instance of this class with another instance.

public final void
removeField(String
String name of the field to be removed. If the field name is illegal or the field is not found, no exception is thrown.
fieldName
)

Implements javax.management.Descriptor.removeField.

Removes a field from the descriptor.

public final void
setField(String fieldName, Object fieldValue)

Implements javax.management.Descriptor.setField.

This operation is unsupported since this class is immutable.

public final void
setFields(String[] fieldNames, Object[] fieldValues)

Implements javax.management.Descriptor.setFields.

This operation is unsupported since this class is immutable.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

public static ImmutableDescriptor

Returns:

an ImmutableDescriptor that is the union of the given descriptors. The returned object may be identical to one of the input descriptors if it is an ImmutableDescriptor that contains all of the required fields.
union
(Descriptor...
the descriptors to be combined. Any of the descriptors can be null, in which case it is skipped.
descriptors
)

Return an ImmutableDescriptor whose contents are the union of the given descriptors.

private static void
Inherited from java.lang.Object:
finalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

EMPTY_DESCRIPTORback to summary
public static final ImmutableDescriptor EMPTY_DESCRIPTOR

An empty descriptor.

hashCodeback to summary
private transient int hashCode
namesback to summary
private final String[] names
serialVersionUIDback to summary
private static final long serialVersionUID
valuesback to summary
private final Object[] values
Annotations
@SuppressWarnings:serial

Constructor Detail

ImmutableDescriptorback to summary
public ImmutableDescriptor(String[] fieldNames, Object[] fieldValues)

Construct a descriptor containing the given fields and values.

Parameters
fieldNames:String[]

the field names

fieldValues:Object[]

the field values

Exceptions
IllegalArgumentException:
if either array is null, or if the arrays have different sizes, or if a field name is null or empty, or if the same field name appears more than once.
ImmutableDescriptorback to summary
public ImmutableDescriptor(String... fields)

Construct a descriptor containing the given fields. Each String must be of the form fieldName=fieldValue. The field name ends at the first = character; for example if the String is a=b=c then the field name is a and its value is b=c.

Parameters
fields:String[]

the field names

Exceptions
IllegalArgumentException:
if the parameter is null, or if a field name is empty, or if the same field name appears more than once, or if one of the strings does not contain an = character.
ImmutableDescriptorback to summary
public ImmutableDescriptor(Map<String, ?> fields)

Construct a descriptor where the names and values of the fields are the keys and values of the given Map.

Parameters
fields:Map<String, ?>

the field names and values

Exceptions
IllegalArgumentException:
if the parameter is null, or if a field name is null or empty, or if the same field name appears more than once (which can happen because field names are not case sensitive).

Method Detail

checkIllegalFieldNameback to summary
private static void checkIllegalFieldName(String name)
cloneback to summary
public Descriptor clone()

Overrides java.lang.Object.clone.

Implements javax.management.Descriptor.clone.

Returns a descriptor which is equal to this descriptor. Changes to the returned descriptor will have no effect on this descriptor, and vice versa.

This method returns the object on which it is called. A subclass can override it to return another object provided the contract is respected.

Annotations
@Override
Exceptions
RuntimeOperationsException:
for illegal value for field Names or field Values. If the descriptor construction fails for any reason, this exception will be thrown.
equalsback to summary
public boolean equals(Object o)

Overrides java.lang.Object.equals.

Implements javax.management.Descriptor.equals.

Doc from javax.management.Descriptor.equals.

Compares this descriptor to the given object. The objects are equal if the given object is also a Descriptor, and if the two Descriptors have the same field names (possibly differing in case) and the same associated values. The respective values for a field in the two Descriptors are equal if the following conditions hold:

  • If one value is null then the other must be too.
  • If one value is a primitive array then the other must be a primitive array of the same type with the same elements.
  • If one value is an object array then the other must be too and Arrays#deepEquals(Object[], Object[]) must return true.
  • Otherwise Object#equals(Object) must return true.
Annotations
@Override
fieldIndexback to summary
private int fieldIndex(String name)
findNonEmptyback to summary
private static int findNonEmpty(Descriptor[] ds, int start)
getFieldNamesback to summary
public final String[] getFieldNames()

Implements javax.management.Descriptor.getFieldNames.

Doc from javax.management.Descriptor.getFieldNames.

Returns all the field names in the descriptor.

getFieldsback to summary
public final String[] getFields()

Implements javax.management.Descriptor.getFields.

Doc from javax.management.Descriptor.getFields.

Returns all of the fields contained in this descriptor as a string array.

getFieldValueback to summary
public final Object getFieldValue(String fieldName)

Implements javax.management.Descriptor.getFieldValue.

Doc from javax.management.Descriptor.getFieldValue.

Returns the value for a specific field name, or null if no value is present for that name.

getFieldValuesback to summary
public final Object[] getFieldValues(String... fieldNames)

Implements javax.management.Descriptor.getFieldValues.

Doc from javax.management.Descriptor.getFieldValues.

Returns all the field values in the descriptor as an array of Objects. The returned values are in the same order as the fieldNames String array parameter.

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Implements javax.management.Descriptor.hashCode.

Doc from javax.management.Descriptor.hashCode.

Returns the hash code value for this descriptor. The hash code is computed as the sum of the hash codes for each field in the descriptor. The hash code of a field with name n and value v is n.toLowerCase().hashCode() ^ h. Here h is the hash code of v, computed as follows:

  • If v is null then h is 0.
  • If v is a primitive array then h is computed using the appropriate overloading of java.util.Arrays.hashCode.
  • If v is an object array then h is computed using Arrays#deepHashCode(Object[]).
  • Otherwise h is v.hashCode().
Annotations
@Override
illegalback to summary
private static void illegal(String message)
isEmptyback to summary
private static boolean isEmpty(Descriptor d)
isValidback to summary
public boolean isValid()

Implements javax.management.Descriptor.isValid.

Returns true if all of the fields have legal values given their names. This method always returns true, but a subclass can override it to return false when appropriate.

Returns:boolean

true if the values are legal.

Exceptions
RuntimeOperationsException:
if the validity checking fails. The method returns false if the descriptor is not valid, but throws this exception if the attempt to determine validity fails.
makeMapback to summary
private static SortedMap<String, ?> makeMap(String[] fieldNames, Object[] fieldValues)
makeMapback to summary
private static SortedMap<String, ?> makeMap(String[] fields)
nonNullDescriptorback to summary
pack-priv static Descriptor nonNullDescriptor(Descriptor d)
readResolveback to summary
private Object readResolve() throws InvalidObjectException

This method can replace a deserialized instance of this class with another instance. For example, it might replace a deserialized empty ImmutableDescriptor with EMPTY_DESCRIPTOR.

Returns:Object

the replacement object, which may be this.

Exceptions
InvalidObjectException:
if the read object has invalid fields.
removeFieldback to summary
public final void removeField(String fieldName)

Implements javax.management.Descriptor.removeField.

Removes a field from the descriptor.

Parameters
fieldName:String

String name of the field to be removed. If the field name is illegal or the field is not found, no exception is thrown.

Exceptions
RuntimeOperationsException:
if a field of the given name exists and the descriptor is immutable. The wrapped exception will be an UnsupportedOperationException.
setFieldback to summary
public final void setField(String fieldName, Object fieldValue) throws RuntimeOperationsException

Implements javax.management.Descriptor.setField.

This operation is unsupported since this class is immutable. If this call would change a mutable descriptor with the same contents, then a RuntimeOperationsException wrapping an UnsupportedOperationException is thrown. Otherwise, the behavior is the same as it would be for a mutable descriptor: either an exception is thrown because of illegal parameters, or there is no effect.

Exceptions
RuntimeOperationsException:

Doc from javax.management.Descriptor.setField.

if the field name or field value is illegal (wrapped exception is IllegalArgumentException); or if the descriptor is immutable (wrapped exception is UnsupportedOperationException).

setFieldsback to summary
public final void setFields(String[] fieldNames, Object[] fieldValues) throws RuntimeOperationsException

Implements javax.management.Descriptor.setFields.

This operation is unsupported since this class is immutable. If this call would change a mutable descriptor with the same contents, then a RuntimeOperationsException wrapping an UnsupportedOperationException is thrown. Otherwise, the behavior is the same as it would be for a mutable descriptor: either an exception is thrown because of illegal parameters, or there is no effect.

Exceptions
RuntimeOperationsException:

Doc from javax.management.Descriptor.setFields.

if the change fails for any reason. Wrapped exception is IllegalArgumentException if fieldNames or fieldValues is null, or if the arrays are of different lengths, or if there is an illegal value in one of them. Wrapped exception is UnsupportedOperationException if the descriptor is immutable, and the call would change its contents.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Annotations
@Override
unionback to summary
public static ImmutableDescriptor union(Descriptor... descriptors)

Return an ImmutableDescriptor whose contents are the union of the given descriptors. Every field name that appears in any of the descriptors will appear in the result with the value that it has when the method is called. Subsequent changes to any of the descriptors do not affect the ImmutableDescriptor returned here.

In the simplest case, there is only one descriptor and the returned ImmutableDescriptor is a copy of its fields at the time this method is called:

Descriptor d = something();
ImmutableDescriptor copy = ImmutableDescriptor.union(d);
Parameters
descriptors:Descriptor[]

the descriptors to be combined. Any of the descriptors can be null, in which case it is skipped.

Returns:ImmutableDescriptor

an ImmutableDescriptor that is the union of the given descriptors. The returned object may be identical to one of the input descriptors if it is an ImmutableDescriptor that contains all of the required fields.

Exceptions
IllegalArgumentException:
if two Descriptors contain the same field name with different associated values. Primitive array values are considered the same if they are of the same type with the same elements. Object array values are considered the same if Arrays#deepEquals(Object[], Object[]) returns true.
unsupportedback to summary
private static void unsupported()