Class Position


  • public class Position
    extends Object
    Position is a data object for an integer position.
    • Constructor Detail

      • Position

        public Position​(double value,
                        boolean isRelative)
        Create a new Position with the supplied value.
        Parameters:
        value - the position
        isRelative - if true, the value is a percentage
        Throws:
        IllegalArgumentException - if the value is less than zero, or if the Position is absolute and its value is not an integer
    • Method Detail

      • parsePosition

        public static Position parsePosition​(String pos)
        Parses the supplied String as a Position. If the string ends with '%', the position will be parsed as a relative position, otherwise it will be parsed as an integer.
        Parameters:
        pos - the string to parse
        Returns:
        returns the new Position
        Throws:
        IllegalArgumentException - if the value is less than zero, or if the Position is absolute and its value is not an integer
      • isRelative

        public boolean isRelative()
        Returns true if this Position is relative, false otherwise.
        Returns:
        returns true if this Position is relative, false otherwise
      • getValue

        public double getValue()
        Gets the position value.
        Returns:
        returns the position value
      • makeAbsolute

        public int makeAbsolute​(int width)
        Gets the absolute value for this Position by multiplying with the given width. If this position is already absolute, the original value is returned.
        Parameters:
        width - the width to use
        Returns:
        returns the absolute value
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object