Class Property<T>

java.lang.Object
org.eclipse.handly.util.Property<T>
Type Parameters:
T - the type of the property

public class Property<T> extends Object
Represents a named property of a given type. The type information is retained and can be retrieved at runtime. The property can provide a default value.

All properties share the default implementation of equals inherited from Object. Property objects that are not equal according to equals may still be "functionally equal" and used interchangeably, depending on the usage context. Such equivalence relations need to be specified on a case-by-case basis.

  • Constructor Details

    • Property

      protected Property(String name)
      Constructs a property with the given name. The type information is captured implicitly.

      The protected constructor forces clients to create a subclass of this class which enables retrieval of the actual type argument at runtime.

      For example, to create a property of type List<String>, you can create an empty anonymous inner class:

      Property<List<String>> p1 = new Property<List<String>>("p1") {};

      Parameters:
      name - the name of the property (not null)
      See Also:
  • Method Details

    • get

      public static <T> Property<T> get(String name, Class<T> type)
      Returns a property with the given name and type. The type is represented by a specified class object. The returned property has no default value (i.e., defaultValue() will always return null).

      If the type of property values is not generic, using this method of obtaining a property might be preferable to using the constructor as it avoids creating a subclass for the property.

      Type Parameters:
      T - the type of the property
      Parameters:
      name - the name of the property (not null)
      type - the type of the property (not null)
      Returns:
      a property with the given name and type (never null)
    • withDefault

      public Property<T> withDefault(T defaultValue)
      Returns a copy of this property with a new default value.

      This property is immutable and is unaffected by this method call.

      Parameters:
      defaultValue - the default value (may be null)
      Returns:
      a copy of this property with a new default value (never null)
    • getName

      public final String getName()
      Returns the name of this property.
      Returns:
      the property name (never null)
    • getType

      public final Type getType()
      Returns the type of this property.
      Returns:
      the property type (never null)
    • getRawType

      public final Class<T> getRawType()
      Returns the raw type of this property.
      Returns:
      the property raw type (never null)
    • defaultValue

      public T defaultValue()
      Returns the "default value" for this property.
      Returns:
      the default value (may be null)
    • equals

      public final boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public final int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object