Framework Professional Edition Package


com.prosyst.util.ini
Class IniSection

java.lang.Object
  extended by com.prosyst.util.ini.IniSection

public class IniSection
extends java.lang.Object

This class defines an IniFile's section. It is a named portion of data that is represented in a file like "[<section name>]" and contains key names and key values pairs.

Author:
Sinisha Djukic

Field Summary
static java.lang.String COMMENT_STRING
          This is the string which appears in front of the comment lines.
static java.lang.String KEY_COMMENT_STRING
          This is the string which appears in front of the commented key-value lines.
protected  com.prosyst.util.ini.Queue keys
          This Queue holds the keys.
protected  java.lang.String sectionName
          This is the section's name as it appears in a file.
protected  com.prosyst.util.ini.Queue values
          This Queue holds the correspondent values.
 
Constructor Summary
IniSection(java.lang.String sectionName)
          Constructs a new IniSection.
 
Method Summary
 void addComment(java.lang.String comment)
          Appends a comment line.
 void addKey(java.lang.String key, java.lang.String newValue)
          Appends a new key name and key value to the section.
 void addString(java.lang.String line)
          Appends a string which can be a null, "", comment, commented key, or a key-value pair.
 void commentKey(int index)
          Comments a given key if it exists and is not already commented.
 void commentKey(java.lang.String key)
          Comments a given key if it exists and is not already commented.
 boolean containsKey(java.lang.String key)
          Returns true if the given key is defined in a section.
 void deleteKey(int index)
          Deletes a key at the given index and its associated value from the section.
 void deleteKey(java.lang.String key)
          Deletes a key and its associated value from the section.
 IniSection duplicate()
          Returns a duplicate of this object.
 java.lang.String getKey(int index)
          Returns a key name at a given index.
 int getKeyCount()
          Returns the number of defined keys (or rows as displayed in a file) in this section.
 int getKeyIndex(java.lang.String key)
          Returns the index of a key in this section.
 java.lang.String getName()
          Returns the name of the section.
 java.lang.String getValue(int index)
          Returns the key value at an index.
 java.lang.String getValue(java.lang.String key)
          Returns the key value.
 java.lang.String indexToString(int index)
          Returns the string representation of a key-value pair at the given index.
 void insertComment(int index, java.lang.String comment)
          Inserts a comment line.
 void insertKey(int index, java.lang.String key, java.lang.String value)
          Inserts a new key at a given index.
 boolean isComment(int index)
          Returns true if the key at the given index is actually a comment.
 boolean isCommentedKey(int index)
          Returns true if the key at the given index is a commented key.
 boolean isCommentedKey(java.lang.String key)
          Returns true if the given key is a commented key.
 void removeCommentedKeys()
          Removes all commented keys.
 void removeComments()
          Removes all comments.
 void setName(java.lang.String newName)
          Sets the section's name.
 void setValue(java.lang.String key, java.lang.String newValue)
          Sets a new value of a key.
 java.lang.String toString()
           
 void uncommentKey(int index)
          Uncomments a given key if it exists and is commented.
 void uncommentKey(java.lang.String key)
          Uncomments a given key if it exists and is commented.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

KEY_COMMENT_STRING

public static final java.lang.String KEY_COMMENT_STRING
This is the string which appears in front of the commented key-value lines.

See Also:
Constant Field Values

COMMENT_STRING

public static final java.lang.String COMMENT_STRING
This is the string which appears in front of the comment lines.

See Also:
Constant Field Values

sectionName

protected java.lang.String sectionName
This is the section's name as it appears in a file.


keys

protected com.prosyst.util.ini.Queue keys
This Queue holds the keys.


values

protected com.prosyst.util.ini.Queue values
This Queue holds the correspondent values.

Constructor Detail

IniSection

public IniSection(java.lang.String sectionName)
Constructs a new IniSection.

Parameters:
sectionName - the new section's name
Method Detail

addKey

public void addKey(java.lang.String key,
                   java.lang.String newValue)
Appends a new key name and key value to the section.

