Package org.acplt.oncrpc.apps.jrpcgen
Class JrpcgenItemTable<T extends JrpcgenItem>
java.lang.Object
org.acplt.oncrpc.apps.jrpcgen.JrpcgenItemTable<T>
- Type Parameters:
T- An interface extending the interfaceJrpcgenItemor a class implementing the interfaceJrpcgenItem.
- All Implemented Interfaces:
Iterable<T>
- Direct Known Subclasses:
JrpcgenConst.Table,JrpcgenDeclaration.Table,JrpcgenXdrDefinition.Table
An item table collects items sharing the same scope. In detail, each item within
an item table comes with an unique identifier. An item table is backed by both a
hash map and a linked list. The former ensures items with unique identifiers,
the latter stores them in the sequence of their appearance.
An item list is prepared to hold a collection of any item as well as items
of a defined type. The global definition list of an RPC/XDR specification will
contain realisations of class JrpcgenXdrDefinition, for example.
- Author:
- Harald Wirths <hwirths@nde.ag>
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanAdds the passed item to this table, if its identifier is unknown to this table.voidclear()Clears this table.Returns the first item of this table.<U extends JrpcgenItem>
UReturns the item based on the passed type and mapped to the passed identifier.Returns the item mapped to the passed identifier.Returns the list of items stored in this table.Returns the last item of this table.booleanisEmpty()Returns whether the table is empty.booleanisUnknownIdentifier(String identifier) Returns whether the passed idnetifier is unknown to the table.iterator()Returns an iterator to the items of this table.<U extends JrpcgenItem>
Iterator<U> Returns an iterator to the items of this table, which are instances of the passed type.voidPuts the passed item to this table, if no item with the same identifier is already in this table.intsize()Returns the size of this table reflecting the number of items kept in this table.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
JrpcgenItemTable
public JrpcgenItemTable()
-
-
Method Details
-
getItemList
Returns the list of items stored in this table. The returned list may be empty, if no item was put to this table so far.- Returns:
- The list of items stored in this table.
-
clear
public void clear()Clears this table. The table will not contain any item afterwards. -
isEmpty
public boolean isEmpty()Returns whether the table is empty.- Returns:
trueif the table does not contain any element,falseotherwise.
-
size
public int size()Returns the size of this table reflecting the number of items kept in this table.- Returns:
- The number of items stored in this table.
-
isUnknownIdentifier
Returns whether the passed idnetifier is unknown to the table. In detaiĺ, this method checks the table for the existence of an item whose identifier equals the passed one and returnstrue, if no item was found, orfalse, if an item was found having set the passed identifier.- Parameters:
identifier- The identifier to check for.- Returns:
trueif no item was found whose identifier equals the passed one,falseotherwise.
-
addItem
Adds the passed item to this table, if its identifier is unknown to this table.- Parameters:
item- The item to be added to this table.- Returns:
trueif the item was added due to the fact, that its identifier was unknown to the table before,falseotherwise.
-
putItem
Puts the passed item to this table, if no item with the same identifier is already in this table.- Parameters:
item- The item to be put into this table.- Throws:
IllegalArgumentException- Passing an item with an already known identifier to this table will cause this exception to be thrown.
-
getItem
Returns the item mapped to the passed identifier. The item is looked up in the hash map of this table.- Parameters:
identifier- The identifier of the requested item.- Returns:
- The requested item will be returned, if the table
contains an item with the passed identifier,
nullotherwise.
-
getItem
Returns the item based on the passed type and mapped to the passed identifier. The item is looked up in the hash map of this table.- Type Parameters:
U- The required type of the requested item.- Parameters:
clazz- The class object representing the expected type of the requested item.identifier- The identifier of the requested item.- Returns:
- The requested item will be returned, if an item is mapped to
the passed identifier and the item is an instance of the passed
type. Otherwise
nullwill be returned.
-
getFirstItem
Returns the first item of this table. The first item is taken from the linked list of this table and reflects the first item that appeared to this table.- Returns:
- The first item of this table if at least
one item is in this table,
nullotherwise.
-
getLastItem
Returns the last item of this table. The last item is taken from the linked list of this table and reflects the last item that appeared to this table.- Returns:
- The last item of this table if at least one item
is in this table,
nullotherwise.
-
iterator
Returns an iterator to the items of this table. The iterator is taken from the linked list and therefore iterates over the items in the sequence of their appearance to this table.- Specified by:
iteratorin interfaceIterable<T extends JrpcgenItem>- Returns:
- An iterator to the items of this table taken from the internal used linked list.
-
iterator
Returns an iterator to the items of this table, which are instances of the passed type. The iterator wraps an iterator taken from the linked list and therefore iterates over the matching items in the sequence of their appearance to this table.- Type Parameters:
U- The type of the items provided by the returned iterator.- Parameters:
clazz- The class instance of the requested item type.- Returns:
- An iterator to the items of this table with the requested type taken from the internal used linked list.
-