public class XenonProperties
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private static int |
GIGA
One giga is a kilo*kilo*kilo
|
private static int |
KILO
One kilo is 1024
|
private static int |
MEGA
One mega is a kilo*kilo
|
private static java.lang.String |
NAME |
private java.util.Map<java.lang.String,java.lang.String> |
properties
The properties that are actually set.
|
private java.util.Map<java.lang.String,XenonPropertyDescription> |
supportedProperties
Contains a description of all properties this XenonProperties should accept, including their type, default, etc.
|
Modifier | Constructor and Description |
---|---|
|
XenonProperties()
Creates an empty XenonProperties.
|
|
XenonProperties(ImmutableArray<XenonPropertyDescription> supportedProperties,
java.util.Map<java.lang.String,java.lang.String> properties)
Create a new XenonProperties that will support the properties in
supportedProperties . |
|
XenonProperties(ImmutableArray<XenonPropertyDescription> supportedProperties,
XenonPropertyDescription.Component level,
java.util.Map<java.lang.String,java.lang.String> properties)
Create a new XenonProperties that will support the properties in
supportedProperties that are valid at level
level . |
private |
XenonProperties(java.util.Map<java.lang.String,XenonPropertyDescription> supportedProperties,
java.util.Map<java.lang.String,java.lang.String> properties)
Private constructor for XenonProperties using in copying and filtering.
|
Modifier and Type | Method and Description |
---|---|
private void |
addProperties(java.util.Map<java.lang.String,java.lang.String> properties)
Adds the specified properties to the current ones and checks if their names and types are correct.
|
private void |
checkType(XenonPropertyDescription description,
java.lang.String key,
java.lang.String value) |
XenonProperties |
clear(java.lang.String prefix)
Returns a copy of this XenonProperties that contains all properties but clears the properties that start with the given
prefix.
|
XenonProperties |
exclude(java.lang.String prefix)
Returns a copy of this XenonProperties that contains all properties except the properties that start with the given
prefix.
|
XenonProperties |
filter(java.lang.String prefix)
Returns a new XenonProperties that contains only the properties whose key start with a certain prefix.
|
XenonProperties |
filter(XenonPropertyDescription.Component level)
Returns a new XenonProperties that contains only the properties with a given level.
|
boolean |
getBooleanProperty(java.lang.String name)
Retrieves the value of a boolean property with the given name.
|
double |
getDoubleProperty(java.lang.String name)
Retrieves the value of an double property with the given name.
|
int |
getIntegerProperty(java.lang.String name)
Retrieves the value of an integer property with the given name.
|
int |
getIntegerProperty(java.lang.String name,
int defaultValue)
Retrieves the value of an integer property with the given name.
|
long |
getLongProperty(java.lang.String name)
Retrieves the value of an long property with the given name.
|
java.lang.String |
getProperty(java.lang.String name)
Retrieves the value of a property with the given name without checking its type.
|
private java.lang.String |
getProperty(java.lang.String name,
XenonPropertyDescription.Type type) |
java.lang.String[] |
getPropertyNames()
Returns a sorted list of all supported property names.
|
long |
getSizeProperty(java.lang.String name)
Retrieves the value of a size property with the given name.
|
java.lang.String |
getStringProperty(java.lang.String name)
Retrieves the value of a string property with the given name.
|
XenonPropertyDescription[] |
getSupportedProperties()
Returns the descriptions of all supported properties.
|
private long |
parseSizeValue(java.lang.String value) |
void |
printProperties(java.io.PrintStream out,
java.lang.String prefix)
Prints properties (including default properties) to a stream.
|
boolean |
propertySet(java.lang.String name)
Check if the property with the given name is set.
|
boolean |
supportsProperty(java.lang.String name)
Check if this XenonProperties supports a property with the given name.
|
java.util.Map<java.lang.String,java.lang.String> |
toMap()
Returns all properties that are set in a Map.
|
java.lang.String |
toString() |
private static final java.lang.String NAME
private static final int KILO
private static final int MEGA
private static final int GIGA
private final java.util.Map<java.lang.String,XenonPropertyDescription> supportedProperties
private final java.util.Map<java.lang.String,java.lang.String> properties
private XenonProperties(java.util.Map<java.lang.String,XenonPropertyDescription> supportedProperties, java.util.Map<java.lang.String,java.lang.String> properties)
properties
parameter is assumed
to only contain valid supported properties and have values of the correct type.supportedProperties
- a map containing a description of all supported properties.properties
- a map containing valid properties and their values.public XenonProperties()
public XenonProperties(ImmutableArray<XenonPropertyDescription> supportedProperties, java.util.Map<java.lang.String,java.lang.String> properties) throws UnknownPropertyException, InvalidPropertyException
supportedProperties
. All properties in
properties
will be added.supportedProperties
- the properties to supportproperties
- the set of properties to storeUnknownPropertyException
- if key is found in properties
that is not listed in supportedProperties
InvalidPropertyException
- if a key from properties
has a value that does not match the type as listed in
supportedProperties
public XenonProperties(ImmutableArray<XenonPropertyDescription> supportedProperties, XenonPropertyDescription.Component level, java.util.Map<java.lang.String,java.lang.String> properties) throws UnknownPropertyException, InvalidPropertyException
supportedProperties
that are valid at level
level
. All properties in properties
will be added.supportedProperties
- the properties to supportlevel
- properties
- the set of properties to storeUnknownPropertyException
- if key is found in properties
that is not listed in supportedProperties
, or not
listed at level level
.InvalidPropertyException
- if a key from properties
has a value that does not match the type as listed in
supportedProperties
.private void addProperties(java.util.Map<java.lang.String,java.lang.String> properties) throws UnknownPropertyException, InvalidPropertyException
properties
- the properties to add.UnknownPropertyException
InvalidPropertyException
private void checkType(XenonPropertyDescription description, java.lang.String key, java.lang.String value) throws InvalidPropertyException
InvalidPropertyException
public boolean supportsProperty(java.lang.String name)
name
- the name of the property.true
if this XenonProperties supports a property with the given name, false
otherwise.public boolean propertySet(java.lang.String name) throws UnknownPropertyException
name
- the name of the property.true
if the property with the given name is set, false
otherwise.UnknownPropertyException
- if the given name is not a supported property.public java.lang.String getProperty(java.lang.String name) throws UnknownPropertyException
String
representation is always returned.name
- the name of the property.UnknownPropertyException
- if the given name is not a supported property.private java.lang.String getProperty(java.lang.String name, XenonPropertyDescription.Type type) throws UnknownPropertyException, PropertyTypeException
public boolean getBooleanProperty(java.lang.String name) throws UnknownPropertyException, PropertyTypeException, InvalidPropertyException
name
- the name of the propertyUnknownPropertyException
- if the given name is not a supported property.PropertyTypeException
- if the property is not of type boolean.InvalidPropertyException
- if the property value cannot be converted into a boolean.public int getIntegerProperty(java.lang.String name) throws UnknownPropertyException, PropertyTypeException, InvalidPropertyException
name
- the name of the propertyUnknownPropertyException
- if the given name is not a supported property.PropertyTypeException
- if the property is not of type integer.InvalidPropertyException
- if the property value cannot be converted into a integer.public int getIntegerProperty(java.lang.String name, int defaultValue) throws UnknownPropertyException, PropertyTypeException, InvalidPropertyException
name
- the name of the propertyUnknownPropertyException
- if the given name is not a supported property.PropertyTypeException
- if the property is not of type integer.InvalidPropertyException
- if the property value cannot be converted into a integer.public long getLongProperty(java.lang.String name) throws UnknownPropertyException, PropertyTypeException, InvalidPropertyException
name
- the name of the propertyUnknownPropertyException
- if the given name is not a supported property.PropertyTypeException
- if the property is not of type long.InvalidPropertyException
- if the property value cannot be converted into a long.public double getDoubleProperty(java.lang.String name) throws UnknownPropertyException, PropertyTypeException, InvalidPropertyException
name
- the name of the propertyUnknownPropertyException
- if the given name is not a supported property.PropertyTypeException
- if the property is not of type double.InvalidPropertyException
- if the property value cannot be converted into a double.public java.lang.String getStringProperty(java.lang.String name) throws UnknownPropertyException, PropertyTypeException
name
- the name of the propertyUnknownPropertyException
- if the given name is not a supported property.PropertyTypeException
- if the property is not of type string.private long parseSizeValue(java.lang.String value) throws InvalidPropertyException
InvalidPropertyException
public long getSizeProperty(java.lang.String name) throws UnknownPropertyException, PropertyTypeException, InvalidPropertyException
name
- the name of the propertyUnknownPropertyException
- if the given name is not a supported property.PropertyTypeException
- if the property is not of type size.InvalidPropertyException
- if the property value cannot be converted into a long.public XenonProperties filter(java.lang.String prefix)
prefix
- the desired prefixpublic XenonProperties filter(XenonPropertyDescription.Component level)
level
- the desired prefixpublic XenonProperties exclude(java.lang.String prefix)
prefix
- the prefix of the properties to excludepublic XenonProperties clear(java.lang.String prefix)
prefix
- the prefix of the properties to excludepublic XenonPropertyDescription[] getSupportedProperties()
public java.lang.String[] getPropertyNames()
public java.util.Map<java.lang.String,java.lang.String> toMap()
public void printProperties(java.io.PrintStream out, java.lang.String prefix)
out
- The stream to write output to.prefix
- Only print properties which start with the given prefix. If null, will print all propertiespublic java.lang.String toString()
toString
in class java.lang.Object