/** * Parses the text into an instance of unit * * @param name * @see UnitFormat#parse(CharSequence) * @throws ParserException if any problem occurs while parsing the specified character sequence * (e.g. illegal syntax). * @throws UnsupportedOperationException if the {@link UnitFormat} is unable to parse. * @return A unit instance */ public static Unit<?> parseUnit(String name) { return Units.autoCorrect(DefaultUnitParser.getInstance().parse(name)); } }
unit = Units.autoCorrect(unit); // auto-correct DEGREE_ANGLE and FOOT_SURVEY } else {
/** * Parses an "UNIT" element. This element has the following pattern: * * <blockquote> * * <code> * UNIT["<name>", <conversion factor> {,<authority>}] * </code> * * </blockquote> * * @param parent The parent element. * @param unit The contextual unit. Usually {@link SI#METRE} or {@link SI#RADIAN}. * @return The "UNIT" element as an {@link Unit} object. * @throws ParseException if the "UNIT" can't be parsed. * @todo Authority code is currently ignored. We may consider to create a subclass of {@link * Unit} which implements {@link IdentifiedObject} in a future version. */ @SuppressWarnings("unchecked") private <T extends Quantity<T>> Unit<T> parseUnit(final Element parent, final Unit<T> unit) throws ParseException { final Element element = parent.pullElement("UNIT"); final String name = element.pullString("name"); final double factor = element.pullDouble("factor"); parseAuthority(element, name); element.close(); Unit<T> finalUnit = (factor != 1) ? unit.multiply(factor) : unit; return Units.autoCorrect(finalUnit); }
throw new IllegalStateException("Unable to map model " + model + " for this unit"); unit = Units.autoCorrect(unit); // auto-correct DEGREE_ANGLE and FOOT_SURVEY
Unit<Q> factor = base.multiply(sz); return Units.autoCorrect(factor); } catch (NumberFormatException nfe) { final IOException ioe =
@Test public void testUnitsMatch() { Unit<Angle> degree = Units.autoCorrect( new TransformedUnit<Angle>( SI.RADIAN, new MultiplyConverter((Math.PI * 2.0) / 360.0))); assertEquals("autocorrection of degree definition from jsr275", NonSI.DEGREE_ANGLE, degree); assertTrue("jsr275 deegree definition", isDegreeAngle(degree)); // UNIT["degree", 0.017453292519943295], degree = Units.autoCorrect( new TransformedUnit<Angle>( SI.RADIAN, new MultiplyConverter(0.017453292519943295))); assertEquals( "autocorrection of deegree definition from EsriLookupTest", NonSI.DEGREE_ANGLE, degree); assertTrue("deegree definition from EsriLookupTest", isDegreeAngle(degree)); Unit<Length> feet = Units.autoCorrect( new TransformedUnit<Length>( SI.METRE, new MultiplyConverter(0.3048006096012192))); assertEquals( "autocorrection of US Survey definition from EsriLookupTest", USCustomary.FOOT_SURVEY, feet); assertTrue("survey foot definition from EsriLookupTest", isUSSurveyFoot(feet)); }