org.wso2.balana.attr.DoubleAttribute Java Examples

The following examples show how to use org.wso2.balana.attr.DoubleAttribute. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MobiAttributeFinder.java    From mobi with GNU Affero General Public License v3.0 6 votes vote down vote up
private AttributeValue getAttributeValue(Literal literal) {
    IRI datatype = literal.getDatatype();
    switch (datatype.stringValue()) {
        case "http://www.w3.org/2001/XMLSchema#string":
            return new StringAttribute(literal.stringValue());
        case "http://www.w3.org/2001/XMLSchema#boolean":
            return BooleanAttribute.getInstance(literal.booleanValue());
        case "http://www.w3.org/2001/XMLSchema#double":
            return new DoubleAttribute(literal.doubleValue());
        case "http://www.w3.org/2001/XMLSchema#integer":
            return new IntegerAttribute(literal.longValue());
        case "http://www.w3.org/2001/XMLSchema#anyURI":
            try {
                return new AnyURIAttribute(new URI(literal.stringValue()));
            } catch (URISyntaxException e) {
                throw new ProcessingException("Not a valid URI");
            }
        case "https://www.w3.org/2001/XMLSchema#dateTime":
            return new DateTimeAttribute(new Date(literal.dateTimeValue().toInstant().toEpochMilli()));
        default:
            throw new ProcessingException("Datatype " + datatype + " is not supported");
    }
}
 
Example #2
Source File: FloorFunction.java    From balana with Apache License 2.0 5 votes vote down vote up
/**
 * Evaluate the function, using the specified parameters.
 * 
 * @param inputs a <code>List</code> of <code>Evaluatable</code> objects representing the
 *            arguments passed to the function
 * @param context an <code>EvaluationCtx</code> so that the <code>Evaluatable</code> objects can
 *            be evaluated
 * @return an <code>EvaluationResult</code> representing the function's result
 */
public EvaluationResult evaluate(List inputs, EvaluationCtx context) {

    // Evaluate the arguments
    AttributeValue[] argValues = new AttributeValue[inputs.size()];
    EvaluationResult result = evalArgs(inputs, context, argValues);
    if (result != null)
        return result;

    // Now that we have real values, perform the floor operation
    double arg = ((DoubleAttribute) argValues[0]).getValue();

    return new EvaluationResult(new DoubleAttribute(Math.floor(arg)));
}
 
Example #3
Source File: MultiplyFunction.java    From balana with Apache License 2.0 5 votes vote down vote up
/**
 * Private helper that returns the type used for the given standard function. Note that this
 * doesn't check on the return value since the method always is called after getId, so we assume
 * that the function is present.
 */
private static String getArgumentType(String functionName) {
    if (functionName.equals(NAME_INTEGER_MULTIPLY))
        return IntegerAttribute.identifier;
    else
        return DoubleAttribute.identifier;
}
 
Example #4
Source File: RoundFunction.java    From balana with Apache License 2.0 5 votes vote down vote up
/**
 * Evaluate the function, using the specified parameters.
 * 
 * @param inputs a <code>List</code> of <code>Evaluatable</code> objects representing the
 *            arguments passed to the function
 * @param context an <code>EvaluationCtx</code> so that the <code>Evaluatable</code> objects can
 *            be evaluated
 * @return an <code>EvaluationResult</code> representing the function's result
 */
public EvaluationResult evaluate(List inputs, EvaluationCtx context) {

    // Evaluate the arguments
    AttributeValue[] argValues = new AttributeValue[inputs.size()];
    EvaluationResult result = evalArgs(inputs, context, argValues);
    if (result != null)
        return result;

    // Now that we have real values, perform the round operation
    double arg = ((DoubleAttribute) argValues[0]).getValue();
    BigDecimal roundValue = new BigDecimal(arg);

    return new EvaluationResult(new DoubleAttribute(roundValue.setScale(0, RoundingMode.HALF_EVEN).doubleValue()));
}
 
Example #5
Source File: AddFunction.java    From balana with Apache License 2.0 5 votes vote down vote up
/**
 * Private helper that returns the type used for the given standard function. Note that this
 * doesn't check on the return value since the method always is called after getId, so we assume
 * that the function is present.
 */
