|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.dtools.ini.IniFile
public abstract class IniFile
An IniFile is an abstract class which defines the public and protected methods of an IniFile implementation. This class is designed to represent a physical INI file (a.k.a. a configuration file) on a hard disk, which is a type of file that stores properties of configuration data for applications.
Field Summary | |
---|---|
protected IniValidator |
validator
A reference to this IniFile 's IniValidator
which validates all names for IniSections and
IniItems . |
Constructor Summary | |
---|---|
IniFile()
Default constructor which creates a new instance of this abstract IniFile and sets the IniFile to have a default
IniValidator and to be case insensitive. |
|
IniFile(boolean caseSensitive)
Constructor which creates a new instance of this abstract IniFile and sets the IniFile to have a default
IniValidator . |
|
IniFile(IniValidator validator)
Constructor which creates a new instance of this abstract IniFile and sets the IniFile to be case insensitive. |
|
IniFile(IniValidator validator,
boolean caseSensitive)
Constructor which creates a new instance of this abstract IniFile . |
Method Summary | |
---|---|
boolean |
addOrMergeSection(IniSection otherSection)
This method adds the given section to the end of the IniFile if a section with the same name does not already exist. |
boolean |
addSection(IniSection section)
This method adds the given IniSection to the
IniFile providing that there are no existing sections with
the same name as the given IniSection . |
abstract boolean |
addSection(IniSection section,
int index)
Adds a section to this INI file. |
IniSection |
addSection(String sectionName)
Adds a section to this INI file. |
IniSection |
addSection(String sectionName,
int index)
Adds a new section to this INI file which has the given name. |
void |
addSections(String... names)
Adds multiple new sections to this INI file. |
abstract Object |
clone()
|
protected abstract IniSection |
createSection(String name)
This method creates and returns a new instance of an IniSection with the same IniValidator and case
sensitivity as this object. |
boolean |
equals(Object other)
This predicate returns true if this IniFile is equal to
the given object. |
int |
getNumberOfItems()
Returns the total number of all the items, in every section, that this IniFile has. |
int |
getNumberOfSections()
Returns the number of sections this IniFile object has. |
abstract IniSection |
getSection(int index)
Get the section which is at the given index. |
IniSection |
getSection(String name)
Returns the section that is called name , or null if no such
section exists. |
Collection<String> |
getSectionNames()
Gets a collection of the names of all the sections in this IniFile. |
abstract Collection<IniSection> |
getSections()
Gets a collection of all the sections within this INI file. |
IniValidator |
getValidator()
Returns a reference to this object's IniValidator which
is used to validate names of this IniFile 's
IniSection s and their IniItem s. |
int |
hashCode()
|
boolean |
hasSection(IniSection section)
Predicate that returns true if this IniFile has a given section. |
boolean |
hasSection(String name)
Predicate that returns true if this IniFile has a section with the given name. |
abstract int |
indexOf(IniSection section)
Get the index of the given section, where 0 is the index is the first section. |
int |
indexOf(String sectionName)
Get the index of the section whose name is given, where 0 is the index is the first section. |
boolean |
isCaseSensitive()
Predicate that returns true if this object is case sensitive, or false if it is case insensitive. |
boolean |
isEmpty()
Predicate that returns true if this IniFile has no sections. |
boolean |
merge(IniFile otherIni)
This method merges an IniFile with this IniFile, and that all the sections within the other IniFile are copied to this IniFile, and if the two IniFiles share any similarly named sections, then those sections are merged together. |
void |
moveSection(int fromIndex,
int toIndex)
This method moves a section at index fromIndex to the index
toIndex . |
boolean |
moveSection(String name,
int toIndex)
This method moves the section whose names is given to the the index toIndex . |
void |
removeAll()
Removes all the sections from this IniFile. |
abstract boolean |
removeSection(IniSection section)
Removes the given section only if the section is within this IniFile |
IniSection |
removeSection(int index)
Removes a section from the IniFile. |
IniSection |
removeSection(String name)
Removes a section from the IniFile. |
Collection<IniSection> |
removeSections(String[] names)
Removes all the sections whose names are in the given array. |
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 IniFile
's IniValidator
which validates all names for IniSections
and
IniItems
.
Constructor Detail |
---|
public IniFile()
Default constructor which creates a new instance of this abstract
IniFile
and sets the IniFile
to have a default
IniValidator
and to be case insensitive.
public IniFile(boolean caseSensitive)
Constructor which creates a new instance of this abstract
IniFile
and sets the IniFile to have a default
IniValidator
.
caseSensitive
- Sets whether this instance of IniFile
is case sensitive or not.public IniFile(IniValidator validator)
Constructor which creates a new instance of this abstract
IniFile
and sets the IniFile to be case insensitive.
validator
- Sets the IniValidator
if this instance of
IniFile
.public IniFile(IniValidator validator, boolean caseSensitive)
Constructor which creates a new instance of this abstract
IniFile
.
validator
- Sets the IniValidator
if this instance of
IniFile
.caseSensitive
- Sets whether this instance of IniFile
is case sensitive or not.Method Detail |
---|
public boolean addOrMergeSection(IniSection otherSection)
This method adds the given section to the end of the IniFile if a section with the same name does not already exist. If a section with the same name does exists, then the given section is merged with the existing section providing that the two sections do not contain identically named items.
A merge is also not possible if the given section is not compatible
with the policies of the IniFile
. That is to say, the
IniSection
has a different case-sensitivity, or an unequal
IniValidator
to the IniFile
.
If a merge is performed, then the index of the existing section does not change.
otherSection
- the new section to add or merge to this IniFile
InvalidNameException
- If the name of the given section is not
considered valid by the IniFile
's
IniValidator
.public boolean addSection(IniSection section)
This method adds the given IniSection
to the
IniFile
providing that there are no existing sections with
the same name as the given IniSection
.
The given section can also not be added if the given section is not
compatible with the policies of the IniFile
. That is to say
the IniSection
has a different case-sensitivity, or an
unequal IniValidator
to the IniFile
.
section
- The section to add to this INI file.
InvalidNameException
- If the name of the given section is not
considered valid by the IniFile
's
IniValidator
.public abstract boolean addSection(IniSection section, int index)
Adds a section to this INI file. If an existing section has the same name as the given section, then the new section is not added and the method returns false. If the given section is of a type that is not compatible with the class that implements this interface, then a compatible copy of the section is made which is then added to the class.
section
- The section to add to this INI file.index
- The index where to add the section, where 0 is the index of
the first section. Any section that already exists at this index
will be moved to index + 1
. If the value is greater
than the number of sections within this INI file, then the section
is appended to the end of the INI file.
IndexOutOfBoundsException
- if the value of index
is
less than 0.public IniSection addSection(String sectionName)
sectionName
-
public IniSection addSection(String sectionName, int index)
sectionName
- The name of the new section to add.index
- The index where to add the section, where 0 is the index of
the first section. Any section that already exists at this index
will be moved to index + 1
. If the value is greater
than the number of sections within this INI file, then the section
is appended to the end of the INI file.
IndexOutOfBoundsException
- if the value of index
is
less than 0.public void addSections(String... names)
names
- a list of names for the new sections.protected abstract IniSection createSection(String name)
IniSection
with the same IniValidator
and case
sensitivity as this object.
name
- The name of the IniSection
to create.
IniSection
with the same
IniValidator
and case sensitivity as this object.
InvalidNameException
- if the name of the IniSection
given is not considered valid by this object's IniValidator
.public boolean equals(Object other)
This predicate returns true if this IniFile
is equal to
the given object. For other
to be equal to this one it
must:
IniFile
.IniFile
.
IniValidator
as this
IniFile
's IniValidator
.IniSection
s as this
IniFile
.IniSection
s as this
IniFile
.IniSection
s as this
IniFile
.
equals
in class Object
other
- The other Object to test for equality.
public int getNumberOfItems()
public int getNumberOfSections()
public abstract IniSection getSection(int index)
index
- the index of the section to retrieve.
IndexOutOfBoundsException
- if the given value is less than 0 or
greater or equal to the number of sections in this INI file (i.e.
> getNumberOfSections()-1
.public IniSection getSection(String name)
name
, or null if no such
section exists.
name
- the name of the section to return
public Collection<String> getSectionNames()
public abstract Collection<IniSection> getSections()
public IniValidator getValidator()
Returns a reference to this object's IniValidator
which
is used to validate names of this IniFile
's
IniSection
s and their IniItem
s.
IniFile
's IniValidator
.public int hashCode()
hashCode
in class Object
public boolean hasSection(IniSection section)
section
- The section to test.
public boolean hasSection(String name)
name
- The name of the section to test
public abstract int indexOf(IniSection section)
section
- The section whose index will be retured
public int indexOf(String sectionName)
sectionName
- The name of the section whose index will be retured
public boolean isCaseSensitive()
Predicate that returns true if this object is case sensitive, or false if it is case insensitive.
public boolean isEmpty()
public boolean merge(IniFile otherIni)
otherIni
- the other IniFile that will be merged with this IniFile.
IniSection.merge(org.dtools.ini.IniSection)
public void moveSection(int fromIndex, int toIndex)
fromIndex
to the index
toIndex
.
fromIndex
- The index of the section to move.toIndex
- The index where to place the section, any sections 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 sections in this INI file (i.e.
> getNumberOfSections()-1
).public boolean moveSection(String name, int toIndex)
toIndex
.
name
- The name of the section to move.toIndex
- The index where to place the section, any sections 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 section in this INI file (i.e.
> getNumberOfSections()-1
).
NullPointerException
- if no section in the section exists called
name
.public void removeAll()
public abstract boolean removeSection(IniSection section)
section
- The section to remove.
public IniSection removeSection(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 section in this INI file
(i.e. > getNumberOfSections()-1
).public IniSection removeSection(String name)
name
- The name of the section to remove
public Collection<IniSection> removeSections(String[] names)
names
- The names of all the sections to remove
public String toString()
toString
in class Object
public abstract Object clone()
clone
in class Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |