Class UnitParser


  • public class UnitParser
    extends java.lang.Object
    class to parse units from strings
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String UNIT_CM  
      static java.lang.String UNIT_IN  
      static java.lang.String UNIT_MM  
      static java.lang.String UNIT_PT  
    • Constructor Summary

      Constructors 
      Constructor Description
      UnitParser()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addUnitKey​(java.lang.String key)  
      void convertUnits​(KElement element)  
      java.lang.String extractUnits​(java.lang.String val)
      extract units if and only if the string has a pattern of "<##>mm" or "<##>cm"or "<##>in" whitespace characters may be placed between the numbers and the units the unit case is ignored
      java.lang.String extractUnits​(java.lang.String key, java.lang.String val)  
      double getFactor​(java.lang.String unit)
      get the factor for one of the units to points
      int getPrecision()
      Getter for precision attribute.
      boolean isUnit​(java.lang.String key)  
      void setPrecision​(int precision)
      Setter for precision attribute.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • UnitParser

        public UnitParser()
    • Method Detail

      • convertUnits

        public void convertUnits​(KElement element)
        Parameters:
        element -
      • isUnit

        public boolean isUnit​(java.lang.String key)
        Parameters:
        key -
        Returns:
      • addUnitKey

        public void addUnitKey​(java.lang.String key)
        Parameters:
        key -
      • getFactor

        public double getFactor​(java.lang.String unit)
        get the factor for one of the units to points
        Parameters:
        unit -
        Returns:
      • extractUnits

        public java.lang.String extractUnits​(java.lang.String key,
                                             java.lang.String val)
        Parameters:
        key - the attribute name to check
        val -
        Returns:
      • extractUnits

        public java.lang.String extractUnits​(java.lang.String val)
        extract units if and only if the string has a pattern of "<##>mm" or "<##>cm"or "<##>in" whitespace characters may be placed between the numbers and the units the unit case is ignored
        Parameters:
        val - the string to convert
        Returns:
        the converted unit string
      • setPrecision

        public void setPrecision​(int precision)
        Setter for precision attribute.
        Parameters:
        precision - the precision to set
      • getPrecision

        public int getPrecision()
        Getter for precision attribute.
        Returns:
        the precision
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
        See Also:
        Object.toString()