se.js.jesdob
Class DobCollection

java.lang.Object
  extended by se.js.jesdob.DobCollection
All Implemented Interfaces:
java.lang.Iterable<IDob>, IDobCollection

public class DobCollection
extends java.lang.Object
implements IDobCollection, java.lang.Iterable<IDob>

A DobCollection is a collection containing one or more IDobs (dynamic objects). It is possible to add objects to a collection, and to remove objects from a collection.

It is possible to get IDobs from the collection, by index, or by searching a specific attribute and value. You can also filter the DobCollection by using a IDobQuery-object. This will make the IDob-object act more like a database.

DobCollections can be exported to text as json-format, xml-format or dob-format. They can then be saved to files and read as dynamic objects when they are needed.


Constructor Summary
DobCollection()
          Parameterless constructor.
DobCollection(IDob... dobs)
          Constructor.
DobCollection(java.lang.String... dobsData)
          Constructor.
 
Method Summary
 IDobCollection add(IDob... dobs)
          Adds one or more dobs to the dob collection.
 IDobCollection add(IDobCollection dobCollection)
          Adds the content of a dob collection to a dob collection.
 IDobCollection add(java.lang.String... dobsData)
          Adds one or more dobs from dob data-strings.
 IDobCollection clear()
          Removes all data from the DobCollection
 IDobCollection filter(IDobQuery query)
          Applies a filter on this DobCollection and returns the filtered version.
 IDob get(int index)
          Returns a Dob from a specific index in the collection.
 IDob get(java.lang.String attribute, java.lang.String value)
          Returns the first dob in the collection where a specific attribute has a specific value.
 IDobCollection getAll(java.lang.String attribute, java.lang.String value)
          Returns a new DobCollection containing all Dobs which have a particular value for a particular attribute.
 boolean isEmpty()
          Returns true or false, depending on if the collection is empty or not.
 java.util.Iterator<IDob> iterator()
          Returns an iterator used for iterating Dobs in the DobCollection.
 boolean remove(java.lang.String attr, java.lang.String value)
          Removes all dobs where a specific attribute has a specific value.
 int size()
          Returns the number of dobs in the collection.
 java.lang.String toDob()
          Returns the content of the collection, in dob-format.
 java.lang.String toJson()
          Returns the content of the collection, in json-format.
 java.util.List<IDob> toList()
          Returns a new list with dobs from the collection.
 java.lang.String toXml()
          Returns the content of the collection, in xml-format.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DobCollection

public DobCollection()
Parameterless constructor.


DobCollection

public DobCollection(IDob... dobs)
Constructor. Creates a new collection filled with a list of attached dobs.

Parameters:
dobs - The dobs we want to fill our collection with.

DobCollection

public DobCollection(java.lang.String... dobsData)
Constructor. Creates a new collection filled with dobs created from string list with dob data.

Parameters:
dobsData - This dob data will be converted to dob, and added to the new collection.
Method Detail

add

public IDobCollection add(IDob... dobs)
Adds one or more dobs to the dob collection.

Specified by:
add in interface IDobCollection
Parameters:
dobs - The dobs that should be added to the collection.
Returns:
The DobCollection object, to enable chaining.

add

public IDobCollection add(IDobCollection dobCollection)
Adds the content of a dob collection to a dob collection.

Specified by:
add in interface IDobCollection
Parameters:
dobCollection - The DobCollection we want to add the content from.
Returns:
The DobCollection object, to enable chaining.

add

public IDobCollection add(java.lang.String... dobsData)
Adds one or more dobs from dob data-strings. The dob data-strings will be converted to dobs and added to the collection.

Specified by:
add in interface IDobCollection
Parameters:
dobsData - The dob data we want to convert to dobs and add to the collection.
Returns:
The DobCollection object, to enable chaining.

remove

public boolean remove(java.lang.String attr,
                      java.lang.String value)
Removes all dobs where a specific attribute has a specific value. Returns true if any objects were removed, and false if no objects were removed.

Specified by:
remove in interface IDobCollection
Parameters:
attr - The attribute we want to check for.
value - The value we want to check for.
Returns:
If any object were removed from the collection.

get

public IDob get(int index)
Returns a Dob from a specific index in the collection.

Specified by:
get in interface IDobCollection
Parameters:
index - A specific Dob index of the collection.
Returns:
The Dob from the specific index in the collection.

size

public int size()
Returns the number of dobs in the collection.

Specified by:
size in interface IDobCollection
Returns:
The number of dobs in the collection.

isEmpty

public boolean isEmpty()
Returns true or false, depending on if the collection is empty or not.

Specified by:
isEmpty in interface IDobCollection
Returns:
True or false, depending on if the collection is empty or not.

toList

public java.util.List<IDob> toList()
Returns a new list with dobs from the collection.

Specified by:
toList in interface IDobCollection
Returns:
A new list with dobs from the collection.

toJson

public java.lang.String toJson()
Returns the content of the collection, in json-format.

Specified by:
toJson in interface IDobCollection
Returns:
The content of the collection, in json-format.

toDob

public java.lang.String toDob()
Returns the content of the collection, in dob-format.

Specified by:
toDob in interface IDobCollection
Returns:
The content of the collection, in dob-format.

toXml

public java.lang.String toXml()
Returns the content of the collection, in xml-format.

Specified by:
toXml in interface IDobCollection
Returns:
The content of the collection, in xml-format.

get

public IDob get(java.lang.String attribute,
                java.lang.String value)
Returns the first dob in the collection where a specific attribute has a specific value. If no such object exists in the collection, this method will return null.

Specified by:
get in interface IDobCollection
Parameters:
attribute - The specific attribute.
value - The specific value.
Returns:
A dob object where the specified attribute matches the specified value.

getAll

public IDobCollection getAll(java.lang.String attribute,
                             java.lang.String value)
Returns a new DobCollection containing all Dobs which have a particular value for a particular attribute. If no such Dobs exists, an empty collection will be returned.

Specified by:
getAll in interface IDobCollection
Parameters:
attribute - The specific attribute.
value - The specific value.
Returns:
A new Dob collection containing all Dobs matching the search criterias.

filter

public IDobCollection filter(IDobQuery query)
Applies a filter on this DobCollection and returns the filtered version. The filtering is done is by the applied IDobQuery object.

Specified by:
filter in interface IDobCollection
Parameters:
query - The query we want to use for filtering the collection.
Returns:
The new collection, produced by filtering the original collection.

clear

public IDobCollection clear()
Removes all data from the DobCollection

Specified by:
clear in interface IDobCollection
Returns:
The DobCollection, to enable chaining.

iterator

public java.util.Iterator<IDob> iterator()
Returns an iterator used for iterating Dobs in the DobCollection.

Specified by:
iterator in interface java.lang.Iterable<IDob>
Returns:
a new iterator used for iterating Dobs in the DobCollection.