org.dtools.ini
Class IniItem

java.lang.Object
  extended by org.dtools.ini.IniItem
All Implemented Interfaces:
Cloneable, Commentable

public class IniItem
extends Object
implements Commentable, Cloneable

The IniItem class represents the simplest element of an INI file, an item, which has only two important properties, a name and a value.

Any primitive type can be saved as a value of this item, and any objects saved as a value are converted to a String via the object's toString(), however all values returned by an item are returned as a String.

Since:
0.1.10
Version:
1.1.0
Author:
David Lewis

Field Summary
 
Fields inherited from interface org.dtools.ini.Commentable
COMMENT_SYMBOL
 
Constructor Summary
IniItem(String name)
          Default constructor which creates a new instance of this IniItem and sets the IniItem to have a default IniValidator and to be case insensitive.
IniItem(String name, boolean caseSensitive)
          Default constructor which creates a new instance of this IniItem and sets the IniItem to have a default IniValidator.
IniItem(String name, IniValidator validator)
          Default constructor which creates a new instance of this IniItem and sets the IniItem to be case insensitive.
IniItem(String name, IniValidator validator, boolean caseSensitive)
          Default constructor which creates a new instance of this IniItem.
 
Method Summary
 boolean clear()
          This method clears the value of this item.
 Object clone()
           
 boolean equals(Object otherObject)
          This predicate returns true if this IniItem is equal to the given object.
 String getEndLineComment()
          Returns the comment that comes after the object on the same line.
 String getName()
          Returns the name of this item, note that the item cannot change its name and one would need to create a new item to do so.
 String getPostComment()
          Returns the comment that comes after the object.
 String getPreComment()
          Returns the comment that comes before the object.
 IniValidator getValidator()
          Gets a reference to this object's IniValidator.
 String getValue()
          This returns the String which this items stores.
 int hashCode()
           
 boolean hasValue()
          Predicate that returns true if this item has a value, or false if it is empty
 boolean isCaseSensitive()
          Predicate that returns true if this IniItem is case sensitive, or false if this IniItem is case insensitive.
 void removeEndLineComment()
          Removes an end line comment from the object.
 void removePostComment()
          Removes a post-comment from the object.
 void removePreComment()
          Removes a pre-comment from the object.
 void setEndLineComment(String comment)
          Set the comment that comes after the object but on the same line.
 void setPostComment(String comment)
          Set the comment that comes after the object.
 void setPreComment(String comment)
          Set the comment that comes before the object.
 void setValue(boolean value)
          Set the value as a boolean value
 void setValue(char value)
          Set the value as a character value
 void setValue(double value)
          Set the value as a double value
 void setValue(long value)
          Set the value as a float value
 void setValue(Object value)
          This set the value to an Object when it has been converted to a String.
 void setValue(String value)
          Set the value as a String value
 String toString()
           
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

IniItem

public IniItem(String name)

Default constructor which creates a new instance of this IniItem and sets the IniItem to have a default IniValidator and to be case insensitive.

Parameters:
name - The name of this IniItem.
Throws:
InvalidNameException - if the name of the IniItem given is not considered valid by this object's IniValidator.

IniItem

public IniItem(String name,
               boolean caseSensitive)

Default constructor which creates a new instance of this IniItem and sets the IniItem to have a default IniValidator.

Parameters:
name - The name of this IniItem.
caseSensitive - Sets whether this IniItem is case sensitive.
Throws:
InvalidNameException - if the name of the IniItem given is not considered valid by this object's IniValidator.

IniItem

public IniItem(String name,
               IniValidator validator)

Default constructor which creates a new instance of this IniItem and sets the IniItem to be case insensitive.

Parameters:
name - The name of this IniItem.
validator - The validator of this IniItem.
Throws:
InvalidNameException - if the name of the IniItem given is not considered valid by this object's IniValidator.

IniItem

public IniItem(String name,
               IniValidator validator,
               boolean caseSensitive)

Default constructor which creates a new instance of this IniItem.

Parameters:
name - The name of this IniItem.
validator - The validator of this IniItem.
caseSensitive - Sets whether this IniItem is case sensitive.
Throws:
InvalidNameException - if the name of the IniItem given is not considered valid by this object's IniValidator.
Method Detail

