T - the property typepublic abstract class BaseProperty<T> extends Object implements Property<T>
Property. All properties should extend from this class.
This base implementation makes interacting with properties null safe by guaranteeing that the default value
and its determined value can never be null.
| Constructor and Description |
|---|
BaseProperty(String path,
T defaultValue)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
PropertyValue<T> |
determineValue(PropertyReader reader)
Returns the value, based on the given reader, which should be used for this property.
|
T |
getDefaultValue()
Returns the default value of this property.
|
protected abstract T |
getFromReader(PropertyReader reader,
ConvertErrorRecorder errorRecorder)
Constructs the value of the property from the property reader.
|
String |
getPath() |
boolean |
isValidValue(T value)
Returns whether the value can be associated to the given property, i.e.
|
String |
toString() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitisValidInResource, toExportValuepublic String getPath()
public T getDefaultValue()
PropertygetDefaultValue in interface Property<T>public PropertyValue<T> determineValue(PropertyReader reader)
PropertyBaseProperty never return null. The return value must be in sync with
Property.isValidValue(Object).determineValue in interface Property<T>reader - the reader to construct the value from (if possible)public boolean isValidValue(T value)
Property
This method is used in ConfigurationDataImpl.setValue(ch.jalu.configme.properties.Property<T>, T), which
throws an exception if this method returns false. Therefore, this method is intended as a last catch
for invalid values and to ensure that programmatically no invalid value can be set. Extended validation of
values encountered in the property reader should be preferably handled in Property.determineValue(ch.jalu.configme.resource.PropertyReader),
or in an extension of MigrationService.
isValidValue in interface Property<T>value - the value to check@Nullable protected abstract T getFromReader(PropertyReader reader, ConvertErrorRecorder errorRecorder)
reader - the reader to read fromerrorRecorder - error recorder to register errors even if a valid value is returnedCopyright © 2016–2021 The AuthMe Team. All rights reserved.