Package org.daisy.dotify.api.formatter
Class Position
- java.lang.Object
-
- org.daisy.dotify.api.formatter.Position
-
public class Position extends Object
Position is a data object for an integer position.
-
-
Constructor Summary
Constructors Constructor Description Position(double value, boolean isRelative)
Create a new Position with the supplied value.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object obj)
double
getValue()
Gets the position value.int
hashCode()
boolean
isRelative()
Returns true if this Position is relative, false otherwise.int
makeAbsolute(int width)
Gets the absolute value for this Position by multiplying with the given width.static Position
parsePosition(String pos)
Parses the supplied String as a Position.
-
-
-
Constructor Detail
-
Position
public Position(double value, boolean isRelative)
Create a new Position with the supplied value.- Parameters:
value
- the positionisRelative
- 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
-
-