tec.uom.se.AbstractUnit Java Examples

The following examples show how to use tec.uom.se.AbstractUnit. 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: QuantityType.java    From openhab-core with Eclipse Public License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public @Nullable QuantityType<T> toUnit(String targetUnit) {
    Unit<T> unit = (Unit<T>) AbstractUnit.parse(targetUnit);
    if (unit != null) {
        return toUnit(unit);
    }

    return null;
}
 
Example #2
Source File: QuantityType.java    From openhab-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public String toFullString() {
    if (quantity.getUnit() == AbstractUnit.ONE) {
        return quantity.getValue().toString();
    } else {
        return quantity.toString();
    }
}
 
Example #3
Source File: QuantityType.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public @Nullable QuantityType<T> toUnit(String targetUnit) {
    Unit<T> unit = (Unit<T>) AbstractUnit.parse(targetUnit);
    if (unit != null) {
        return toUnit(unit);
    }

    return null;
}
 
Example #4
Source File: QuantityType.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public String toFullString() {
    if (quantity.getUnit() == AbstractUnit.ONE) {
        return quantity.getValue().toString();
    } else {
        return quantity.toString();
    }
}
 
Example #5
Source File: GeometryUtils.java    From geowave with Apache License 2.0 5 votes vote down vote up
public static Unit<Length> lookup(final String name) {
  final String lowerCaseName = name.toLowerCase();

  Unit<Length> unit = lookup(SI.class, lowerCaseName);
  if (unit != null) {
    return unit;
  }

  unit = lookup(NonSI.class, lowerCaseName);
  if (unit != null) {
    return unit;
  }

  if (lowerCaseName.endsWith("s")) {
    return lookup(lowerCaseName.substring(0, lowerCaseName.length() - 1));
  }
  if (lowerCaseName.startsWith("kilo") && (lowerCaseName.length() > 4)) {
    final Unit<Length> u = lookup(lowerCaseName.substring(4));
    if (u != null) {
      return u.multiply(1000);
    }
  }
  // if we get here, try some aliases
  if (lowerCaseName.equals("feet")) {
    return USCustomary.FOOT;
  }
  // if we get here, try some aliases
  if (lowerCaseName.equals("meter")) {
    return Units.METRE;
  }
  if (lowerCaseName.equals("unity")) {
    return (Unit) AbstractUnit.ONE;
  }
  return null;
}
 
Example #6
Source File: SmartHomeUnits.java    From openhab-core with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * Adds a new unit and maps it to the specified quantity type.
 *
 * @param unit the unit being added.
 * @param type the quantity type.
 * @return <code>unit</code>.
 */
private static <U extends AbstractUnit<?>> U addUnit(U unit, Class<? extends Quantity<?>> type) {
    INSTANCE.units.add(unit);
    INSTANCE.quantityToUnit.put(type, unit);
    return unit;
}