asia.redact.bracket.properties
Class PropertiesImpl

java.lang.Object
  extended by asia.redact.bracket.properties.AbstractPropertiesBase
      extended by asia.redact.bracket.properties.PropertiesImpl
All Implemented Interfaces:
Properties
Direct Known Subclasses:
ServerLocalizedProperties, SortedPropertiesImpl

public class PropertiesImpl
extends AbstractPropertiesBase
implements Properties

 A better Properties class. This implementation class is thread-safe.
 
 

Author:
Dave

Nested Class Summary
 
Nested classes/interfaces inherited from interface asia.redact.bracket.properties.Properties
Properties.Factory, Properties.Mode
 
Field Summary
 
Fields inherited from class asia.redact.bracket.properties.AbstractPropertiesBase
lock, map
 
Constructor Summary
PropertiesImpl()
           
PropertiesImpl(InputStream in)
           
PropertiesImpl(Properties legacy)
          Some slight information loss here is unavoidable.
PropertiesImpl(Reader in)
           
PropertiesImpl(URL url)
           
 
Method Summary
 Date dateValue(String key)
          Date value here is assumed to be a long
 Date dateValue(String key, String format)
          I should really deprecate this - you should really use long values as dates in a serialization.
 boolean equals(Object obj)
           
 String get(String key)
          Get the value of the property; concatenate multiple lines.
 List<String> getComments(String key)
          Get the list of comments, return an empty list if none
 Properties getGroup(GroupParams params)
           
 List<String> getKeyGroup(String keyBase)
           
 Map<String,ValueModel> getPropertyMap()
          Can be used to get direct access to the Entry data structures
 char getSeparator(String key)
          The char found in the parse, normally '='
 Node getTree()
          Use "\\." as the separator
 Node getTree(GroupParams params)
           Get the properties as a tree of nodes with a selector a.b.c=something a.b.c.d=something else a.b.c.e.f=item a.b.c.e=item2
 int hashCode()
           
 boolean hasValue(String key)
          Returns true if the key exists and has a non-empty value
protected  void initMap()
           
 int intValue(String key)
          Coerce to an integer value.
 long longValue(String key)
          Coerce to a long value.
 Properties merge(Properties props)
          This is a merge function, existing keys which do not collide with the incoming are kept, keys that collide are overwritten with the new values TODO, cause comments to come over as well
 Properties merge(Properties props, boolean mergeComments)
          Overwrite existing keys with the new ones, keep those existing ones that don't collide This operation is non-destructive on the input
 void put(String key, String... values)
          yes, multivalued (multilined) properties are in the spec.
 void synchronize(Node rootNode)
          Cause a graph to become the contents of the properties file.
 
Methods inherited from class asia.redact.bracket.properties.AbstractPropertiesBase
clear, containsKey, containsValue, isEmpty, keySet, remove, size, toString, values
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface asia.redact.bracket.properties.Properties
clear, containsKey, size
 

Constructor Detail

PropertiesImpl

public PropertiesImpl()

PropertiesImpl

public PropertiesImpl(Properties legacy)
Some slight information loss here is unavoidable. For example if a colon is used as the separator in the original, that information will be lost. If you need a more exact translation you can do that with the lexer and parser classes by reading in the data directly from the properties file instead of reading in with java.util.Properties and then converting.


PropertiesImpl

public PropertiesImpl(URL url)

PropertiesImpl

public PropertiesImpl(InputStream in)

PropertiesImpl

public PropertiesImpl(Reader in)
Method Detail

initMap

protected void initMap()

get

public String get(String key)
Get the value of the property; concatenate multiple lines.

Specified by:
get in interface Properties
Parameters:
key -
Returns:
Throws:
RuntimeException - if key is not present.

put

public void put(String key,
                String... values)
yes, multivalued (multilined) properties are in the spec. if values exist, they are removed and replaced

Specified by:
put in interface Properties
Parameters:
key -
values -

getPropertyMap

public Map<String,ValueModel> getPropertyMap()
Description copied from interface: Properties
Can be used to get direct access to the Entry data structures

Specified by:
getPropertyMap in interface Properties
Returns:

getComments

public List<String> getComments(String key)
Description copied from interface: Properties
Get the list of comments, return an empty list if none

Specified by:
getComments in interface Properties
Returns:

getSeparator

public char getSeparator(String key)
Description copied from interface: Properties
The char found in the parse, normally '='

Specified by:
getSeparator in interface Properties
Returns:

getKeyGroup

public List<String> getKeyGroup(String keyBase)

hashCode

public int hashCode()
Overrides:
hashCode in class AbstractPropertiesBase

equals

public boolean equals(Object obj)
Overrides:
equals in class AbstractPropertiesBase

merge

public Properties merge(Properties props)
This is a merge function, existing keys which do not collide with the incoming are kept, keys that collide are overwritten with the new values TODO, cause comments to come over as well

Specified by:
merge in interface Properties
Parameters:
props -
Returns:
the merged properties

merge

public Properties merge(Properties props,
                        boolean mergeComments)
Description copied from interface: Properties
Overwrite existing keys with the new ones, keep those existing ones that don't collide This operation is non-destructive on the input

Specified by:
merge in interface Properties
Returns:
the merged properties

getTree

public Node getTree()
Use "\\." as the separator

Specified by:
getTree in interface Properties
Returns:

getTree

public Node getTree(GroupParams params)
Description copied from interface: Properties
 Get the properties as a tree of nodes with a selector
 
 a.b.c=something
 a.b.c.d=something else
 a.b.c.e.f=item
 a.b.c.e=item2
 

Specified by:
getTree in interface Properties

getGroup

public Properties getGroup(GroupParams params)

intValue

public int intValue(String key)
Description copied from interface: Properties
Coerce to an integer value. Obviously this works better if the value is actually an integer.

Specified by:
intValue in interface Properties
Returns:

longValue

public long longValue(String key)
Description copied from interface: Properties
Coerce to a long value. Obviously this works better if the value is actually a long.

Specified by:
longValue in interface Properties
Returns:

dateValue

public Date dateValue(String key)
Description copied from interface: Properties
Date value here is assumed to be a long

Specified by:
dateValue in interface Properties
Returns:

dateValue

public Date dateValue(String key,
                      String format)
               throws ParseException
I should really deprecate this - you should really use long values as dates in a serialization. See above.

Specified by:
dateValue in interface Properties
Returns:
Throws:
ParseException

hasValue

public boolean hasValue(String key)
Description copied from interface: Properties
Returns true if the key exists and has a non-empty value

Specified by:
hasValue in interface Properties
Returns:

synchronize

public void synchronize(Node rootNode)
Description copied from interface: Properties
Cause a graph to become the contents of the properties file. Destructive to current entries, so this is not very useful yet

Specified by:
synchronize in interface Properties


Copyright © 2011-2013 David R. Smith. All Rights Reserved.