public final class IdentifierDictionary extends Object implements IIdentifierDictionary
IIdentifierDictionary
. This class is declared final because overriding the methods could
cause serious bugs. To provide specialized id functionality, the class IdentifierHelper
can be subclassed
instead.Modifier and Type | Field and Description |
---|---|
private IIdentifierField[] |
fieldArray |
private Map<String,Integer> |
fieldIndices |
private Map<String,IIdentifierField> |
fieldMap |
protected int |
maxIndex |
private String |
name |
protected int |
numberOfFields |
Constructor and Description |
---|
IdentifierDictionary(String name,
List<IIdentifierField> fieldList)
Create an identifier dictionary with fields from
fieldList . |
Modifier and Type | Method and Description |
---|---|
private void |
addField(IIdentifierField field,
int index)
Add a field.
|
private void |
addFields(List<IIdentifierField> fields)
Add a list of fields.
|
IIdentifierField |
getField(int index)
Get a field by index.
|
IIdentifierField |
getField(String fieldName)
Get a field by name or
null if it doesn't exist in this dictionary. |
int |
getFieldIndex(String fieldName)
Get a field's index in the array or
null if it doesn't exist. |
List<IIdentifierField> |
getFieldList()
Get the list of fields.
|
List<String> |
getFieldNames()
Get the list of fields in this dictionary, which is cloned in case the caller modifies it.
|
int |
getFieldValue(IIdentifier compact,
int idx)
Extract value of a field by index.
|
int |
getFieldValue(IIdentifier compact,
String field)
Extract value of a named field from packed id.
|
int |
getMaxIndex()
Get the maximum index in the field array.
|
String |
getName()
Get the name of this dictionary.
|
int |
getNumberOfFields()
Get the number of fields in the dictionary.
|
boolean |
hasField(String fieldName)
True if the dictionary has a field called
fieldName ; false if not. |
boolean |
isValid(IExpandedIdentifier id)
Check that an
IExpandedIdentifier is valid for this dictionary. |
IIdentifier |
pack(IExpandedIdentifier id)
Pack an expanded id.
|
String |
toString()
Convert the dictionary to a String.
|
IExpandedIdentifier |
unpack(IIdentifier compact)
Unpack a packed id.
|
IExpandedIdentifier |
unpack(IIdentifier compact,
List<Integer> indices)
Unpack id, only including fields with indices in list.
|
private IIdentifierField[] fieldArray
private Map<String,IIdentifierField> fieldMap
private final String name
protected int numberOfFields
protected int maxIndex
public IdentifierDictionary(String name, List<IIdentifierField> fieldList)
fieldList
. A dictionary cannot be modified once it
is created.name
- The name of the dictionary.fieldList
- The list of fields.public String getName()
getName
in interface IIdentifierDictionary
public List<IIdentifierField> getFieldList()
getFieldList
in interface IIdentifierDictionary
public IIdentifierField getField(String fieldName)
null
if it doesn't exist in this dictionary.getField
in interface IIdentifierDictionary
fieldName
- The field.fieldName
or null if doesn't exist.public IIdentifierField getField(int index)
getField
in interface IIdentifierDictionary
index
in the array.ArrayOutOfBoundsException
- if index is not valid.public int getFieldIndex(String fieldName)
null
if it doesn't exist.getFieldIndex
in interface IIdentifierDictionary
fieldName
- The name of the field.fieldName
or null if doesn't exist.public List<String> getFieldNames()
getFieldNames
in interface IIdentifierDictionary
public int getNumberOfFields()
getNumberOfFields
in interface IIdentifierDictionary
public int getMaxIndex()
getMaxIndex
in interface IIdentifierDictionary
public boolean hasField(String fieldName)
fieldName
; false if not.hasField
in interface IIdentifierDictionary
fieldName
- The name of the field.fieldName
exists in this dictionary; false if not.public IExpandedIdentifier unpack(IIdentifier compact)
unpack
in interface IIdentifierDictionary
compact
- The packed id.public IExpandedIdentifier unpack(IIdentifier compact, List<Integer> indices)
IIdentifierDictionary
unpack
in interface IIdentifierDictionary
compact
- The packed idindices
- The indices of the fields to unpack.public IIdentifier pack(IExpandedIdentifier id)
pack
in interface IIdentifierDictionary
id
- The expanded id.public int getFieldValue(IIdentifier compact, String field)
getFieldValue
in interface IIdentifierDictionary
compact
- The packed id.field
- The field name.public int getFieldValue(IIdentifier compact, int idx)
getFieldValue
in interface IIdentifierDictionary
compact
- The packed id.field
- The field name.private void addField(IIdentifierField field, int index)
field
- The field object.index
- The field index.private void addFields(List<IIdentifierField> fields)
fields
- The list of fields.public boolean isValid(IExpandedIdentifier id)
IExpandedIdentifier
is valid for this dictionary.
This method checks that the sizes are the same and that the values
are valid for their corresponding fields.isValid
in interface IIdentifierDictionary
Copyright © 2016 Linear Collider Detector (LCD). All rights reserved.