Serializable, Cloneable, Descriptor
public class ImmutableDescriptor extends Object implements Descriptor
| Modifier and Type | Field | Description | 
|---|---|---|
| static final ImmutableDescriptor | EMPTY_DESCRIPTOR | An empty descriptor. | 
| Constructor | Description | 
|---|---|
| ImmutableDescriptor | Construct a descriptor containing the given fields. | 
| ImmutableDescriptor | Construct a descriptor containing the given fields and values. | 
| ImmutableDescriptor | Construct a descriptor where the names and values of the fields are the keys and values of the given Map. | 
| Modifier and Type | Method | Description | 
|---|---|---|
| Descriptor | clone() | Returns a descriptor which is equal to this descriptor. | 
| boolean | equals | Compares this descriptor to the given object. | 
| final String[] | getFieldNames() | Returns all the field names in the descriptor. | 
| final String[] | getFields() | Returns all of the fields contained in this descriptor as a string array. | 
| final Object | getFieldValue | Returns the value for a specific field name, or null if no value is present for that name. | 
| final Object[] | getFieldValues | 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. | 
| final void | removeField | Removes a field from the descriptor. | 
| final void | setField | This operation is unsupported since this class is immutable. | 
| final void | setFields | This operation is unsupported since this class is immutable. | 
| static ImmutableDescriptor | union | Return an  ImmutableDescriptorwhose contents are the union of the given descriptors. | 
public static final ImmutableDescriptor EMPTY_DESCRIPTOR
public ImmutableDescriptor(String[] fieldNames, Object[] fieldValues)
fieldNames - the field namesfieldValues - the field valuesIllegalArgumentException - 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.public ImmutableDescriptor(String... fields)
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.fields - the field namesIllegalArgumentException - 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.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.
fields - the field names and valuesIllegalArgumentException - 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).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);
descriptors - the descriptors to be combined. Any of the descriptors can be null, in which case it is skipped.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.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.public final Object getFieldValue(String fieldName)
DescriptorgetFieldValue in interface Descriptor
fieldName - the field name.public final String[] getFields()
DescriptorgetFields in interface Descriptor
public final Object[] getFieldValues(String... fieldNames)
DescriptorfieldNames String array parameter.getFieldValues in interface Descriptor
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(). 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.fieldNames is empty, you will get an empty array.public final String[] getFieldNames()
DescriptorgetFieldNames in interface Descriptor
public boolean equals(Object o)
Arrays.deepEquals(Object[],Object[]) must return true.Object.equals(Object) must return true.equals in interface Descriptor
equals in class Object
o - the object to compare with.true if the objects are the same; false otherwise.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:
v is null then h is 0.v is a primitive array then h is computed using the appropriate overloading of java.util.Arrays.hashCode.v is an object array then h is computed using Arrays.deepHashCode(Object[]).h is v.hashCode().hashCode in interface Descriptor
hashCode in class Object
public boolean isValid()
isValid in interface Descriptor
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.public 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.
clone in interface Descriptor
clone in class Object
RuntimeOperationsException - for illegal value for field Names or field Values. If the descriptor construction fails for any reason, this exception will be thrown.public final void setFields(String[] fieldNames, Object[] fieldValues) throws RuntimeOperationsException
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.setFields in interface Descriptor
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.RuntimeOperationsException - 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.public final void setField(String fieldName, Object fieldValue) throws RuntimeOperationsException
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.setField in interface Descriptor
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.RuntimeOperationsException - if the field name or field value is illegal (wrapped exception is IllegalArgumentException); or if the descriptor is immutable (wrapped exception is UnsupportedOperationException).public final void removeField(String fieldName)
removeField in interface Descriptor
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.RuntimeOperationsException - if a field of the given name exists and the descriptor is immutable. The wrapped exception will be an UnsupportedOperationException.
    © 1993, 2023, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
    https://docs.oracle.com/en/java/javase/21/docs/api/java.management/javax/management/ImmutableDescriptor.html