org.dtools.ini
Class BasicIniSection

java.lang.Object
  extended by org.dtools.ini.IniSection
      extended by org.dtools.ini.BasicIniSection
All Implemented Interfaces:
Cloneable, Iterable<IniItem>, Commentable

public class BasicIniSection
extends IniSection

A basic\simple implementation of the IniSection interface.

This class implements only the abstract methods of AbstractIniSection and nothing else. Therefore, the performance of this class is not as good as it could be. However the class stays simple and provides a quick implementation for the IniFile interface.

Since:
0.1.15
Version:
1.0.0
Author:
David Lewis

Field Summary
 
Fields inherited from class org.dtools.ini.IniSection
validator
 
Fields inherited from interface org.dtools.ini.Commentable
COMMENT_SYMBOL
 
Constructor Summary
BasicIniSection(String name)
          Default constructor which creates a new instance of this IniSection and sets the IniSection to have a default IniValidator and to be case insensitive.
BasicIniSection(String name, boolean caseSensitive)
          Default constructor which creates a new instance of this IniSection and sets the IniSection to have a default IniValidator and to be case insensitive.
BasicIniSection(String name, IniValidator validator)
          Default constructor which creates a new instance of this IniSection and sets the IniSection to have a default IniValidator and to be case insensitive.
BasicIniSection(String name, IniValidator validator, boolean caseSensitive)
          Default constructor which creates a new instance of this IniSection and sets the IniSection to have a default IniValidator and to be case insensitive.
 
Method Summary
 boolean addItem(IniItem item, int index)
          Adds an IniItem to this section at the given index.
 Object clone()
          This class implements the Cloneable interface, but leaves implementation to subclasses which override this class.
protected  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.
 IniItem getItem(int index)
          Get the item which is at the given index.
 Collection<IniItem> getItems()
          Get a collection of all the items within this section.
 int indexOf(IniItem item)
          Returns the index of item that is in this section.
 Iterator<IniItem> iterator()
           
 boolean removeItem(IniItem item)
          Removes the item this section.
 
Methods inherited from class org.dtools.ini.IniSection
addItem, addItem, addItem, addItems, equals, getEndLineComment, getItem, getItemNames, getName, getNumberOfItems, getPostComment, getPreComment, getValidator, hashCode, hasItem, hasItem, indexOf, isCaseSensitive, isEmpty, merge, moveItem, moveItem, removeAll, removeEndLineComment, removeItem, removeItem, removeItems, removePostComment, removePreComment, setEndLineComment, setPostComment, setPreComment, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BasicIniSection

public BasicIniSection(String name)

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

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

BasicIniSection

public BasicIniSection(String name,
                       IniValidator validator)

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

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

BasicIniSection

public BasicIniSection(String name,
                       boolean caseSensitive)

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

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

BasicIniSection

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

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

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

addItem

public boolean addItem(IniItem item,
                       int index)
Description copied from class: IniSection
Adds an IniItem to this section at the given index. If an item already in the section has the same name as the one being added, then the method will not overwrite the item and will instead return false.

Specified by:
addItem in class IniSection
Parameters:
item - 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.
Returns:
true if the item was added successfully, false if the item already existed or could not be added

createItem

protected IniItem createItem(String name)
Description copied from class: IniSection

This method creates and returns a new instance of an IniItem with the same IniValidator and case sensitivity as this object.

Specified by:
createItem in class IniSection
Parameters:
name - The name of the IniItem to create.
Returns:
A new instance of an IniItem with the same IniValidator and case sensitivity as this object.

getItem

public IniItem getItem(int index)
Description copied from class: IniSection
Get the item which is at the given index.

Specified by:
getItem in class IniSection
Parameters:
index - the index of the item to retrieve.
Returns:
The item that is at the given index.

getItems

public Collection<IniItem> getItems()
Description copied from class: IniSection
Get a collection of all the items within this section.

Specified by:
getItems in class IniSection
Returns:
A collection of all the items.

indexOf

public int indexOf(IniItem item)
Description copied from class: IniSection
Returns the index of item that is in this section. If no such item exists, then the value -1 is returned.

Specified by:
indexOf in class IniSection
Parameters:
item - The IniItem whose index will be returned.
Returns:
The index of the given item.

removeItem

public boolean removeItem(IniItem item)
Description copied from class: IniSection
Removes the item this section. If the given item does not exists in the section, then the method does nothing.

Specified by:
removeItem in class IniSection
Parameters:
item - The item to remove.
Returns:
boolean, true if the IniItem was removed, false it the given IniItem did not exists in the first place.

clone

public Object clone()
Description copied from class: IniSection

This class implements the Cloneable interface, but leaves implementation to subclasses which override this class.

Specified by:
clone in class IniSection
Returns:
An object which is an instance of class, has the same values as this object, would return true for thisObject.equals( thisObject.clone() );, but returns false for thisObject == thisObject.clone();
Since:
1.0.00

iterator

public Iterator<IniItem> iterator()