/** * Returns the value of the node as a float. * @param value a model node * @return the value of the node as a float. */ public static float asFloat(ModelNode value) { return Double.valueOf(value.asDouble()).floatValue(); }
@Override protected void convertAttribute(PathAddress address, String attributeName, ModelNode attributeValue, TransformationContext context) { if (attributeValue.isDefined() && attributeValue.getType() != EXPRESSION) { attributeValue.set((int) Math.ceil(attributeValue.asDouble())); } } }, Attribute.DECAY.getDefinition())
/** * Returns the optional double value of the specified {@link ModelNode}. * @param value the model node * @return an optional value */ public static OptionalDouble optionalDouble(ModelNode value) { return value.isDefined() ? OptionalDouble.of(value.asDouble()) : OptionalDouble.empty(); }
private void addLoadMetrics(Set<LoadMetric> metrics, ModelNode nodes, final OperationContext context) throws OperationFailedException { for (Property property1 : nodes.asPropertyList()) { ModelNode node = property1.getValue(); double capacity = LoadMetricResourceDefinition.SharedAttribute.CAPACITY.resolveModelAttribute(context, node).asDouble(); int weight = LoadMetricResourceDefinition.SharedAttribute.WEIGHT.resolveModelAttribute(context, node).asInt();
@Override public void validateParameter(String parameterName, ModelNode parameterValue) throws OperationFailedException { super.validateParameter(parameterName, parameterValue); if (parameterValue.isDefined() && parameterValue.getType() != ModelType.EXPRESSION) { double value = parameterValue.asDouble(); if (this.lowerBound != null) { double bound = this.lowerBound.getValue(); boolean exclusive = this.lowerBound.isExclusive(); if ((value < bound) || (exclusive && (value == bound))) { throw ClusteringLogger.ROOT_LOGGER.parameterValueOutOfBounds(parameterName, value, exclusive ? ">" : ">=", bound); } } if (this.upperBound != null) { double bound = this.upperBound.getValue(); boolean exclusive = this.upperBound.isExclusive(); if ((value > bound) || (exclusive && (value == bound))) { throw ClusteringLogger.ROOT_LOGGER.parameterValueOutOfBounds(parameterName, value, exclusive ? "<" : "<=", bound); } } } } }
Object fromModelNode(final ModelNode node) { return node.asDouble(); }
Object fromModelNode(final ModelNode node) { return node.asDouble(); }
Object fromModelNode(final ModelNode node) { return node.asDouble(); }
/** * Returns the value of the node as a float, or null if the node is undefined. * @param value a model node * @return the value of the node as a float, or null if the node is undefined. */ public static float asFloat(ModelNode value) { return Double.valueOf(value.asDouble()).floatValue(); }
/** * Returns the value of the node as a float. * @param value a model node * @return the value of the node as a float. */ public static float asFloat(ModelNode value) { return Double.valueOf(value.asDouble()).floatValue(); }
/** * Returns the value of the node as a string, or the specified default value if the node is undefined. * @param value a model node * @return the value of the node as a string, or the specified default value if the node is undefined. */ public static float asFloat(ModelNode value, float defaultValue) { return Double.valueOf(value.asDouble(defaultValue)).floatValue(); }
@Override public double getDouble() { if (!isDefined()) return 0d; return value.asDouble(); }
public final List<Double> doubleListValue() { List<ModelNode> listValue = listValue(); List<Double> result = new ArrayList<Double>(listValue.size()); for (ModelNode value : listValue) { result.add(value.asDouble()); } return Collections.unmodifiableList(result); }
@Override protected void convertAttribute(PathAddress address, String attributeName, ModelNode attributeValue, TransformationContext context) { if (attributeValue.isDefined() && attributeValue.getType() != EXPRESSION) { attributeValue.set((int) Math.ceil(attributeValue.asDouble())); } } }, Attribute.DECAY.getDefinition())
public final double doubleValue() { if (!hasDefinedValue()) { throw new IllegalArgumentException(); } return value().asDouble(); }
public final double doubleValue(double defaultValue) { if (!hasDefinedValue()) { return defaultValue; } return value().asDouble(); }
@SuppressWarnings("unchecked") private T convertToBaseType(ModelNode dmr) { if (getType() == String.class) return (T) dmr.asString(); if (getType() == Long.class) return (T) Long.valueOf(dmr.asLong()); if (getType() == Integer.class) return (T) Integer.valueOf(dmr.asInt()); if (getType() == Boolean.class) return (T) Boolean.valueOf(dmr.asBoolean()); if (getType() == Double.class) return (T) Double.valueOf(dmr.asDouble()); if (getType() == BigDecimal.class) return (T) BigDecimal.valueOf(dmr.asDouble()); if (getType() == byte[].class) return (T) dmr.asBytes(); throw new IllegalArgumentException("Can not convert. This node is not of a base type. Actual type is " + type.getName()); }
@SuppressWarnings("unchecked") private T convertToBaseType(ModelNode dmr) { if (getType() == String.class) return (T) dmr.asString(); if (getType() == Long.class) return (T) Long.valueOf(dmr.asLong()); if (getType() == Integer.class) return (T) Integer.valueOf(dmr.asInt()); if (getType() == Boolean.class) return (T) Boolean.valueOf(dmr.asBoolean()); if (getType() == Double.class) return (T) Double.valueOf(dmr.asDouble()); if (getType() == BigDecimal.class) return (T) BigDecimal.valueOf(dmr.asDouble()); if (getType() == byte[].class) return (T) dmr.asBytes(); throw new IllegalArgumentException("Can not convert. This node is not of a base type. Actual type is " + type.getName()); }
/** * Returns the optional double value of the specified {@link ModelNode}. * @param value the model node * @return an optional value */ public static OptionalDouble optionalDouble(ModelNode value) { return value.isDefined() ? OptionalDouble.of(value.asDouble()) : OptionalDouble.empty(); }
private Object toJavaValue(ModelType type, ModelNode propValue) { if (type.equals(ModelType.STRING)) { return propValue.asString(); } else if (type.equals(ModelType.INT)) { return propValue.asInt(); } else if (type.equals(ModelType.DOUBLE)) { return propValue.asDouble(); } else if (type.equals(ModelType.LONG)) { return propValue.asLong(); } else if (type.equals(ModelType.BOOLEAN)) { return propValue.asBoolean(); } else { throw new RuntimeException("Unsupported DMR type: " + type); } } }