Package net.sf.basedb.util.parser
Class DefaultItemFunction<T extends Nameable>
java.lang.Object
net.sf.basedb.util.parser.DefaultItemFunction<T>
- All Implemented Interfaces:
JepFunction
,org.nfunk.jep.function.PostfixMathCommandI
JEP function that can be used to return the name of a default item in
a project. The constructor need to specify the project and the type
of item to look for. Use 'default()' or 'default(col("header"))' in the
JEP expression to use this function. The first variant will always
return the default item if one exists for the project. The second
variant will return the default item only if the 'col("header")' part
is null or an empty string.
Before this function is used the setCurrentSubtype(ItemSubtype)
can be called to limit the search to items with a specific subtype. If
there is more than one matching item in a project, it is undefined which
one is returned, but multiple uses of this function will return the same
item.
- Since:
- 3.1
- Author:
- Nicklas
- Last modified
- $Date: 2019-03-01 09:42:54 +0100 (fre, 01 mars 2019) $
-
Field Summary
-
Constructor Summary
ConstructorDescriptionDefaultItemFunction
(DbControl dc, Project project, Item itemType) Create a new function instance. -
Method Summary
Modifier and TypeMethodDescriptionboolean
checkNumberOfParameters
(int n) Find a default item.Get the name of this function.int
void
void
setCurNumberOfParameters
(int n) void
setCurrentSubtype
(ItemSubtype subtype) Set the current subtype to use when looking for default items.
-
Field Details
-
dc
-
project
-
itemType
-
subtype
-
numParameters
private int numParameters -
itemCache
-
-
Constructor Details
-
DefaultItemFunction
Create a new function instance.- Parameters:
dc
- The DbControl to use when loading items from the databaseproject
- The project (null is allowed)itemType
- The type of item to look for
-
-
Method Details
-
getFunctionName
Description copied from interface:JepFunction
Get the name of this function. It is used when registering the function with aJEP
parser.- Specified by:
getFunctionName
in interfaceJepFunction
- Returns:
- The string "default"
- See Also:
-
getNumberOfParameters
public int getNumberOfParameters()- Specified by:
getNumberOfParameters
in interfaceorg.nfunk.jep.function.PostfixMathCommandI
-
setCurNumberOfParameters
public void setCurNumberOfParameters(int n) - Specified by:
setCurNumberOfParameters
in interfaceorg.nfunk.jep.function.PostfixMathCommandI
-
checkNumberOfParameters
public boolean checkNumberOfParameters(int n) - Specified by:
checkNumberOfParameters
in interfaceorg.nfunk.jep.function.PostfixMathCommandI
-
run
- Specified by:
run
in interfaceorg.nfunk.jep.function.PostfixMathCommandI
- Throws:
ParseException
-
findDefaultItem
Find a default item. If a subtype has been set withsetCurrentSubtype(ItemSubtype)
theProject.findDefaultItems(DbControl, ItemSubtype, boolean)
method is used in non-strict mode, otherwise theProject.findDefaultItems(DbControl, Item, boolean)
is used in strict mode.- Returns:
- A matching default item or null if none could be found
-
setCurrentSubtype
Set the current subtype to use when looking for default items.
-