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
public class DefaultItemFunction<T extends Nameable> extends Object implements JepFunction
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) $
-
-
Constructor Summary
Constructors Constructor Description DefaultItemFunction(DbControl dc, Project project, Item itemType)
Create a new function instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
checkNumberOfParameters(int n)
T
findDefaultItem()
Find a default item.String
getFunctionName()
Get the name of this function.int
getNumberOfParameters()
void
run(Stack stack)
void
setCurNumberOfParameters(int n)
void
setCurrentSubtype(ItemSubtype subtype)
Set the current subtype to use when looking for default items.
-
-
-
Method Detail
-
getFunctionName
public String 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:
JEP.addFunction(String, PostfixMathCommandI)
-
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
public void run(Stack stack) throws ParseException
- Specified by:
run
in interfaceorg.nfunk.jep.function.PostfixMathCommandI
- Throws:
ParseException
-
findDefaultItem
public T 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
public void setCurrentSubtype(ItemSubtype subtype)
Set the current subtype to use when looking for default items.
-
-