Parameters:
key - new key name
newValue - new key value

containsKey

public boolean containsKey(java.lang.String key)
Returns true if the given key is defined in a section.

Parameters:
key - the key name to search for
Returns:
true if it is defined in this section.

deleteKey

public void deleteKey(int index)
Deletes a key at the given index and its associated value from the section.

Parameters:
index - index of a key to be deleted

deleteKey

public void deleteKey(java.lang.String key)
Deletes a key and its associated value from the section.

Parameters:
key - a key to be deleted

getKeyIndex

public int getKeyIndex(java.lang.String key)
Returns the index of a key in this section.

Parameters:
key - key to be searched for
Returns:
the index of the key or -1 if not found.

getKey

public java.lang.String getKey(int index)
Returns a key name at a given index.

Parameters:
index - key's index
Returns:
the key name.

getKeyCount

public int getKeyCount()
Returns the number of defined keys (or rows as displayed in a file) in this section.

Returns:
the number of defined keys.

getValue

public java.lang.String getValue(java.lang.String key)
Returns the key value.

Parameters:
key - key name
Returns:
the key value.

getValue

public java.lang.String getValue(int index)
Returns the key value at an index.

Parameters:
index - index of a value
Returns:
the key value.

getName

public java.lang.String getName()
Returns the name of the section.

Returns:
the section's name.

insertKey

public void insertKey(int index,
                      java.lang.String key,
                      java.lang.String value)
Inserts a new key at a given index.

Parameters:
index - index at which to insert the new key
key - new key name
value - new key value

setName

public void setName(java.lang.String newName)
Sets the section's name.

Parameters:
newName - new section's name

setValue

public void setValue(java.lang.String key,
                     java.lang.String newValue)
Sets a new value of a key.

Parameters:
key - key to be updated
newValue - new key value

commentKey

public void commentKey(java.lang.String key)
Comments a given key if it exists and is not already commented.

Parameters:
key - key to comment

commentKey

public void commentKey(int index)
Comments a given key if it exists and is not already commented.

Parameters:
index - index of the key to comment

uncommentKey

public void uncommentKey(java.lang.String key)
Uncomments a given key if it exists and is commented.

Parameters:
key - key to uncomment

uncommentKey

public void uncommentKey(int index)
Uncomments a given key if it exists and is commented.

Parameters:
index - index of the key to uncomment

removeCommentedKeys

public void removeCommentedKeys()
Removes all commented keys.


isCommentedKey

public boolean isCommentedKey(int index)
Returns true if the key at the given index is a commented key.

Parameters:
index - key index
Returns:
true if the key at the given index is a commented key

isCommentedKey

public boolean isCommentedKey(java.lang.String key)
Returns true if the given key is a commented key.

Parameters:
key - key to test if it is commented
Returns:
if the given key a commented key

addComment

public void addComment(java.lang.String comment)
Appends a comment line. A given comment can already be commented and will not be commented once more.

Parameters:
comment - comment to add

insertComment

public void insertComment(int index,
                          java.lang.String comment)
Inserts a comment line. A given comment can already be commented and will not be commented once more.

Parameters:
index - index at which the comment will be inserted
comment - comment to add

removeComments

public void removeComments()
Removes all comments.


isComment

public boolean isComment(int index)
Returns true if the key at the given index is actually a comment.

Parameters:
index - key index
Returns:
true if the key at the given index is actually a comment

indexToString

public java.lang.String indexToString(int index)
Returns the string representation of a key-value pair at the given index. Different outlook will have comments, commented keys and keys.

Parameters:
index - key index
Returns:
string representation of a key-value pair at the given index

addString

public void addString(java.lang.String line)
Appends a string which can be a null, "", comment, commented key, or a key-value pair.

Parameters:
line - string representing the possible section data

duplicate

public IniSection duplicate()
Returns a duplicate of this object.

Returns:
a duplicate of this object

toString

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

Framework Professional Edition Package


Copyright © 1999-2007 ProSyst Software GmbH. All Rights Reserved