iaik.tc.utils.properties
Class Properties

java.lang.Object
  extended by iaik.tc.utils.properties.Properties

public class Properties
extends java.lang.Object

Class for handling configuration files in Java properties like formatting.

Example of expected format:

 # a comment
 [Section1]
 something = anything
 
 [Section2]
 whatever = new thing
 


Constructor Summary
Properties()
          Creates new empty Properties.
Properties(java.lang.String file)
          Creates new Properties object from file content.
 
Method Summary
 void addSection(java.lang.String sectionname)
          Adds a new empty section.
 java.lang.String getProperty(java.lang.String key)
          Returns a property from the section that has been previously specified via setSectionPointer(java.lang.String).
 java.lang.String getProperty(java.lang.String section, java.lang.String key)
          Returns a property from the specified section.
 java.math.BigInteger getPropertyAsBigInt(java.lang.String key)
          Returns a property from the section that has been previously specified via setSectionPointer(java.lang.String).
 java.math.BigInteger getPropertyAsBigInt(java.lang.String section, java.lang.String key)
          Returns a property from the specified section.
 int getPropertyAsInt(java.lang.String key)
          Returns a property from the section that has been previously specified via setSectionPointer(java.lang.String).
 int getPropertyAsInt(java.lang.String section, java.lang.String key)
          Returns a property from the specified section.
 java.util.ArrayList getSections()
          Gets array of section names.
 boolean hasSection(java.lang.String sectionname)
          Determines if a section of supplied name already exists.
 void setProperty(java.lang.String key, java.lang.String value)
          Sets a property in the currently selected section.
 void setProperty(java.lang.String section, java.lang.String key, java.lang.String value)
          Sets a property in the specified section.
 void setSectionPointer(java.lang.String section)
          Sets current section pointer.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Properties

public Properties()
Creates new empty Properties.


Properties

public Properties(java.lang.String file)
           throws java.io.IOException
Creates new Properties object from file content.

A new Properties object is created and its initial content read from indicated file.

Throws:
java.io.IOException
Method Detail

setSectionPointer

public void setSectionPointer(java.lang.String section)
Sets current section pointer.

Throws:
java.lang.IllegalArgumentException - if section does not exist

addSection

public void addSection(java.lang.String sectionname)
Adds a new empty section.

After successful creation of the new section the current section pointer is updated to the new section. If a section of the specified name already existed, the current section pointer is only updated to this section.

Parameters:
sectionname - name of the section to create

hasSection

public boolean hasSection(java.lang.String sectionname)
Determines if a section of supplied name already exists.

Parameters:
sectionname - section name
Returns:
true if section of that name exists, false otherwise.

getSections

public java.util.ArrayList getSections()
Gets array of section names.

Returns:
array of section names

setProperty

public void setProperty(java.lang.String section,
                        java.lang.String key,
                        java.lang.String value)
Sets a property in the specified section.

Parameters:
section - section name
key - property name
value - property value
Throws:
java.lang.IllegalArgumentException - if any parameter is null or section does not exist

setProperty

public void setProperty(java.lang.String key,
                        java.lang.String value)
Sets a property in the currently selected section.

Parameters:
key - property name
value - value to set

getProperty

public java.lang.String getProperty(java.lang.String key)
Returns a property from the section that has been previously specified via setSectionPointer(java.lang.String).

Parameters:
key - property name
Returns:
property value

getPropertyAsInt

public int getPropertyAsInt(java.lang.String key)
Returns a property from the section that has been previously specified via setSectionPointer(java.lang.String). It is assumed the property String can be converted on the fly to an integer type.

Parameters:
key - property name
Returns:
property value

getPropertyAsBigInt

public java.math.BigInteger getPropertyAsBigInt(java.lang.String key)
Returns a property from the section that has been previously specified via setSectionPointer(java.lang.String). It is assumed the property String can be converted on the fly to a BigInteger type.

Parameters:
key - property name
Returns:
property value

getProperty

public java.lang.String getProperty(java.lang.String section,
                                    java.lang.String key)
Returns a property from the specified section.

Parameters:
section - section name
key - property name
Returns:
property value
Throws:
java.lang.IllegalArgumentException - if section does not exist

getPropertyAsInt

public int getPropertyAsInt(java.lang.String section,
                            java.lang.String key)
Returns a property from the specified section. It is assumed the property String can be converted on the fly to an integer type.

Parameters:
section - section name
key - property name
Returns:
property value
Throws:
java.lang.IllegalArgumentException - if section does not exist

getPropertyAsBigInt

public java.math.BigInteger getPropertyAsBigInt(java.lang.String section,
                                                java.lang.String key)
Returns a property from the specified section. It is assumed the property String can be converted on the fly to a BigInteger type.

Parameters:
section - section name
key - property name
Returns:
property value
Throws:
java.lang.IllegalArgumentException - if section does not exist

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object