si.uom.SI Java Examples

The following examples show how to use si.uom.SI. 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: UCUMFormat.java    From uom-systems with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
private CharSequence symbolForKilogram(ComparableUnit unit) throws IOException {
    
    final Unit<?> systemUnit = unit.getSystemUnit();
    if (!systemUnit.equals(SI.KILOGRAM)) {
        return null;
    }

    final UnitConverter converter = 
            UCUMFormatHelper.toKnownPrefixConverterIfPossible(
                    unit.getConverterTo(systemUnit)
                    .concatenate(MultiplyConverter.ofPrefix(MetricPrefix.KILO)));
    
    final StringBuilder sb = new StringBuilder();
    final boolean printSeparator = true;
    
    // A special case because KILOGRAM is a BaseUnit instead of
    // a transformed unit, for compatibility with existing SI
    // unit system.
    format(SI.GRAM, sb);
    formatConverter(converter, printSeparator, sb, symbolMap);    
    
    return sb;
}
 
Example #2
Source File: UCUMFormat.java    From uom-systems with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
private CharSequence symbolForKilogram(ComparableUnit unit) throws IOException {
    
    final Unit<?> systemUnit = unit.getSystemUnit();
    if (!systemUnit.equals(SI.KILOGRAM)) {
        return null;
    }

    final UnitConverter converter = 
            UCUMFormatHelper.toKnownPrefixConverterIfPossible(
                    unit.getConverterTo(systemUnit)
                    .concatenate(MultiplyConverter.ofPrefix(MetricPrefix.KILO)));
    
    final StringBuilder sb = new StringBuilder();
    final boolean printSeparator = true;
    
    // A special case because KILOGRAM is a BaseUnit instead of
    // a transformed unit, for compatibility with existing SI
    // unit system.
    format(SI.GRAM, sb);
    formatConverter(converter, printSeparator, sb, symbolMap);    
    
    return sb;
}
 
Example #3
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;
}