Package org.simpleframework.xml.util
Class Dictionary<T extends Entry>
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractSet<T>
-
- org.simpleframework.xml.util.Dictionary<T>
-
- All Implemented Interfaces:
java.lang.Iterable<T>
,java.util.Collection<T>
,java.util.Set<T>
public class Dictionary<T extends Entry> extends java.util.AbstractSet<T>
TheDictionary
object represents a mapped set of entry objects that can be serialized and deserialized. This is used when there is a need to load a list of objects that can be mapped using a name attribute. Using this object avoids the need to implement a commonly required pattern of building a map of XML element objects.<dictionary> <entry name="example"> <element>example text</element> </entry> <entry name="example"> <element>example text</element> </entry> </dictionary>
This can contain implementations of theEntry
object which contains a required "name" attribute. Implementations of the entry object can add further XML attributes an elements. This must be annotated with theElementList
annotation in order to be serialized and deserialized as an object field.- Author:
- Niall Gallagher
- See Also:
Entry
-
-
Constructor Summary
Constructors Constructor Description Dictionary()
Constructor for theDictionary
object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
add(T item)
This method is used to add the provided entry to this set.T
get(java.lang.String name)
This is used to acquire anEntry
from the set by its name.java.util.Iterator<T>
iterator()
Returns an iterator ofEntry
objects which can be used to remove items from this set.T
remove(java.lang.String name)
This is used to remove anEntry
from the set by its name.int
size()
This returns the number ofEntry
objects within the dictionary.-
Methods inherited from class java.util.AbstractCollection
addAll, clear, contains, containsAll, isEmpty, remove, retainAll, toArray, toArray, toString
-
-
-
-
Method Detail
-
add
public boolean add(T item)
This method is used to add the provided entry to this set. If an entry of the same name already existed within the set then it is replaced with the specifiedEntry
object.
-
size
public int size()
This returns the number ofEntry
objects within the dictionary. This will use the internal map to acquire the number of entry objects that have been inserted to the map.
-
iterator
public java.util.Iterator<T> iterator()
Returns an iterator ofEntry
objects which can be used to remove items from this set. This will use the internal map object and return the iterator for the map values.- Specified by:
iterator
in interfacejava.util.Collection<T extends Entry>
- Specified by:
iterator
in interfacejava.lang.Iterable<T extends Entry>
- Specified by:
iterator
in interfacejava.util.Set<T extends Entry>
- Specified by:
iterator
in classjava.util.AbstractCollection<T extends Entry>
- Returns:
- this returns an iterator for the entry objects
-
get
public T get(java.lang.String name)
This is used to acquire anEntry
from the set by its name. This uses the internal map to look for the entry, if the entry exists it is returned, if not this returns null.- Parameters:
name
- this is the name of the entry object to retrieve- Returns:
- this returns the entry mapped to the specified name
-
remove
public T remove(java.lang.String name)
This is used to remove anEntry
from the set by its name. This uses the internal map to look for the entry, if the entry exists it is returned and removed from the map.- Parameters:
name
- this is the name of the entry object to remove- Returns:
- this returns the entry mapped to the specified name
-
-