All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.xresch.cfw.features.query.functions.CFWQueryFunctionCos 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 CFWQueryFunctionCos extends CFWQueryFunction {

	public static final String FUNCTION_NAME = "cos";

	public CFWQueryFunctionCos(CFWQueryContext context) {
		super(context);
	}

	/***********************************************************************************************
	 * 
	 ***********************************************************************************************/
	@Override
	public String uniqueName() {
		return FUNCTION_NAME;
	}
	
	/***********************************************************************************************
	 * 
	 ***********************************************************************************************/
	@Override
	public TreeSet getTags(){
		TreeSet tags = new TreeSet<>();
		tags.add(CFWQueryFunction.TAG_MATH);
		return tags;
	}
	
	/***********************************************************************************************
	 * 
	 ***********************************************************************************************/
	@Override
	public String descriptionSyntax() {
		return FUNCTION_NAME+"(number, useDegrees)";
	}
	/***********************************************************************************************
	 * 
	 ***********************************************************************************************/
	@Override
	public String descriptionShort() {
		return "Returns the cosine value of a radians or degree value.";
	}
	
	/***********************************************************************************************
	 * 
	 ***********************************************************************************************/
	@Override
	public String descriptionSyntaxDetailsHTML() {
		return 
			 "
    " +"
  • number: The value you want the cosine value for.
  • " +"
  • useDegrees: (Optional)Set to true to use degrees instead of radians for first parameter.
  • " +"
" ; } /*********************************************************************************************** * ***********************************************************************************************/ @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) { //----------------------------- // Handle empty params int paramCount = parameters.size(); if(paramCount == 0) { return QueryPartValue.newNumber(0); } //----------------------------- // Get Value to Calculate QueryPartValue initialValue = parameters.get(0); //----------------------------- // Calculate if(initialValue.isNumberOrNumberString()) { //----------------------------- // Get useDegrees boolean useDegrees = false; if(paramCount >= 2) { QueryPartValue booleanValue = parameters.get(1); if(booleanValue.isBoolOrBoolString()) { useDegrees = booleanValue.getAsBoolean(); } } //----------------------------- // Calculate Value double doubleValue = initialValue.getAsDouble(); if(useDegrees) { doubleValue = Math.toRadians(doubleValue); } return QueryPartValue.newNumber( Math.cos( doubleValue ) ); } // return empty in other cases return QueryPartValue.newNumber(0); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy