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 interface `JrpcgenItem` or a class implementing the interface `JrpcgenItem`.

All Implemented Interfaces:
  `Iterable<T>`

Direct Known Subclasses:
  `JrpcgenConst.Table`, `JrpcgenDeclaration.Table`, `JrpcgenXdrDefinition.Table`

public class JrpcgenItemTable<T extends JrpcgenItem> extends Object implements Iterable<T>
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
Constructor
Description
`JrpcgenItemTable()`

## Method Summary

Modifier and Type
Method
Description
`boolean`
`addItem(T item)`
Adds the passed item to this table, if its identifier is unknown to this table.
`void`
`clear()`
Clears this table.
`T`
`getFirstItem()`
Returns the first item of this table.
`<U extends JrpcgenItem>
U`
`getItem(Class<U> clazz, String identifier)`
Returns the item based on the passed type and mapped to the passed identifier.
`T`
`getItem(String identifier)`
Returns the item mapped to the passed identifier.
`List<T>`
`getItemList()`
Returns the list of items stored in this table.
`T`
`getLastItem()`
Returns the last item of this table.
`boolean`
`isEmpty()`
Returns whether the table is empty.
`boolean`
`isUnknownIdentifier(String identifier)`
Returns whether the passed idnetifier is unknown to the table.
`Iterator<T>`
`iterator()`
Returns an iterator to the items of this table.
`<U extends JrpcgenItem>
Iterator<U>`
`iterator(Class<U> clazz)`
Returns an iterator to the items of this table, which are instances of the passed type.
`void`
`putItem(T item)`
Puts the passed item to this table, if no item with the same identifier is already in this table.
`int`
`size()`
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, wait`

### Methods inherited from interface java.lang.Iterable

`forEach, spliterator`

## Constructor Details

### JrpcgenItemTable

public JrpcgenItemTable()

## Method Details

### getItemList

public List<T> 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:
  `true` if the table does not contain any element, `false` otherwise.

### 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

public boolean isUnknownIdentifier(String identifier)
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 returns `true`, if no item was found, or `false`, if an item was found having set the passed identifier.

Parameters:
  `identifier` - The identifier to check for.
Returns:
  `true` if no item was found whose identifier equals the passed one, `false` otherwise.

### addItem

public boolean addItem(T item)
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:
  `true` if the item was added due to the fact, that its identifier was unknown to the table before, `false` otherwise.

### putItem

public void putItem(T item)
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

public T getItem(String identifier)
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, `null` otherwise.

### getItem

public <U extends JrpcgenItem> U getItem(Class<U> clazz, String identifier)
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 `null` will be returned.

### getFirstItem

public T 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, `null` otherwise.

### getLastItem

public T 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, `null` otherwise.

### iterator

public Iterator<T> 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:
  `iterator` in interface `Iterable<T extends JrpcgenItem>`
Returns:
  An iterator to the items of this table taken from the internal used linked list.

### iterator

public <U extends JrpcgenItem> Iterator<U> iterator(Class<U> clazz)
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.