ImmutableDescriptor (Java Platform SE 8 ) (original) (raw)
- javax.management.ImmutableDescriptor
All Implemented Interfaces:
Serializable, Cloneable, Descriptor
public class ImmutableDescriptor
extends Object
implements Descriptor
An immutable descriptor.
Since:
1.6
See Also:
Serialized Form
Field Summary
Fields
Modifier and Type Field Description static ImmutableDescriptor EMPTY_DESCRIPTOR An empty descriptor. Constructor Summary
Constructors
Constructor Description ImmutableDescriptor(Map<String,?> fields) Construct a descriptor where the names and values of the fields are the keys and values of the given Map. ImmutableDescriptor(String... fields) Construct a descriptor containing the given fields. ImmutableDescriptor(String[] fieldNames,Object[] fieldValues) Construct a descriptor containing the given fields and values. Method Summary
All Methods Static Methods Instance Methods Concrete Methods
Modifier and Type Method Description Descriptor clone() Returns a descriptor which is equal to this descriptor. boolean equals(Object o) Compares this descriptor to the given object. String[] getFieldNames() Returns all the field names in the descriptor. String[] getFields() Returns all of the fields contained in this descriptor as a string array. Object getFieldValue(String fieldName) Returns the value for a specific field name, or null if no value is present for that name. Object[] getFieldValues(String... fieldNames) Returns all the field values in the descriptor as an array of Objects. int hashCode() Returns the hash code value for this descriptor. boolean isValid() Returns true if all of the fields have legal values given their names. void removeField(String fieldName) Removes a field from the descriptor. void setField(String fieldName,Object fieldValue) This operation is unsupported since this class is immutable. void setFields(String[] fieldNames,Object[] fieldValues) This operation is unsupported since this class is immutable. String toString() Returns a string representation of the object. static ImmutableDescriptor union(Descriptor... descriptors) Return an ImmutableDescriptor whose contents are the union of the given descriptors. * ### Methods inherited from class java.lang.[Object](../../java/lang/Object.html "class in java.lang") `[finalize](../../java/lang/Object.html#finalize--), [getClass](../../java/lang/Object.html#getClass--), [notify](../../java/lang/Object.html#notify--), [notifyAll](../../java/lang/Object.html#notifyAll--), [wait](../../java/lang/Object.html#wait--), [wait](../../java/lang/Object.html#wait-long-), [wait](../../java/lang/Object.html#wait-long-int-)`
Field Detail
* #### EMPTY\_DESCRIPTOR public static final [ImmutableDescriptor](../../javax/management/ImmutableDescriptor.html "class in javax.management") EMPTY_DESCRIPTOR An empty descriptor.
Constructor Detail
* #### ImmutableDescriptor public ImmutableDescriptor([String](../../java/lang/String.html "class in java.lang")[] fieldNames, [Object](../../java/lang/Object.html "class in java.lang")[] fieldValues) Construct a descriptor containing the given fields and values. Throws: `[IllegalArgumentException](../../java/lang/IllegalArgumentException.html "class in java.lang")` \- 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. * #### ImmutableDescriptor public ImmutableDescriptor([String](../../java/lang/String.html "class in java.lang")... 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`. Throws: `[IllegalArgumentException](../../java/lang/IllegalArgumentException.html "class in java.lang")` \- 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. * #### ImmutableDescriptor public ImmutableDescriptor([Map](../../java/util/Map.html "interface in java.util")<[String](../../java/lang/String.html "class in java.lang"),?> fields) Construct a descriptor where the names and values of the fields are the keys and values of the given Map. Throws: `[IllegalArgumentException](../../java/lang/IllegalArgumentException.html "class in java.lang")` \- 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
* #### union public static [ImmutableDescriptor](../../javax/management/ImmutableDescriptor.html "class in javax.management") union([Descriptor](../../javax/management/Descriptor.html "interface in javax.management")... 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` \- the descriptors to be combined. Any of the descriptors can be null, in which case it is skipped. 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. Throws: `[IllegalArgumentException](../../java/lang/IllegalArgumentException.html "class in java.lang")` \- 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\[\])](../../java/util/Arrays.html#deepEquals-java.lang.Object:A-java.lang.Object:A-) returns true. * #### getFieldValue public final [Object](../../java/lang/Object.html "class in java.lang") getFieldValue([String](../../java/lang/String.html "class in java.lang") fieldName) Description copied from interface: `[Descriptor](../../javax/management/Descriptor.html#getFieldValue-java.lang.String-)` Returns the value for a specific field name, or null if no value is present for that name. Specified by: `[getFieldValue](../../javax/management/Descriptor.html#getFieldValue-java.lang.String-)` in interface `[Descriptor](../../javax/management/Descriptor.html "interface in javax.management")` Parameters: `fieldName` \- the field name. Returns: the corresponding value, or null if the field is not present. * #### getFields public final [String](../../java/lang/String.html "class in java.lang")[] getFields() Description copied from interface: `[Descriptor](../../javax/management/Descriptor.html#getFields--)` Returns all of the fields contained in this descriptor as a string array. Specified by: `[getFields](../../javax/management/Descriptor.html#getFields--)` in interface `[Descriptor](../../javax/management/Descriptor.html "interface in javax.management")` Returns: String array of fields in the format _fieldName=fieldValue_ If the value of a field is not a String, then the toString() method will be called on it and the returned value, enclosed in parentheses, used as the value for the field in the returned array. If the value of a field is null, then the value of the field in the returned array will be empty. If the descriptor is empty, you will get an empty array. See Also: [Descriptor.setFields(java.lang.String\[\], java.lang.Object\[\])](../../javax/management/Descriptor.html#setFields-java.lang.String:A-java.lang.Object:A-) * #### getFieldValues public final [Object](../../java/lang/Object.html "class in java.lang")[] getFieldValues([String](../../java/lang/String.html "class in java.lang")... fieldNames) Description copied from interface: `[Descriptor](../../javax/management/Descriptor.html#getFieldValues-java.lang.String...-)` 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. Specified by: `[getFieldValues](../../javax/management/Descriptor.html#getFieldValues-java.lang.String...-)` in interface `[Descriptor](../../javax/management/Descriptor.html "interface in javax.management")` Parameters: `fieldNames` \- String array of the names of the fields that the values should be returned for. If the array is empty then an empty array will be returned. If the array is null then all values will be returned, as if the parameter were the array returned by [Descriptor.getFieldNames()](../../javax/management/Descriptor.html#getFieldNames--). If a field name in the array does not exist, including the case where it is null or the empty string, then null is returned for the matching array element being returned. Returns: Object array of field values. If the list of `fieldNames` is empty, you will get an empty array. * #### getFieldNames public final [String](../../java/lang/String.html "class in java.lang")[] getFieldNames() Description copied from interface: `[Descriptor](../../javax/management/Descriptor.html#getFieldNames--)` Returns all the field names in the descriptor. Specified by: `[getFieldNames](../../javax/management/Descriptor.html#getFieldNames--)` in interface `[Descriptor](../../javax/management/Descriptor.html "interface in javax.management")` Returns: String array of field names. If the descriptor is empty, you will get an empty array. * #### equals public boolean equals([Object](../../java/lang/Object.html "class in java.lang") o) 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\[\])](../../java/util/Arrays.html#deepEquals-java.lang.Object:A-java.lang.Object:A-) must return true. * Otherwise [Object.equals(Object)](../../java/lang/Object.html#equals-java.lang.Object-) must return true. Specified by: `[equals](../../javax/management/Descriptor.html#equals-java.lang.Object-)` in interface `[Descriptor](../../javax/management/Descriptor.html "interface in javax.management")` Overrides: `[equals](../../java/lang/Object.html#equals-java.lang.Object-)` in class `[Object](../../java/lang/Object.html "class in java.lang")` Parameters: `o` \- the object to compare with. Returns: `true` if the objects are the same; `false` otherwise. See Also: [Object.hashCode()](../../java/lang/Object.html#hashCode--), [HashMap](../../java/util/HashMap.html "class in java.util") * #### hashCode public int 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\[\])](../../java/util/Arrays.html#deepHashCode-java.lang.Object:A-). * Otherwise `h` is `v.hashCode()`. Specified by: `[hashCode](../../javax/management/Descriptor.html#hashCode--)` in interface `[Descriptor](../../javax/management/Descriptor.html "interface in javax.management")` Overrides: `[hashCode](../../java/lang/Object.html#hashCode--)` in class `[Object](../../java/lang/Object.html "class in java.lang")` Returns: A hash code value for this object. See Also: [Object.equals(java.lang.Object)](../../java/lang/Object.html#equals-java.lang.Object-), [System.identityHashCode(java.lang.Object)](../../java/lang/System.html#identityHashCode-java.lang.Object-) * #### toString public [String](../../java/lang/String.html "class in java.lang") toString() Description copied from class: `[Object](../../java/lang/Object.html#toString--)` Returns a string representation of the object. In general, the`toString` method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method. The `toString` method for class `Object` returns a string consisting of the name of the class of which the object is an instance, the at-sign character \` `@`', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of: > getClass().getName() + '@' + Integer.toHexString(hashCode()) > Overrides: `[toString](../../java/lang/Object.html#toString--)` in class `[Object](../../java/lang/Object.html "class in java.lang")` Returns: a string representation of the object. * #### isValid public boolean 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. Specified by: `[isValid](../../javax/management/Descriptor.html#isValid--)` in interface `[Descriptor](../../javax/management/Descriptor.html "interface in javax.management")` Returns: true if the values are legal. Throws: `[RuntimeOperationsException](../../javax/management/RuntimeOperationsException.html "class in javax.management")` \- 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. * #### clone public [Descriptor](../../javax/management/Descriptor.html "interface in javax.management") 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. Specified by: `[clone](../../javax/management/Descriptor.html#clone--)` in interface `[Descriptor](../../javax/management/Descriptor.html "interface in javax.management")` Overrides: `[clone](../../java/lang/Object.html#clone--)` in class `[Object](../../java/lang/Object.html "class in java.lang")` Returns: a clone of this instance. Throws: `[RuntimeOperationsException](../../javax/management/RuntimeOperationsException.html "class in javax.management")` \- for illegal value for field Names or field Values. If the descriptor construction fails for any reason, this exception will be thrown. See Also: [Cloneable](../../java/lang/Cloneable.html "interface in java.lang") * #### setFields public final void setFields([String](../../java/lang/String.html "class in java.lang")[] fieldNames, [Object](../../java/lang/Object.html "class in java.lang")[] fieldValues) throws [RuntimeOperationsException](../../javax/management/RuntimeOperationsException.html "class in javax.management") This operation is unsupported since this class is immutable. If this call would change a mutable descriptor with the same contents, then a [RuntimeOperationsException](../../javax/management/RuntimeOperationsException.html "class in javax.management") wrapping an[UnsupportedOperationException](../../java/lang/UnsupportedOperationException.html "class in java.lang") 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. Specified by: `[setFields](../../javax/management/Descriptor.html#setFields-java.lang.String:A-java.lang.Object:A-)` in interface `[Descriptor](../../javax/management/Descriptor.html "interface in javax.management")` Parameters: `fieldNames` \- String array of field names. The array and array elements cannot be null. `fieldValues` \- Object array of the corresponding field values. The array cannot be null. Elements of the array can be null. Throws: `[RuntimeOperationsException](../../javax/management/RuntimeOperationsException.html "class in javax.management")` \- if the change fails for any reason. Wrapped exception is [IllegalArgumentException](../../java/lang/IllegalArgumentException.html "class in java.lang") 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](../../java/lang/UnsupportedOperationException.html "class in java.lang") if the descriptor is immutable, and the call would change its contents. See Also: [Descriptor.getFields()](../../javax/management/Descriptor.html#getFields--) * #### setField public final void setField([String](../../java/lang/String.html "class in java.lang") fieldName, [Object](../../java/lang/Object.html "class in java.lang") fieldValue) throws [RuntimeOperationsException](../../javax/management/RuntimeOperationsException.html "class in javax.management") This operation is unsupported since this class is immutable. If this call would change a mutable descriptor with the same contents, then a [RuntimeOperationsException](../../javax/management/RuntimeOperationsException.html "class in javax.management") wrapping an[UnsupportedOperationException](../../java/lang/UnsupportedOperationException.html "class in java.lang") 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. Specified by: `[setField](../../javax/management/Descriptor.html#setField-java.lang.String-java.lang.Object-)` in interface `[Descriptor](../../javax/management/Descriptor.html "interface in javax.management")` Parameters: `fieldName` \- The field name to be set. Cannot be null or empty. `fieldValue` \- The field value to be set for the field name. Can be null if that is a valid value for the field. Throws: `[RuntimeOperationsException](../../javax/management/RuntimeOperationsException.html "class in javax.management")` \- if the field name or field value is illegal (wrapped exception is [IllegalArgumentException](../../java/lang/IllegalArgumentException.html "class in java.lang")); or if the descriptor is immutable (wrapped exception is[UnsupportedOperationException](../../java/lang/UnsupportedOperationException.html "class in java.lang")). * #### removeField public final void removeField([String](../../java/lang/String.html "class in java.lang") fieldName) Removes a field from the descriptor. Specified by: `[removeField](../../javax/management/Descriptor.html#removeField-java.lang.String-)` in interface `[Descriptor](../../javax/management/Descriptor.html "interface in javax.management")` Parameters: `fieldName` \- String name of the field to be removed. If the field name is illegal or the field is not found, no exception is thrown. Throws: `[RuntimeOperationsException](../../javax/management/RuntimeOperationsException.html "class in javax.management")` \- if a field of the given name exists and the descriptor is immutable. The wrapped exception will be an [UnsupportedOperationException](../../java/lang/UnsupportedOperationException.html "class in java.lang").
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2025, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.