clear

public boolean clear()
This method clears the value of this item.

Returns:
Returns true is the item's value was cleared successfully, false otherwise.

equals

public boolean equals(Object otherObject)

This predicate returns true if this IniItem is equal to the given object. For otherObject to be equal to this one it must:

* If the two IniItems are case-sensitive, then these are compared using the equals(Object) method. If the two IniItems are case-insensitive, then these are compared using the String.equalsIgnoreCase(String) method.

Overrides:
equals in class Object
Parameters:
otherObject - The other Object to test for equality.
Returns:
True if equal, false if not equal.
Since:
0.1.15

getEndLineComment

public String getEndLineComment()
Description copied from interface: Commentable

Returns the comment that comes after the object on the same line. If not such comment exists an empty string is returned.

Specified by:
getEndLineComment in interface Commentable
Returns:
the comment or "" if no comment exists.

getName

public String getName()
Returns the name of this item, note that the item cannot change its name and one would need to create a new item to do so.

Returns:
the name of this item

getPostComment

public String getPostComment()
Description copied from interface: Commentable

Returns the comment that comes after the object. If not such comment exists an empty string is returned.

Specified by:
getPostComment in interface Commentable
Returns:
the comment or "" if no comment exists.

getPreComment

public String getPreComment()
Description copied from interface: Commentable

Returns the comment that comes before the object. If not such comment exists an empty string is returned.

Specified by:
getPreComment in interface Commentable
Returns:
the comment or "" if no comment exists.

getValidator

public IniValidator getValidator()

Gets a reference to this object's IniValidator.

Returns:
The IniValidator used by this IniItem.
Since:
0.1.17

getValue

public String getValue()
This returns the String which this items stores. If the item has no value, then null is returned.

Returns:
String, the value of this item.

hashCode

public int hashCode()
Overrides:
hashCode in class Object

hasValue

public boolean hasValue()
Predicate that returns true if this item has a value, or false if it is empty

Returns:
true or false

isCaseSensitive

public boolean isCaseSensitive()

Predicate that returns true if this IniItem is case sensitive, or false if this IniItem is case insensitive.

Returns:
boolean
Since:
0.1.16

removeEndLineComment

public void removeEndLineComment()
Description copied from interface: Commentable
Removes an end line comment from the object. This is the equivalent to:
setEndLineComment("");

Specified by:
removeEndLineComment in interface Commentable

removePostComment

public void removePostComment()
Description copied from interface: Commentable
Removes a post-comment from the object. This is the equivalent to:
setPostComment("");

Specified by:
removePostComment in interface Commentable

removePreComment

public void removePreComment()
Description copied from interface: Commentable
Removes a pre-comment from the object. This is the equivalent to:
setPreComment("");

Specified by:
removePreComment in interface Commentable

setEndLineComment

public void setEndLineComment(String comment)
Description copied from interface: Commentable

Set the comment that comes after the object but on the same line.

Specified by:
setEndLineComment in interface Commentable
Parameters:
comment - The text comment, if this value is null, then the comment is set to an empty string.

setPostComment

public void setPostComment(String comment)
Description copied from interface: Commentable
Set the comment that comes after the object.

Specified by:
setPostComment in interface Commentable
Parameters:
comment - the text comment, if this value is null, then the comment is set to an empty string.

setPreComment

public void setPreComment(String comment)
Description copied from interface: Commentable

Set the comment that comes before the object.

Specified by:
setPreComment in interface Commentable
Parameters:
comment - the text comment, if this value is null, then the comment is set to an empty string.

setValue

public void setValue(boolean value)
Set the value as a boolean value

Parameters:
value - The value to set.

setValue

public void setValue(char value)
Set the value as a character value

Parameters:
value - The value to set.

setValue

public void setValue(double value)
Set the value as a double value

Parameters:
value - The value to set.

setValue

public void setValue(long value)
Set the value as a float value

Parameters:
value - the value to set

setValue

public void setValue(Object value)
This set the value to an Object when it has been converted to a String.

Parameters:
value - the value to set

setValue

public void setValue(String value)
Set the value as a String value

Parameters:
value - the value to set

toString

public String toString()
Overrides:
toString in class Object

clone

public Object clone()
Overrides:
clone in class Object