Class AngleFormatter

All Implemented Interfaces:
Cloneable

public class AngleFormatter extends MeasureFormatter<Angle,AngleUnit>
Formats and parses angle value and unit.
  • Field Details

    • DEGREE

      public static final String DEGREE
      Degree symbol.
      See Also:
    • RADIAN

      public static final String RADIAN
      Radian symbol.
      See Also:
    • DEGREES_AND_MINUTES_MESSAGE_PATTERN

      private static final String DEGREES_AND_MINUTES_MESSAGE_PATTERN
      Pattern to format degrees and minutes.
      See Also:
    • DEGREES_MINUTES_AND_SECONDS_MESSAGE_PATTERN

      private static final String DEGREES_MINUTES_AND_SECONDS_MESSAGE_PATTERN
      Pattern to format degrees, minutes and seconds.
      See Also:
    • DEGREES_AND_MINUTES_PATTERN

      private static final String DEGREES_AND_MINUTES_PATTERN
      Pattern to parse degrees and minutes expressions.
      See Also:
    • DEGREES_MINUTES_AND_SECONDS_PATTERN

      private static final String DEGREES_MINUTES_AND_SECONDS_PATTERN
      Pattern to parse degrees, minutes and seconds expressions.
      See Also:
    • degreesAndMinutesPattern

      private Pattern degreesAndMinutesPattern
      Pattern to parse angle in degrees and decimal minutes format.
    • degreesMinutesAndSecondsPattern

      private Pattern degreesMinutesAndSecondsPattern
      Pattern to parse angle in degrees, minutes and decimal seconds format.
  • Constructor Details

    • AngleFormatter

      public AngleFormatter()
      Constructor.
    • AngleFormatter

      public AngleFormatter(Locale locale)
      Constructor with locale.
      Parameters:
      locale - locale.
      Throws:
      IllegalArgumentException - if locale is null.
    • AngleFormatter

      public AngleFormatter(AngleFormatter formatter)
      Copy constructor.
      Parameters:
      formatter - input instance to copy from.
      Throws:
      NullPointerException - if provided formatter is null.
  • Method Details

    • equals

      public boolean equals(Object obj)
      Determines if two angle formatters are equal by comparing all of its internal parameters.
      Overrides:
      equals in class MeasureFormatter<Angle,AngleUnit>
      Parameters:
      obj - another object to compare.
      Returns:
      true if provided object is assumed to be equal to this instance.
    • hashCode

      public int hashCode()
      Hash code generated for this instance. Hash codes can be internally used by some collections to coarsely compare objects. This implementation only calls parent implementation to avoid static analyzer warning.
      Overrides:
      hashCode in class MeasureFormatter<Angle,AngleUnit>
      Returns:
      hash code.
    • getUnitSystem

      public UnitSystem getUnitSystem(String source)
      Gets unit system for detected unit into provided string representation of a measurement.
      Specified by:
      getUnitSystem in class MeasureFormatter<Angle,AngleUnit>
      Parameters:
      source - a measurement string representation to be checked.
      Returns:
      a unit system (metric) or null if unit cannot be determined.
    • parse

      public Angle parse(String source) throws ParseException, UnknownUnitException
      Parses provided string and tries to determine an angle value and unit.
      Specified by:
      parse in class MeasureFormatter<Angle,AngleUnit>
      Parameters:
      source - a string to be parsed.
      Returns:
      an angle containing a value and unit.
      Throws:
      ParseException - if provided string cannot be parsed.
      UnknownUnitException - if unit cannot be determined.
    • findUnit

      public AngleUnit findUnit(String source)
      Attempts to determine an angle unit within a measurement string representation.
      Specified by:
      findUnit in class MeasureFormatter<Angle,AngleUnit>
      Parameters:
      source - an angle measurement string representation.
      Returns:
      an angle unit, or null if none can be determined.
    • formatAndConvert

      public String formatAndConvert(Number value, AngleUnit unit, UnitSystem system)
      Formats and converts provided angle value and unit using metric system. This implementation ignores provided unit system.
      Specified by:
      formatAndConvert in class MeasureFormatter<Angle,AngleUnit>
      Parameters:
      value - a measurement value.
      unit - a measurement unit.
      system - ignored.
      Returns:
      a string representation of angle value and unit.
    • getUnitSymbol

      public String getUnitSymbol(AngleUnit unit)
      Returns unit string representation.
      Specified by:
      getUnitSymbol in class MeasureFormatter<Angle,AngleUnit>
      Parameters:
      unit - an angle unit.
      Returns:
      its string representation.
    • formatDegreesAndMinutes

      public String formatDegreesAndMinutes(Angle angle)
      Formats provided angle into degrees and decimal minutes.
      Parameters:
      angle - angle to be formatted.
      Returns:
      string representation of provided angle expressed as degrees and decimal minutes.
    • formatDegreesMinutesAndSeconds

      public String formatDegreesMinutesAndSeconds(Angle angle)
      Formats provided angle into degrees, minutes and decimal seconds.
      Parameters:
      angle - angle to be formatted.
      Returns:
      string representation of provided angle expressed as degrees, minutes and decimal seconds.
    • parseDegreesAndMinutes

      public Angle parseDegreesAndMinutes(CharSequence source) throws ParseException, UnknownUnitException
      Parses provided string representation using degrees and decimal minutes format. Note: decimals are not accepted on degrees value.
      Parameters:
      source - string to be parsed.
      Returns:
      parsed angle.
      Throws:
      ParseException - if parsing fails.
      UnknownUnitException - if format is not recognized.
    • parseDegreesMinutesAndSeconds

      public Angle parseDegreesMinutesAndSeconds(CharSequence source) throws ParseException, UnknownUnitException
      Parses provided string representation using degrees, minutes and decimal seconds format.
      Parameters:
      source - string to be parsed.
      Returns:
      parsed angle.
      Throws:
      ParseException - if parsing fails.
      UnknownUnitException - if format is not recognized.