
com.xresch.cfw.features.query.functions.CFWQueryFunctionIsNumber Maven / Gradle / Ivy
package com.xresch.cfw.features.query.functions;
import java.util.ArrayList;
import java.util.TreeSet;
import com.xresch.cfw._main.CFW;
import com.xresch.cfw.features.query.CFWQueryContext;
import com.xresch.cfw.features.query.CFWQueryFunction;
import com.xresch.cfw.features.query.EnhancedJsonObject;
import com.xresch.cfw.features.query.FeatureQuery;
import com.xresch.cfw.features.query.parse.QueryPartValue;
/************************************************************************************************************
*
* @author Reto Scheiwiller, (c) Copyright 2023
* @license MIT-License
************************************************************************************************************/
public class CFWQueryFunctionIsNumber extends CFWQueryFunction {
public static final String FUNCTION_NAME = "isnumber";
public CFWQueryFunctionIsNumber(CFWQueryContext context) {
super(context);
}
/***********************************************************************************************
*
***********************************************************************************************/
@Override
public String uniqueName() {
return FUNCTION_NAME;
}
/***********************************************************************************************
*
***********************************************************************************************/
@Override
public TreeSet getTags(){
TreeSet tags = new TreeSet<>();
tags.add(CFWQueryFunction.TAG_CODING);
return tags;
}
/***********************************************************************************************
*
***********************************************************************************************/
@Override
public String descriptionSyntax() {
return FUNCTION_NAME+"(valueOrFieldname, allowStrings)";
}
/***********************************************************************************************
*
***********************************************************************************************/
@Override
public String descriptionShort() {
return "Returns true if the value is a number, false otherwise.";
}
/***********************************************************************************************
*
***********************************************************************************************/
@Override
public String descriptionSyntaxDetailsHTML() {
return ""
+"- valueOrFieldname: The value or field that should be checked.
"
+"- allowStrings: (true) If set to false, if the value is of type string will return false even if the string is a number. (Default: true)
"
+"
"
;
}
/***********************************************************************************************
*
***********************************************************************************************/
@Override
public String descriptionHTML() {
return CFW.Files.readPackageResource(FeatureQuery.PACKAGE_MANUAL+".functions", "function_"+FUNCTION_NAME+".html");
}
/***********************************************************************************************
*
***********************************************************************************************/
@Override
public boolean supportsAggregation() {
return false;
}
/***********************************************************************************************
*
***********************************************************************************************/
@Override
public void aggregate(EnhancedJsonObject object,ArrayList parameters) {
// not supported
}
/***********************************************************************************************
*
***********************************************************************************************/
@Override
public QueryPartValue execute(EnhancedJsonObject object, ArrayList parameters) {
//----------------------------------
//
if(parameters.size() >= 1) {
QueryPartValue value = parameters.get(0);
boolean allowStrings = true;
if(parameters.size() >= 2) {
allowStrings = parameters.get(1).getAsBoolean();
}
if(allowStrings) {
return QueryPartValue.newBoolean( value.isNumberOrNumberString() );
}else {
return QueryPartValue.newBoolean( value.isNumber() );
}
}
//----------------------------------
// Return null if not enough params
return QueryPartValue.newNull();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy