Package com.igormaznitsa.jbbp
Class JBBPNamedNumericFieldMap
java.lang.Object
com.igormaznitsa.jbbp.JBBPNamedNumericFieldMap
- All Implemented Interfaces:
JBBPFieldFinder
Implements a storage to keep named fields. it is not a thread-safe one
- Since:
- 1.0
-
Constructor Summary
ConstructorsConstructorDescriptionEmpty constructor which makes a map with null provider.JBBPNamedNumericFieldMap(JBBPExternalValueProvider externalValueProvider) A Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clear the map.findFieldForName(String fieldName) Find a field for its name.<T extends JBBPAbstractField>
TfindFieldForNameAndType(String fieldName, Class<T> fieldType) Find a field for its name and type pair.findFieldForPath(String fieldPath) Find a field for its path.<T extends JBBPAbstractField>
TfindFieldForPathAndType(String fieldPath, Class<T> fieldType) Find a field for its path and type pair.<T extends JBBPAbstractField>
TfindFieldForType(Class<T> fieldType) Find unique field for defined class.<T extends JBBPAbstractField>
TfindFirstFieldForType(Class<T> fieldType) Find the first met field for defined class.findForFieldOffset(int offset) Find a registered field for its field offset in compiled script.<T extends JBBPAbstractField>
TfindLastFieldForType(Class<T> fieldType) Find the last met field for defined class.get(JBBPNamedFieldInfo namedField) Get a numeric field for its field name info.intgetExternalFieldValue(String externalFieldName, JBBPCompiledBlock compiledBlock, JBBPIntegerValueEvaluator evaluator) Ask the registered external value provider for a field value.Get the external value provider.booleanisEmpty()Check that the map is empty.booleannameExists(String fieldName) Check that a field exists for a namebooleanpathExists(String fieldPath) Check that a file exists for pathvoidputField(JBBPNumericField field) Put a numeric field into map.remove(JBBPNamedFieldInfo nameInfo) Remove a field for its field name info descriptor.intsize()Get number of registered fields in the map.
-
Constructor Details
-
JBBPNamedNumericFieldMap
public JBBPNamedNumericFieldMap()Empty constructor which makes a map with null provider. -
JBBPNamedNumericFieldMap
A Constructor.- Parameters:
externalValueProvider- an external value provider, it can be null
-
-
Method Details
-
getExternalValueProvider
Get the external value provider.- Returns:
- the external value provider or null if it is undefined
-
get
Get a numeric field for its field name info.- Parameters:
namedField- a field name info, it must not be null- Returns:
- the found field or null if it is not found
-
putField
Put a numeric field into map.- Parameters:
field- a field to be added into map or replace already exists one, it must not be null- Throws:
NullPointerException- if the field is null or if it is an anonymous field
-
remove
Remove a field for its field name info descriptor.- Parameters:
nameInfo- the field name info, it must not be null- Returns:
- removed numeric field or null if there was not any field for the info
-
findForFieldOffset
Find a registered field for its field offset in compiled script.- Parameters:
offset- the field offset- Returns:
- found field or null if there is not any found for the offset
-
findFirstFieldForType
Description copied from interface:JBBPFieldFinderFind the first met field for defined class. Field should be exactly instance of the class, not a successor.- Specified by:
findFirstFieldForTypein interfaceJBBPFieldFinder- Type Parameters:
T- the class of the field- Parameters:
fieldType- the field class for search- Returns:
- found field or null
-
findLastFieldForType
Description copied from interface:JBBPFieldFinderFind the last met field for defined class. Field should be exactly instance of the class, not a successor.- Specified by:
findLastFieldForTypein interfaceJBBPFieldFinder- Type Parameters:
T- the class of the field- Parameters:
fieldType- the field class for search, must not be null- Returns:
- found field or null
-
findFieldForType
Description copied from interface:JBBPFieldFinderFind unique field for defined class. Field should be exactly instance of the class and the field must be only one or not be presented else an exception will be thrown.- Specified by:
findFieldForTypein interfaceJBBPFieldFinder- Type Parameters:
T- the class of the field- Parameters:
fieldType- the field class for search, must not be null- Returns:
- found field or null
-
findFieldForNameAndType
public <T extends JBBPAbstractField> T findFieldForNameAndType(String fieldName, Class<T> fieldType) Description copied from interface:JBBPFieldFinderFind a field for its name and type pair.- Specified by:
findFieldForNameAndTypein interfaceJBBPFieldFinder- Type Parameters:
T- the class of the field- Parameters:
fieldName- the field name for search, must not be nullfieldType- the field class for search, must not be null- Returns:
- found field or null
-
findFieldForPathAndType
public <T extends JBBPAbstractField> T findFieldForPathAndType(String fieldPath, Class<T> fieldType) Description copied from interface:JBBPFieldFinderFind a field for its path and type pair.- Specified by:
findFieldForPathAndTypein interfaceJBBPFieldFinder- Type Parameters:
T- the class of the field- Parameters:
fieldPath- the field path for search, must not be nullfieldType- the field class for search, must not be null- Returns:
- found field or null
-
findFieldForName
Description copied from interface:JBBPFieldFinderFind a field for its name.- Specified by:
findFieldForNamein interfaceJBBPFieldFinder- Parameters:
fieldName- the field name for search, it must not be null- Returns:
- found field or null
-
findFieldForPath
Description copied from interface:JBBPFieldFinderFind a field for its path.- Specified by:
findFieldForPathin interfaceJBBPFieldFinder- Parameters:
fieldPath- the field path for search, it must not be null- Returns:
- found field or null
-
nameExists
Description copied from interface:JBBPFieldFinderCheck that a field exists for a name- Specified by:
nameExistsin interfaceJBBPFieldFinder- Parameters:
fieldName- a field name to check, it must not be null- Returns:
- true if the field exists, false otherwise
-
pathExists
Description copied from interface:JBBPFieldFinderCheck that a file exists for path- Specified by:
pathExistsin interfaceJBBPFieldFinder- Parameters:
fieldPath- a field path to check, it must not be null- Returns:
- true if the field exists, false otherwise
-
clear
public void clear()Clear the map. -
isEmpty
public boolean isEmpty()Check that the map is empty.- Returns:
- true if the map is empty, false otherwise
-
size
public int size()Get number of registered fields in the map.- Returns:
- number of registered fields as integer
-
getExternalFieldValue
public int getExternalFieldValue(String externalFieldName, JBBPCompiledBlock compiledBlock, JBBPIntegerValueEvaluator evaluator) Ask the registered external value provider for a field value.- Parameters:
externalFieldName- the name of a field, it must not be nullcompiledBlock- the compiled block, it must not be nullevaluator- an evaluator which is calling the method, it can be null- Returns:
- integer value for the field
- Throws:
JBBPException- if there is not any external value provider
-