org.jagatoo.util.ini
Class IniFile

java.lang.Object
  extended by org.jagatoo.util.ini.IniFile

public class IniFile
extends java.lang.Object

Read-only interface to an ini file.

Author:
Marvin Froehlich (aka Qudus)

Field Summary
static boolean DEFAULT_CASE_SENSITIVITY
           
 
Constructor Summary
IniFile(java.io.File file)
          Creates a new ini file interface.
IniFile(java.io.File file, boolean caseSensitivity)
          Creates a new ini file interface.
IniFile(java.lang.String filename)
          Creates a new ini file interface.
IniFile(java.lang.String filename, boolean caseSensitivity)
          Creates a new ini file interface.
 
Method Summary
 java.lang.String getGroup(int index)
          Gets the index'th group name.
 java.util.List<java.lang.String> getGroups()
          Gets an unmodifiable list of the group names.
 java.lang.String getKey(java.lang.String group, int index)
          Gets the index'th setting key in the passed group.
 java.util.List<java.lang.String> getKeys(java.lang.String group)
          Gets an unmodifiable list of the key names.
 int getNumGroups()
          Gets the number of groups.
 int getNumSettings(java.lang.String group)
          Gets the number of settings in the given group.
 java.lang.String getSetting(java.lang.String group, java.lang.String key)
          Gets the settings's value for the given group and key.
 java.lang.String getSetting(java.lang.String group, java.lang.String key, java.lang.String defaultValue)
          Gets the settings's value for the given group and key.
 boolean refresh()
          Checks, if the ini file has bee modified since the last refresh and updates in case.
 boolean settingExists(java.lang.String group, java.lang.String key)
          Gets the settings's value for the given group and key.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_CASE_SENSITIVITY

public static final boolean DEFAULT_CASE_SENSITIVITY
See Also:
Constant Field Values
Constructor Detail

IniFile

public IniFile(java.io.File file,
               boolean caseSensitivity)
Creates a new ini file interface. The constructor doesn't call the refresh() method.

Parameters:
file -
caseSensitivity -

IniFile

public IniFile(java.lang.String filename,
               boolean caseSensitivity)
Creates a new ini file interface. The constructor doesn't call the refresh() method.

Parameters:
filename -
caseSensitivity -

IniFile

public IniFile(java.io.File file)
Creates a new ini file interface. The constructor doesn't call the refresh() method.

Parameters:
file -

IniFile

public IniFile(java.lang.String filename)
Creates a new ini file interface. The constructor doesn't call the refresh() method.

Parameters:
filename -
Method Detail

refresh

public boolean refresh()
                throws java.io.IOException,
                       ParsingException
Checks, if the ini file has bee modified since the last refresh and updates in case.

Returns:
whether a refresh as necessary.
Throws:
java.io.IOException
ParsingException

settingExists

public final boolean settingExists(java.lang.String group,
                                   java.lang.String key)
Gets the settings's value for the given group and key.

Parameters:
group -
key -
Returns:
the settings's value for the given group and key or null, if not found.

getSetting

public final java.lang.String getSetting(java.lang.String group,
                                         java.lang.String key,
                                         java.lang.String defaultValue)
Gets the settings's value for the given group and key.

Parameters:
group -
key -
defaultValue - the value to be returned, if the settings does not exist
Returns:
the settings's value for the given group and key or 'defaultValue', if not found.

getSetting

public final java.lang.String getSetting(java.lang.String group,
                                         java.lang.String key)
Gets the settings's value for the given group and key.

Parameters:
group -
key -
Returns:
the settings's value for the given group and key or null, if not found.

getNumGroups

public final int getNumGroups()
Gets the number of groups.

Returns:
the number of groups.

getGroup

public final java.lang.String getGroup(int index)
Gets the index'th group name.

Parameters:
index -
Returns:
the index'th group name.

getGroups

public final java.util.List<java.lang.String> getGroups()
Gets an unmodifiable list of the group names.

Returns:
an unmodifiable list of the group names.

getNumSettings

public final int getNumSettings(java.lang.String group)
Gets the number of settings in the given group. If the given group does not exist, -1 is returned.

Parameters:
group -
Returns:
the number of settings in the given group or -1.

getKey

public final java.lang.String getKey(java.lang.String group,
                                     int index)
Gets the index'th setting key in the passed group.

Parameters:
group -
index -
Returns:
the index'th setting key in the passed group.

getKeys

public final java.util.List<java.lang.String> getKeys(java.lang.String group)
Gets an unmodifiable list of the key names.

Parameters:
group -
Returns:
an unmodifiable list of the key names.