public class RaftProperties extends Object
| Constructor and Description |
|---|
RaftProperties()
A new configuration.
|
RaftProperties(RaftProperties other)
A new RaftProperties with the same settings cloned from another.
|
| Modifier and Type | Method and Description |
|---|---|
void |
clear()
Clears all keys from the configuration.
|
String |
get(String name)
Get the value of the
name property, null if
no such property exists. |
String |
get(String name,
String defaultValue)
Get the value of the
name. |
boolean |
getBoolean(String name,
boolean defaultValue)
Get the value of the
name property as a boolean. |
Class<?> |
getClass(String name,
Class<?> defaultValue)
Get the value of the
name property as a Class. |
<BASE> Class<? extends BASE> |
getClass(String name,
Class<? extends BASE> defaultValue,
Class<BASE> xface)
Get the value of the
name property as a Class
implementing the interface specified by xface. |
Class<?>[] |
getClasses(String name,
Class<?>... defaultValue)
Get the value of the
name property
as an array of Class. |
double |
getDouble(String name,
double defaultValue)
Get the value of the
name property as a double. |
<T extends Enum<T>> |
getEnum(String name,
T defaultValue)
Return value matching this enumerated type.
|
File |
getFile(String name,
File defaultValue) |
List<File> |
getFiles(String name,
List<File> defaultValue)
Get the value of the
name property as a list
of File. |
int |
getInt(String name,
int defaultValue)
Get the value of the
name property as an int. |
long |
getLong(String name,
long defaultValue)
Get the value of the
name property as a long. |
String |
getRaw(String name)
Get the value of the
name property, without doing
variable expansion.If the key is
deprecated, it returns the value of the first key which replaces
the deprecated key and is not null. |
SizeInBytes |
getSizeInBytes(String name,
SizeInBytes defaultValue) |
TimeDuration |
getTimeDuration(String name,
TimeDuration defaultValue,
TimeUnit defaultUnit)
Return time duration in the given time unit.
|
BiFunction<String,TimeDuration,TimeDuration> |
getTimeDuration(TimeUnit defaultUnit) |
String |
getTrimmed(String name)
Get the value of the
name property as a trimmed String,
null if no such property exists. |
String[] |
getTrimmedStrings(String name)
Get the comma delimited values of the
name property as
an array of Strings, trimmed of the leading and trailing whitespace. |
void |
set(String name,
String value)
Set the
value of the name property. |
void |
setBoolean(String name,
boolean value)
Set the value of the
name property to a boolean. |
void |
setClass(String name,
Class<?> theClass,
Class<?> xface)
Set the value of the
name property to the name of a
theClass implementing the given interface xface. |
void |
setDouble(String name,
double value)
Set the value of the
name property to a double. |
<T extends Enum<T>> |
setEnum(String name,
T value)
Set the value of the
name property to the given type. |
void |
setFile(String name,
File value) |
void |
setFiles(String name,
List<File> value) |
void |
setIfUnset(String name,
String value)
Sets a property if it is currently unset.
|
void |
setInt(String name,
int value)
Set the value of the
name property to an int. |
void |
setLong(String name,
long value)
Set the value of the
name property to a long. |
void |
setTimeDuration(String name,
TimeDuration value)
Set the value of
name to the given time duration. |
int |
size() |
String |
toString() |
void |
unset(String name)
Unset a previously set property.
|
public RaftProperties()
public RaftProperties(RaftProperties other)
other - the RaftProperties from which to clone settings.public String get(String name)
name property, null if
no such property exists. If the key is deprecated, it returns the value of
the first key which replaces the deprecated key and is not null.
Values are processed for variable expansion
before being returned.name - the property name, will be trimmed before get value.name or its replacing property,
or null if no such property exists.public String getTrimmed(String name)
name property as a trimmed String,
null if no such property exists.
If the key is deprecated, it returns the value of
the first key which replaces the deprecated key and is not null
Values are processed for variable expansion
before being returned.name - the property name.name or its replacing property,
or null if no such property exists.public String getRaw(String name)
name property, without doing
variable expansion.If the key is
deprecated, it returns the value of the first key which replaces
the deprecated key and is not null.name - the property name.name property or
its replacing property and null if no such property exists.public void set(String name, String value)
value of the name property. If
name is deprecated, it also sets the value to
the keys that replace the deprecated key. Name will be trimmed before put
into configuration.name - property name.value - property value.IllegalArgumentException - when the value or name is null.public void unset(String name)
public void setIfUnset(String name, String value)
name - the property namevalue - the new valuepublic String get(String name, String defaultValue)
name. If the key is deprecated,
it returns the value of the first key which replaces the deprecated key
and is not null.
If no such property exists,
then defaultValue is returned.name - property name, will be trimmed before get value.defaultValue - default value.defaultValue if the property
doesn't exist.public int getInt(String name, int defaultValue)
name property as an int.
If no such property exists, the provided default value is returned,
or if the specified value is not a valid int,
then an error is thrown.name - property name.defaultValue - default value.int,
or defaultValue.NumberFormatException - when the value is invalidpublic void setInt(String name, int value)
name property to an int.name - property name.value - int value of the property.public long getLong(String name, long defaultValue)
name property as a long.
If no such property exists, the provided default value is returned,
or if the specified value is not a valid long,
then an error is thrown.name - property name.defaultValue - default value.long,
or defaultValue.NumberFormatException - when the value is invalidpublic File getFile(String name, File defaultValue)
public List<File> getFiles(String name, List<File> defaultValue)
name property as a list
of File.
The value of the property specifies a list of comma separated path names.
If no such property is specified, then defaultValue is
returned.name - the property name.defaultValue - default value.defaultValue.public SizeInBytes getSizeInBytes(String name, SizeInBytes defaultValue)
public void setLong(String name, long value)
name property to a long.name - property name.value - long value of the property.public double getDouble(String name, double defaultValue)
name property as a double.
If no such property exists, the provided default value is returned,
or if the specified value is not a valid double,
then an error is thrown.name - property name.defaultValue - default value.double,
or defaultValue.NumberFormatException - when the value is invalidpublic void setDouble(String name, double value)
name property to a double.name - property name.value - property value.public boolean getBoolean(String name, boolean defaultValue)
name property as a boolean.
If no such property is specified, or if the specified value is not a valid
boolean, then defaultValue is returned.name - property name.defaultValue - default value.boolean,
or defaultValue.public void setBoolean(String name, boolean value)
name property to a boolean.name - property name.value - boolean value of the property.public <T extends Enum<T>> void setEnum(String name, T value)
name property to the given type. This
is equivalent to set(<name>, value.toString()).name - property namevalue - new valuepublic <T extends Enum<T>> T getEnum(String name, T defaultValue)
name - Property namedefaultValue - Value returned if no mapping existsIllegalArgumentException - If mapping is illegal for the type
providedpublic void setTimeDuration(String name, TimeDuration value)
name to the given time duration. This
is equivalent to set(<name>, value + <time suffix>).name - Property namevalue - Time durationpublic TimeDuration getTimeDuration(String name, TimeDuration defaultValue, TimeUnit defaultUnit)
name - Property namedefaultValue - Value returned if no mapping exists.NumberFormatException - If the property stripped of its unit is not
a numberpublic BiFunction<String,TimeDuration,TimeDuration> getTimeDuration(TimeUnit defaultUnit)
public String[] getTrimmedStrings(String name)
name property as
an array of Strings, trimmed of the leading and trailing whitespace.
If no such property is specified then an empty array is returned.name - property name.Strings,
or empty array.public Class<?>[] getClasses(String name, Class<?>... defaultValue)
name property
as an array of Class.
The value of the property specifies a list of comma separated class names.
If no such property is specified, then defaultValue is
returned.name - the property name.defaultValue - default value.Class[],
or defaultValue.public Class<?> getClass(String name, Class<?> defaultValue)
name property as a Class.
If no such property is specified, then defaultValue is
returned.name - the class name.defaultValue - default value.Class,
or defaultValue.public <BASE> Class<? extends BASE> getClass(String name, Class<? extends BASE> defaultValue, Class<BASE> xface)
name property as a Class
implementing the interface specified by xface.
If no such property is specified, then defaultValue is
returned.
An exception is thrown if the returned class does not implement the named
interface.name - the class name.defaultValue - default value.xface - the interface implemented by the named class.Class,
or defaultValue.public void setClass(String name, Class<?> theClass, Class<?> xface)
name property to the name of a
theClass implementing the given interface xface.
An exception is thrown if theClass does not implement the
interface xface.name - property name.theClass - property value.xface - the interface implemented by the named class.public int size()
public void clear()
Copyright © 2017–2022 The Apache Software Foundation. All rights reserved.