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 java.lang.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 fromObject
. Property objects that are not equal according toequals
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 Summary
Constructors Modifier Constructor Description protected
Property(java.lang.String name)
Constructs a property with the given name.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description T
defaultValue()
Returns the "default value" for this property.boolean
equals(java.lang.Object obj)
static <T> Property<T>
get(java.lang.String name, java.lang.Class<T> type)
Returns a property with the given name and type.java.lang.String
getName()
Returns the name of this property.java.lang.Class<T>
getRawType()
Returns the raw type of this property.java.lang.reflect.Type
getType()
Returns the type of this property.int
hashCode()
java.lang.String
toString()
Property<T>
withDefault(T defaultValue)
Returns a copy of this property with a new default value.
-
-
-
Constructor Detail
-
Property
protected Property(java.lang.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 (notnull
)- See Also:
get(String, Class)
-
-
Method Detail
-
get
public static <T> Property<T> get(java.lang.String name, java.lang.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 returnnull
).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 (notnull
)type
- the type of the property (notnull
)- 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 benull
)- Returns:
- a copy of this property with a new default value
(never
null
)
-
getName
public final java.lang.String getName()
Returns the name of this property.- Returns:
- the property name (never
null
)
-
getType
public final java.lang.reflect.Type getType()
Returns the type of this property.- Returns:
- the property type (never
null
)
-
getRawType
public final java.lang.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(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public final int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-