private static String getArgumentType(String functionName) {
	if (functionName.equals(NAME_INTEGER_ADD))
		return IntegerAttribute.identifier;
	else
		return DoubleAttribute.identifier;
}
 
Example #6
Source File: AbsFunction.java    From balana with Apache License 2.0 5 votes vote down vote up
/**
 * Private helper that returns the type used for the given standard function. Note that this
 * doesn't check on the return value since the method always is called after getId, so we assume
 * that the function is present.
 */
private static String getArgumentType(String functionName) {
    if (functionName.equals(NAME_INTEGER_ABS))
        return IntegerAttribute.identifier;
    else
        return DoubleAttribute.identifier;
}
 
Example #7
Source File: NumericConvertFunction.java    From balana with Apache License 2.0 5 votes vote down vote up
/**
 * Private helper that returns the type used for the given standard function. Note that this
 * doesn't check on the return value since the method always is called after getId, so we assume
 * that the function is present.
 */
private static String getArgumentType(String functionName) {
    if (functionName.equals(NAME_DOUBLE_TO_INTEGER))
        return DoubleAttribute.identifier;
    else
        return IntegerAttribute.identifier;
}
 
Example #8
Source File: NumericConvertFunction.java    From balana with Apache License 2.0 5 votes vote down vote up
/**
 * Private helper that returns the return type for the given standard function. Note that this
 * doesn't check on the return value since the method always is called after getId, so we assume
 * that the function is present.
 */
private static String getReturnType(String functionName) {
    if (functionName.equals(NAME_DOUBLE_TO_INTEGER))
        return IntegerAttribute.identifier;
    else
        return DoubleAttribute.identifier;
}
 
Example #9
Source File: DivideFunction.java    From balana with Apache License 2.0 5 votes vote down vote up
/**
 * Private helper that returns the type used for the given standard function. Note that this
 * doesn't check on the return value since the method always is called after getId, so we assume
 * that the function is present.
 */
private static String getArgumentType(String functionName) {
    if (functionName.equals(NAME_INTEGER_DIVIDE))
        return IntegerAttribute.identifier;
    else
        return DoubleAttribute.identifier;
}
 
Example #10
Source File: SubtractFunction.java    From balana with Apache License 2.0 5 votes vote down vote up
/**
 * Private helper that returns the type used for the given standard function. Note that this
 * doesn't check on the return value since the method always is called after getId, so we assume
 * that the function is present.
 */
private static String getArgumentType(String functionName) {
    if (functionName.equals(NAME_INTEGER_SUBTRACT))
        return IntegerAttribute.identifier;
    else
        return DoubleAttribute.identifier;
}
 
Example #11
Source File: DoubleAttributeProxy.java    From balana with Apache License 2.0 4 votes vote down vote up
public AttributeValue getInstance(Node root) throws Exception {
    return DoubleAttribute.getInstance(root);
}
 
Example #12
Source File: DoubleAttributeProxy.java    From balana with Apache License 2.0 4 votes vote down vote up
public AttributeValue getInstance(String value) throws Exception {
    return DoubleAttribute.getInstance(value);
}
 
Example #13
Source File: FloorFunction.java    From balana with Apache License 2.0 3 votes vote down vote up
/**
 * Creates a new <code>FloorFunction</code> object.
 * 
 * @param functionName the standard XACML name of the function to be handled by this object,
 *            including the full namespace
 * 
 * @throws IllegalArgumentException if the function is unknown
 */
public FloorFunction(String functionName) {
    super(NAME_FLOOR, 0, DoubleAttribute.identifier, false, 1, DoubleAttribute.identifier,
            false);

    if (!functionName.equals(NAME_FLOOR))
        throw new IllegalArgumentException("unknown floor function: " + functionName);
}
 
Example #14
Source File: RoundFunction.java    From balana with Apache License 2.0 3 votes vote down vote up
/**
 * Creates a new <code>RoundFunction</code> object.
 * 
 * @param functionName the standard XACML name of the function to be handled by this object,
 *            including the full namespace
 * 
 * @throws IllegalArgumentException if the function is unknown
 */
public RoundFunction(String functionName) {
    super(NAME_ROUND, 0, DoubleAttribute.identifier, false, 1, DoubleAttribute.identifier,
            false);

    if (!functionName.equals(NAME_ROUND))
        throw new IllegalArgumentException("unknown round function: " + functionName);
}