public void setAltitude(DecimalType altitude) { this.altitude = altitude.toBigDecimal(); }
@Override public int compareTo(DecimalType o) { return value.compareTo(o.toBigDecimal()); }
@Override public State calculate(Set<Item> items) { if (items != null && items.size() > 0) { BigDecimal max = null; for (Item item : items) { DecimalType itemState = item.getStateAs(DecimalType.class); if (itemState != null) { if (max == null || max.compareTo(itemState.toBigDecimal()) < 0) { max = itemState.toBigDecimal(); } } } if (max != null) { return new DecimalType(max); } } return UnDefType.UNDEF; }
@Override public State calculate(Set<Item> items) { if (items != null && items.size() > 0) { BigDecimal min = null; for (Item item : items) { DecimalType itemState = item.getStateAs(DecimalType.class); if (itemState != null) { if (min == null || min.compareTo(itemState.toBigDecimal()) > 0) { min = itemState.toBigDecimal(); } } } if (min != null) { return new DecimalType(min); } } return UnDefType.UNDEF; }
@Override public State calculate(Set<Item> items) { BigDecimal sum = BigDecimal.ZERO; if (items != null) { for (Item item : items) { DecimalType itemState = item.getStateAs(DecimalType.class); if (itemState != null) { sum = sum.add(itemState.toBigDecimal()); } } } return new DecimalType(sum); }
/** * Canonicalize the current latitude and longitude values such that: * * <pre> * -90 <= latitude <= +90 - 180 < longitude <= +180 * </pre> */ private void canonicalize(DecimalType aLat, DecimalType aLon) { latitude = FLAT.add(aLat.toBigDecimal()).remainder(CIRCLE); longitude = aLon.toBigDecimal(); if (latitude.compareTo(BigDecimal.ZERO) == -1) { latitude = latitude.add(CIRCLE); } latitude = latitude.subtract(FLAT); if (latitude.compareTo(RIGHT) == 1) { latitude = FLAT.subtract(latitude); longitude = longitude.add(FLAT); } else if (latitude.compareTo(RIGHT.negate()) == -1) { latitude = FLAT.negate().subtract(latitude); longitude = longitude.add(FLAT); } longitude = FLAT.add(longitude).remainder(CIRCLE); if (longitude.compareTo(BigDecimal.ZERO) <= 0) { longitude = longitude.add(CIRCLE); } longitude = longitude.subtract(FLAT); }
/** * Try to convert a {@link DecimalType} into a new {@link QuantityType}. The unit for the new * type is derived either from the state description (which might also give a hint on items w/o dimension) or from * the system default unit of the given dimension. * * @param originalType the source {@link DecimalType}. * @param dimension the dimension to which the new {@link QuantityType} should adhere. * @return the new {@link QuantityType} from the given originalType, {@code null} if a unit could not be calculated. */ public @Nullable QuantityType<?> toQuantityType(DecimalType originalType, @Nullable Class<? extends Quantity<?>> dimension) { Unit<? extends Quantity<?>> itemUnit = getUnit(dimension); if (itemUnit != null) { return new QuantityType<>(originalType.toBigDecimal(), itemUnit); } return null; }
@Override public State calculate(Set<Item> items) { BigDecimal sum = BigDecimal.ZERO; int count = 0; if (items != null) { for (Item item : items) { DecimalType itemState = item.getStateAs(DecimalType.class); if (itemState != null) { sum = sum.add(itemState.toBigDecimal()); count++; } } } if (count > 0) { return new DecimalType(sum.divide(BigDecimal.valueOf(count), RoundingMode.HALF_UP)); } else { return UnDefType.UNDEF; } }
@Override public <T extends State> @Nullable T as(@Nullable Class<T> target) { if (target == OnOffType.class) { return target.cast(equals(ZERO) ? OnOffType.OFF : OnOffType.ON); } else if (target == PercentType.class) { return target.cast(new PercentType(toBigDecimal().multiply(BigDecimal.valueOf(100)))); } else if (target == UpDownType.class) { if (equals(ZERO)) { return target.cast(UpDownType.UP); } else if (toBigDecimal().compareTo(BigDecimal.valueOf(1)) == 0) { return target.cast(UpDownType.DOWN); } else { return null; } } else if (target == OpenClosedType.class) { if (equals(ZERO)) { return target.cast(OpenClosedType.CLOSED); } else if (toBigDecimal().compareTo(BigDecimal.valueOf(1)) == 0) { return target.cast(OpenClosedType.OPEN); } else { return null; } } else if (target == HSBType.class) { return target.cast(new HSBType(DecimalType.ZERO, PercentType.ZERO, new PercentType(this.toBigDecimal().multiply(BigDecimal.valueOf(100))))); } else { return defaultConversion(target); } }
/** * Constructs a HSBType instance with the given values * * @param h the hue value in the range from 0 <= h < 360 * @param s the saturation as a percent value * @param b the brightness as a percent value */ public HSBType(DecimalType h, PercentType s, PercentType b) { this.hue = h.toBigDecimal(); this.saturation = s.toBigDecimal(); this.value = b.toBigDecimal(); validateValue(this.hue, this.saturation, this.value); }
@Override public int compareTo(DecimalType o) { return value.compareTo(o.toBigDecimal()); }
} else if (state instanceof DecimalType && !(state instanceof HSBType)) { applyState(new HSBType(hue, saturation, new PercentType(((DecimalType) state).toBigDecimal().multiply(BigDecimal.valueOf(100))))); } else { applyState(state);
public static boolean operator_lessThan(Type type, Number x) { if (type instanceof QuantityType && x instanceof QuantityType) { return operator_lessThan((QuantityType<?>) type, (QuantityType<?>) x); } if (type != null && type instanceof DecimalType && x != null) { return ((DecimalType) type).toBigDecimal().compareTo(numberToBigDecimal(x)) < 0; } else { return false; } }
public static boolean operator_equals(Type type, Number x) { if (type instanceof QuantityType && x instanceof QuantityType) { return operator_equals((QuantityType<?>) type, (QuantityType<?>) x); } if (type != null && type instanceof DecimalType && x != null) { return ((DecimalType) type).toBigDecimal().compareTo(numberToBigDecimal(x)) == 0; } else { return type == x; // both might be null, then we should return true } }
public static boolean operator_lessEqualsThan(Type type, Number x) { if (type instanceof QuantityType && x instanceof QuantityType) { return operator_lessEqualsThan((QuantityType<?>) type, (QuantityType<?>) x); } if (type != null && type instanceof DecimalType && x != null) { return ((DecimalType) type).toBigDecimal().compareTo(numberToBigDecimal(x)) <= 0; } else { return false; } }
public static boolean operator_greaterEqualsThan(Type type, Number x) { if (type instanceof QuantityType && x instanceof QuantityType) { return operator_greaterEqualsThan((QuantityType<?>) type, (QuantityType<?>) x); } if (type != null && type instanceof DecimalType && x != null) { return ((DecimalType) type).toBigDecimal().compareTo(numberToBigDecimal(x)) >= 0; } else { return false; } }
public static boolean operator_notEquals(Type type, Number x) { if (type instanceof QuantityType && x instanceof QuantityType) { return operator_notEquals((QuantityType<?>) type, (QuantityType<?>) x); } if (type != null && type instanceof DecimalType && x != null) { return ((DecimalType) type).toBigDecimal().compareTo(numberToBigDecimal(x)) != 0; } else { return type != x; // both might be null, then we should return // false, otherwise true } }
public static boolean operator_greaterThan(Type type, Number x) { if (type instanceof QuantityType && x instanceof QuantityType) { return operator_greaterThan((QuantityType<?>) type, (QuantityType<?>) x); } if (type != null && type instanceof DecimalType && x != null) { return ((DecimalType) type).toBigDecimal().compareTo(numberToBigDecimal(x)) > 0; } else { return false; } }
@Override public State calculate(Set<Item> items) { BigDecimal sum = BigDecimal.ZERO; if (items != null) { for (Item item : items) { DecimalType itemState = item.getStateAs(DecimalType.class); if (itemState != null) { sum = sum.add(itemState.toBigDecimal()); } } } return new DecimalType(sum); }
/** * Constructs a HSBType instance with the given values * * @param h the hue value in the range from 0 <= h < 360 * @param s the saturation as a percent value * @param b the brightness as a percent value */ public HSBType(DecimalType h, PercentType s, PercentType b) { this.hue = h.toBigDecimal(); this.saturation = s.toBigDecimal(); this.value = b.toBigDecimal(); validateValue(this.hue, this.saturation, this.value); }