public DecimalType getLatitude() { return new DecimalType(latitude); }
public DecimalType getLongitude() { return new DecimalType(longitude); }
public DecimalType getAltitude() { return new DecimalType(altitude); }
public static DecimalType valueOf(String value) { return new DecimalType(value); }
public DecimalType getHue() { return new DecimalType(hue); }
public DecimalType getGravity() { double latRad = Math.toRadians(latitude.doubleValue()); double deltaG = -2000.0 * (altitude.doubleValue() / 1000) * EARTH_GRAVITATIONAL_CONSTANT / (Math.pow(WGS84_A, 3.0)); double sin2lat = Math.sin(latRad) * Math.sin(latRad); double sin22lat = Math.sin(2.0 * latRad) * Math.sin(2.0 * latRad); double result = (9.780327 * (1.0 + 5.3024e-3 * sin2lat - 5.8e-6 * sin22lat) + deltaG); return new DecimalType(result); }
@Override public <T extends State> @Nullable T as(@Nullable Class<T> target) { if (target == DecimalType.class) { return target.cast(this == OPEN ? new DecimalType(1) : DecimalType.ZERO); } else if (target == PercentType.class) { return target.cast(this == OPEN ? PercentType.HUNDRED : PercentType.ZERO); } else { return State.super.as(target); } }
@Override public <T extends State> @Nullable T as(@Nullable Class<T> target) { if (target == DecimalType.class) { return target.cast(this == ON ? new DecimalType(1) : DecimalType.ZERO); } else if (target == PercentType.class) { return target.cast(this == ON ? PercentType.HUNDRED : PercentType.ZERO); } else if (target == HSBType.class) { return target.cast(this == ON ? HSBType.WHITE : HSBType.BLACK); } else { return State.super.as(target); } }
public PointType(StringType latitude, StringType longitude, StringType altitude) { this(new DecimalType(latitude.toString()), new DecimalType(longitude.toString()), new DecimalType(altitude.toString())); }
@Override public State calculate(Set<Item> items) { int count = 0; if (items != null) { for (Item item : items) { Matcher matcher = pattern.matcher(item.getState().toString()); if (matcher.matches()) { count++; } } } return new DecimalType(count); }
public PointType(StringType latitude, StringType longitude) { this(new DecimalType(latitude.toString()), new DecimalType(longitude.toString())); }
public PointType(String value) { if (!value.isEmpty()) { List<String> elements = Arrays.stream(value.split(",")).map(in -> in.trim()).collect(Collectors.toList()); if (elements.size() >= 2) { canonicalize(new DecimalType(elements.get(0)), new DecimalType(elements.get(1))); if (elements.size() == 3) { setAltitude(new DecimalType(elements.get(2))); } else if (elements.size() > 3) { throw new IllegalArgumentException(value + " is not a valid PointType syntax. The syntax must not consist of more than 3 elements."); } } else { throw new IllegalArgumentException(value + " is not a valid PointType syntax"); } } else { throw new IllegalArgumentException("Constructor argument must not be blank"); } }
/** * Return the distance in meters from otherPoint, ignoring altitude. This algorithm also * ignores the oblate spheroid shape of Earth and assumes a perfect sphere, so results * are inexact. * * @param otherPoint * @return distance in meters * @see <a href="https://en.wikipedia.org/wiki/Haversine_formula">Haversine formula</a> */ public DecimalType distanceFrom(PointType otherPoint) { double dLat = Math.toRadians(otherPoint.latitude.doubleValue() - this.latitude.doubleValue()); double dLong = Math.toRadians(otherPoint.longitude.doubleValue() - this.longitude.doubleValue()); double a = Math.pow(Math.sin(dLat / 2D), 2D) + Math.cos(Math.toRadians(this.latitude.doubleValue())) * Math.cos(Math.toRadians(otherPoint.latitude.doubleValue())) * Math.pow(Math.sin(dLong / 2D), 2D); double c = 2D * Math.atan2(Math.sqrt(a), Math.sqrt(1D - a)); return new DecimalType(WGS84_A * c); }
/** * Compute the distance with another Point type, * http://stackoverflow.com/questions/837872/calculate-distance-in-meters-when-you-know-longitude-and-latitude-in- * java * * @param away : the point to calculate the distance with * @return distance between the two points in meters */ public DecimalType distanceFrom(@Nullable LocationItem awayItem) { if (awayItem != null && awayItem.state instanceof PointType && this.state instanceof PointType) { PointType thisPoint = (PointType) this.state; PointType awayPoint = (PointType) awayItem.state; return thisPoint.distanceFrom(awayPoint); } return new DecimalType(-1); }
@Override public <T extends State> T getStateAs(Set<Item> items, Class<T> stateClass) { State state = calculate(items); if (stateClass.isInstance(state)) { return stateClass.cast(state); } else { if (stateClass == DecimalType.class) { return stateClass.cast(new DecimalType(count(items, activeState))); } else { return null; } } }
@Override public <T extends State> @Nullable T as(@Nullable Class<T> target) { if (target == DecimalType.class) { return target.cast(equals(UP) ? DecimalType.ZERO : new DecimalType(new BigDecimal("1.0"))); } else if (target == PercentType.class) { return target.cast(equals(UP) ? PercentType.ZERO : PercentType.HUNDRED); } else { return State.super.as(target); } }
@Override public <T extends State> T getStateAs(Set<Item> items, Class<T> stateClass) { State state = calculate(items); if (stateClass.isInstance(state)) { return stateClass.cast(state); } else { if (stateClass == DecimalType.class) { if (items != null) { return stateClass.cast(new DecimalType(items.size() - count(items, activeState))); } else { return stateClass.cast(DecimalType.ZERO); } } else { return null; } } }
@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); }
@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) { // if brightness is not completely off, we consider the state to be on return target.cast(getBrightness().equals(PercentType.ZERO) ? OnOffType.OFF : OnOffType.ON); } else if (target == DecimalType.class) { return target.cast(new DecimalType( getBrightness().toBigDecimal().divide(BigDecimal.valueOf(100), 8, RoundingMode.UP))); } else if (target == PercentType.class) { return target.cast(new PercentType(getBrightness().toBigDecimal())); } else { return defaultConversion(target); } } }