Class CssLengthUtil



  • public class CssLengthUtil
    extends java.lang.Object
    a utility class for css length value manipulations.
    Since:
    1.0.0
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.Object[] getLengthValueAndUnit​(java.lang.String cssValue)
      gets the length value and unit as an array.
      static java.lang.Object[] getLengthValueAsPremitiveAndUnit​(java.lang.String cssValue)
      gets the length value and unit as an array.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • getLengthValueAsPremitiveAndUnit

        public static java.lang.Object[] getLengthValueAsPremitiveAndUnit​(java.lang.String cssValue)
        gets the length value and unit as an array. For a cssValue 555px, the returned array may be used as
         Object[] lengthValueAsPremitiveAndUnit = CssLengthUtil
                 .getLengthValueAsPremitiveAndUnit("555px");
         float value = (float) lengthValueAsPremitiveAndUnit[0];
        
         // the object will be equal to CssLengthUnit.PX
         CssLengthUnit unit = (CssLengthUnit) lengthValueAsPremitiveAndUnit[1];
        
         Auto-boxing is done when the primitive value is stored in an object array
         therefore there is no much advantage with this method.
         [This method is left for future modification.]
        
         
        Parameters:
        cssValue - the value from which the length value and unit required to be parsed, Eg:- 555px.
        Returns:
        an array containing length and unit. The length will be in the zeroth index as float (primitive type) type and its unit in the first index as an object of CssLengthUnit. If the given cssValue doesn't contain unit but contains value then an array containing only length value (i.e. array having length one) will be returned. For any invalid value it will return an empty array (having length zero), specifically it will never return null.
        Since:
        1.0.0
      • getLengthValueAndUnit

        public static java.lang.Object[] getLengthValueAndUnit​(java.lang.String cssValue)
        gets the length value and unit as an array. For a cssValue 555px, the returned array may be used as
         Object[] lengthValueAndUnit = CssLengthUtil
                 .getLengthValueAndUnit("555px");
         Float value = (Float) lengthValueAndUnit[0];
        
         // the object will be equal to CssLengthUnit.PX
         CssLengthUnit unit = (CssLengthUnit) lengthValueAndUnit[1];
         
        Parameters:
        cssValue - the value from which the length value and unit required to be parsed, Eg:- 555px.
        Returns:
        an array containing length and unit. The length will be in the zeroth index as Float (wrapper type) type and its unit in the first index as an object of CssLengthUnit. If the given cssValue doesn't contain unit but contains value then an array containing only length value (i.e. array having length one) will be returned. For any invalid value it will return an empty array (having length zero), specifically it will never return null.
        Since:
        1.0.0