Class DefaultItemFunction<T extends Nameable>

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.

Last modified
$Date: 2019-03-01 09:42:54 +0100 (fre, 01 mars 2019) $
  • Field Details

    • dc

      private final DbControl dc
    • project

      private final Project project
    • itemType

      private final Item itemType
    • subtype

      private ItemSubtype subtype
    • numParameters

      private int numParameters
    • itemCache

      private Map<Object,T extends Nameable> itemCache
  • Constructor Details

    • DefaultItemFunction

      public DefaultItemFunction(DbControl dc, Project project, Item itemType)
      Create a new function instance.
      dc - The DbControl to use when loading items from the database
      project - The project (null is allowed)
      itemType - The type of item to look for
  • Method Details

    • getFunctionName

      public String getFunctionName()
      Description copied from interface: JepFunction
      Get the name of this function. It is used when registering the function with a JEP parser.
      Specified by:
      getFunctionName in interface JepFunction
      The string "default"
      See Also:
    • getNumberOfParameters

      public int getNumberOfParameters()
      Specified by:
      getNumberOfParameters in interface org.nfunk.jep.function.PostfixMathCommandI
    • setCurNumberOfParameters

      public void setCurNumberOfParameters(int n)
      Specified by:
      setCurNumberOfParameters in interface org.nfunk.jep.function.PostfixMathCommandI
    • checkNumberOfParameters

      public boolean checkNumberOfParameters(int n)
      Specified by:
      checkNumberOfParameters in interface org.nfunk.jep.function.PostfixMathCommandI
    • run

      public void run(Stack stack) throws ParseException
      Specified by:
      run in interface org.nfunk.jep.function.PostfixMathCommandI
    • findDefaultItem

      public T findDefaultItem()
      Find a default item. If a subtype has been set with setCurrentSubtype(ItemSubtype) the Project.findDefaultItems(DbControl, ItemSubtype, boolean) method is used in non-strict mode, otherwise the Project.findDefaultItems(DbControl, Item, boolean) is used in strict mode.
      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.