|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.dtools.ini.IniSection
public abstract class IniSection
An IniSection represents a section within a configuration file (aka INI
file). A section can contain zero or more items (which have unique names
within a section), and those items have a value. In this API, an item is
represented by the class IniItem
.
Field Summary | |
---|---|
protected IniValidator |
validator
A reference to this (and subclasses) IniSection 's
IniValidator which validates the name of this IniSection
and all IniItem s within this IniSection . |
Fields inherited from interface org.dtools.ini.Commentable |
---|
COMMENT_SYMBOL |
Constructor Summary | |
---|---|
IniSection(String name)
Default constructor which creates a new instance of this abstract IniSection and sets the IniSection to have a
default IniValidator and to be case insensitive. |
|
IniSection(String name,
boolean caseSensitive)
Constructor which creates a new instance of this abstract IniSection and sets the IniSection to have a
default IniValidator . |
|
IniSection(String name,
IniValidator validator)
Constructor which creates a new instance of this abstract IniSection and sets the IniSection to be case
insensitive. |
|
IniSection(String name,
IniValidator validator,
boolean caseSensitive)
Constructor which creates a new instance of this abstract IniSection . |
Method Summary | |
---|---|
boolean |
addItem(IniItem item)
Adds an IniItem to this section. |
abstract boolean |
addItem(IniItem item,
int index)
Adds an IniItem to this section at the given index. |
IniItem |
addItem(String itemName)
Adds a new IniItem to this section with the given name. |
IniItem |
addItem(String itemName,
int index)
Adds an IniItem to this section at the given index. |
void |
addItems(String... itemNames)
Add multiple new items to this section. |
abstract Object |
clone()
This class implements the Cloneable interface, but leaves implementation to subclasses which override this class. |
protected abstract IniItem |
createItem(String name)
This method creates and returns a new instance of an IniItem with the same IniValidator and case
sensitivity as this object. |
boolean |
equals(Object other)
This predicate returns true if this IniSection is equal
to the given object. |
String |
getEndLineComment()
Returns the comment that comes after the object on the same line. |
abstract IniItem |
getItem(int index)
Get the item which is at the given index. |
IniItem |
getItem(String name)
Returns the item with the given name, or null if no item exists with the given name. |
Collection<String> |
getItemNames()
This method returns a collection of all the names of all the items within this section. |
abstract Collection<IniItem> |
getItems()
Get a collection of all the items within this section. |
String |
getName()
This method returns the name of this section. |
int |
getNumberOfItems()
Return the number of IniItems that this array has. |
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 . |
int |
hashCode()
|
boolean |
hasItem(IniItem item)
Predicate that returns true if an item is in this section. |
boolean |
hasItem(String itemName)
Predicate that returns true if an item already exists. |
abstract int |
indexOf(IniItem item)
Returns the index of item that is in this section. |
int |
indexOf(String itemName)
Returns the index of item that is in this section. |
boolean |
isCaseSensitive()
Predicate that returns true if this IniSection is case
sensitive, or false if this IniSection is
case insensitive. |
boolean |
isEmpty()
Predicate that returns true if the section has no items, false if it does have at least one item. |
boolean |
merge(IniSection otherSection)
This method merges another IniSection to this section. |
void |
moveItem(int fromIndex,
int toIndex)
This method moves an item at index fromIndex to the index
toIndex . |
void |
moveItem(String name,
int toIndex)
This method moves the item whose names is given to the the index toIndex . |
void |
removeAll()
Removes all the items and its values from the section. |
void |
removeEndLineComment()
Removes an end line comment from the object. |
abstract boolean |
removeItem(IniItem item)
Removes the item this section. |
IniItem |
removeItem(int index)
Removes the item that is at the given index from this section. |
IniItem |
removeItem(String name)
Removes an item whose name matches the given name the section. |
Collection<IniItem> |
removeItems(String[] names)
Removes all the items from this section whose names are within the given array. |
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. |
String |
toString()
|
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.lang.Iterable |
---|
iterator |
Field Detail |
---|
protected IniValidator validator
A reference to this (and subclasses) IniSection
's
IniValidator
which validates the name of this IniSection
and all IniItem
s within this IniSection
.
Constructor Detail |
---|
public IniSection(String name)
Default constructor which creates a new instance of this abstract
IniSection
and sets the IniSection
to have a
default IniValidator
and to be case insensitive.
name
- The name of this IniSection
.
InvalidNameException
- if the name of the IniSection
given is not considered valid by this object's IniValidator
.public IniSection(String name, boolean caseSensitive)
Constructor which creates a new instance of this abstract
IniSection
and sets the IniSection
to have a
default IniValidator
.
name
- The name of this IniSection
.caseSensitive
- Sets whether this IniSection is case sensitive or
not.
InvalidNameException
- if the name of the IniSection
given is not considered valid by this object's IniValidator
.public IniSection(String name, IniValidator validator)
Constructor which creates a new instance of this abstract
IniSection
and sets the IniSection
to be case
insensitive.
name
- The name of this IniSection
.validator
- The IniValidator
of this
IniSection
.
InvalidNameException
- if the name of the IniSection
given is not considered valid by this object's IniValidator
.public IniSection(String name, IniValidator validator, boolean caseSensitive)
Constructor which creates a new instance of this abstract
IniSection
.
name
- The name of this IniSection
.validator
- The IniValidator
of this
IniSection
.caseSensitive
- Sets whether this IniSection is case sensitive or
not.
InvalidNameException
- if the name of the IniSection
given is not considered valid by this object's IniValidator
.Method Detail |
---|
public boolean addItem(IniItem item)
item
- the item to add
public abstract boolean addItem(IniItem item, int index)
item
- the item to addindex
- the index where to add the item, where 0 is the index of the
first item. Any items that already exists at this index will be
moved to index + 1
. If the value is greater than the
number of items within this section, then the item is appended to
the end of the section.
IndexOutOfBoundsException
- if the value of index
is
less than 0.public IniItem addItem(String itemName)
itemName
- The name of the item to add.
public IniItem addItem(String itemName, int index)
itemName
- The name of the item to add.index
- The index where to add the item, where 0 is the index of the
first item. Any items that already exists at this index will be
moved to index + 1
. If the value is greater than the
number of items within this section, then the item is appended to
the end of the section.
IndexOutOfBoundsException
- if the value of index
is
less than 0.public void addItems(String... itemNames)
itemNames
- the names of the items to add.protected abstract IniItem createItem(String name)
IniItem
with the same IniValidator
and case
sensitivity as this object.
name
- The name of the IniItem
to create.
IniItem
with the same
IniValidator
and case sensitivity as this object.
InvalidNameException
- if the name of the IniItem
given is not considered valid by this object's IniValidator
.public boolean equals(Object other)
This predicate returns true if this IniSection
is equal
to the given object. For other
to be equal to this one it
must:
IniSection
.IniSection
.
IniValidator
as this
IniSection
's IniValidator
.IniSection
.*IniSection
.*IniSection
.*IniSection
.*IniItem
s as this
IniSection
.IniItem
s as this
IniSection
.IniItem
s as this
IniSection
.* If the two IniSection
s are
case-sensitive, then these are compared using the
equals(Object)
method. If the two IniSection
s
are case-insensitive, then these are compared using the
String.equalsIgnoreCase(String)
method.
equals
in class Object
other
- The other Object to test for equality.
public String getEndLineComment()
Commentable
Returns the comment that comes after the object on the same line. If not such comment exists an empty string is returned.
getEndLineComment
in interface Commentable
public abstract IniItem getItem(int index)
index
- the index of the item to retrieve.
IndexOutOfBoundsException
- if the given value is less than 0 or
greater or equal to the number of items in this section (i.e.
> getNumberOfItems()-1
.public IniItem getItem(String name)
name
- The name of the item.
public Collection<String> getItemNames()
public abstract Collection<IniItem> getItems()
public String getName()
public int getNumberOfItems()
public String getPostComment()
Commentable
Returns the comment that comes after the object. If not such comment exists an empty string is returned.
getPostComment
in interface Commentable
public String getPreComment()
Commentable
Returns the comment that comes before the object. If not such comment exists an empty string is returned.
getPreComment
in interface Commentable
public IniValidator getValidator()
Gets a reference to this object's IniValidator
.
IniValidator
used by this
IniSection
.public int hashCode()
hashCode
in class Object
public boolean hasItem(IniItem item)
item
- The item to test.
public boolean hasItem(String itemName)
itemName
- the name of the item to test
public abstract int indexOf(IniItem item)
-1
is returned.
item
- The IniItem whose index will be returned.
public int indexOf(String itemName)
-1
is returned.
itemName
- The name of the item whose index will be returned.
public boolean isCaseSensitive()
Predicate that returns true if this IniSection
is case
sensitive, or false if this IniSection
is
case insensitive.
public boolean isEmpty()
public boolean merge(IniSection otherSection)
otherSection
- the other section to merge to this section
public void moveItem(int fromIndex, int toIndex)
fromIndex
to the index
toIndex
.
fromIndex
- The index of the item to movetoIndex
- The index where to place the item, any items already at
that index will be moved to index+1
.
IndexOutOfBoundsException
- if either fromIndex
or
toIndex
is below 0 or greater than or equal to the
number of items in this section (i.e.
> getNumberOfItems()-1
).public void moveItem(String name, int toIndex)
toIndex
.
name
- The name of the item to move.toIndex
- The index where to place the item, any items already at
that index will be moved to index+1
.
IndexOutOfBoundsException
- if toIndex
is below 0 or
greater than or equal to the number of items in this section
(i.e. > getNumberOfItems()-1
), or if the given
name of the item doesn't exist.public void removeAll()
public void removeEndLineComment()
Commentable
setEndLineComment("");
removeEndLineComment
in interface Commentable
public abstract boolean removeItem(IniItem item)
item
- The item to remove.
public IniItem removeItem(int index)
index
- the index of the item to remove
IndexOutOfBoundsException
- if index
is below 0 or
greater than or equal to the number of items in this section (i.e.
> getNumberOfItems() - 1
).public IniItem removeItem(String name)
name
- The name of the name of the item to remove.
public Collection<IniItem> removeItems(String[] names)
names
- An array of the names of the items to remove
public void removePostComment()
Commentable
setPostComment("");
removePostComment
in interface Commentable
public void removePreComment()
Commentable
setPreComment("");
removePreComment
in interface Commentable
public void setEndLineComment(String comment)
Commentable
Set the comment that comes after the object but on the same line.
setEndLineComment
in interface Commentable
comment
- The text comment, if this value is null, then the comment
is set to an empty string.public void setPostComment(String comment)
Commentable
setPostComment
in interface Commentable
comment
- the text comment, if this value is null, then the comment
is set to an empty string.public void setPreComment(String comment)
Commentable
Set the comment that comes before the object.
setPreComment
in interface Commentable
comment
- the text comment, if this value is null, then the comment
is set to an empty string.public String toString()
toString
in class Object
public abstract Object clone()
This class implements the Cloneable interface, but leaves implementation to subclasses which override this class.
clone
in class Object
thisObject.equals(
thisObject.clone() );
, but returns false for thisObject ==
thisObject.clone();
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |