Package org.apache.fop.traits
Class MinOptMax
- java.lang.Object
-
- org.apache.fop.traits.MinOptMax
-
- All Implemented Interfaces:
java.io.Serializable
public final class MinOptMax extends java.lang.Object implements java.io.SerializableThis class holds the resolved (as mpoints) form of aLengthRangeorSpacetype property value.Instances of this class are immutable. All arithmetic methods like
plus,minusormultreturn a different instance. So it is possible to pass around instances without copying.MinOptMaxvalues are used during layout calculations.- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(java.lang.Object obj)MinOptMaxextendMinimum(int newMin)Extends the minimum length to the given length if necessary, and adjusts opt and max accordingly.static MinOptMaxgetInstance(int value)Returns an instance ofMinOptMaxwith one fixed value for all three properties (min, opt, max).static MinOptMaxgetInstance(int min, int opt, int max)Returns an instance ofMinOptMaxwith the given values.intgetMax()Returns the maximum value of thisMinOptMax.intgetMin()Returns the minimum value of thisMinOptMax.intgetOpt()Returns the optimum value of thisMinOptMax.intgetShrink()Returns the shrinkability of thisMinOptMaxwhich is the absolute difference betweenminandopt.intgetStretch()Returns the stretchability of thisMinOptMaxwhich is the absolute difference betweenoptandmax.inthashCode()booleanisElastic()Determines whether thisMinOptMaxallows for shrinking or stretching, which means that at least one of the min or max values isn't equal to the opt value.booleanisNonZero()Determines whether thisMinOptMaxrepresents a non-zero dimension, which means that not all values (min, opt, max) are zero.booleanisStiff()Determines whether thisMinOptMaxdoesn't allow for shrinking or stretching, which means that all values (min, opt, max) are the same.MinOptMaxminus(int value)Subtracts the given value from all three components of this instance and returns the result.MinOptMaxminus(MinOptMax operand)Returns the difference of thisMinOptMaxand the givenMinOptMax.MinOptMaxminusMax(int maxOperand)Do not use, backwards compatibility only.MinOptMaxminusMin(int minOperand)Do not use, backwards compatibility only.MinOptMaxmult(int factor)Returns the product of thisMinOptMaxand the given factor.MinOptMaxplus(int value)Adds the given value to all three components of this instance and returns the result.MinOptMaxplus(MinOptMax operand)Returns the sum of thisMinOptMaxand the givenMinOptMax.MinOptMaxplusMax(int maxOperand)Do not use, backwards compatibility only.MinOptMaxplusMin(int minOperand)Do not use, backwards compatibility only.java.lang.StringtoString()
-
-
-
Field Detail
-
ZERO
public static final MinOptMax ZERO
The zeroMinOptMaxinstance withmin == opt == max == 0.
-
-
Method Detail
-
getInstance
public static MinOptMax getInstance(int min, int opt, int max) throws java.lang.IllegalArgumentException
Returns an instance ofMinOptMaxwith the given values.- Parameters:
min- the minimum valueopt- the optimum valuemax- the maximum value- Returns:
- the corresponding instance
- Throws:
java.lang.IllegalArgumentException- ifmin > opt || max < opt.
-
getInstance
public static MinOptMax getInstance(int value)
Returns an instance ofMinOptMaxwith one fixed value for all three properties (min, opt, max).- Parameters:
value- the value for min, opt and max- Returns:
- the corresponding instance
- See Also:
isStiff()
-
getMin
public int getMin()
Returns the minimum value of thisMinOptMax.- Returns:
- the minimum value of this
MinOptMax.
-
getOpt
public int getOpt()
Returns the optimum value of thisMinOptMax.- Returns:
- the optimum value of this
MinOptMax.
-
getMax
public int getMax()
Returns the maximum value of thisMinOptMax.- Returns:
- the maximum value of this
MinOptMax.
-
getShrink
public int getShrink()
Returns the shrinkability of thisMinOptMaxwhich is the absolute difference betweenminandopt.- Returns:
- the shrinkability of this
MinOptMaxwhich is always non-negative.
-
getStretch
public int getStretch()
Returns the stretchability of thisMinOptMaxwhich is the absolute difference betweenoptandmax.- Returns:
- the stretchability of this
MinOptMaxwhich is always non-negative.
-
plus
public MinOptMax plus(MinOptMax operand)
Returns the sum of thisMinOptMaxand the givenMinOptMax.- Parameters:
operand- the second operand of the sum (the first is this instance itself),- Returns:
- the sum of this
MinOptMaxand the givenMinOptMax.
-
plus
public MinOptMax plus(int value)
Adds the given value to all three components of this instance and returns the result.- Parameters:
value- value to add to the min, opt, max components- Returns:
- the result of the addition
-
minus
public MinOptMax minus(MinOptMax operand) throws java.lang.ArithmeticException
Returns the difference of thisMinOptMaxand the givenMinOptMax. This instance must be a compound of the operand and anotherMinOptMax, that is, there must exist aMinOptMaxm such thatthis.equals(m.plus(operand)). In other words, the operand must have less shrink and stretch than this instance.- Parameters:
operand- the value to be subtracted- Returns:
- the difference of this
MinOptMaxand the givenMinOptMax. - Throws:
java.lang.ArithmeticException- if this instance has strictly less shrink or stretch than the operand
-
minus
public MinOptMax minus(int value)
Subtracts the given value from all three components of this instance and returns the result.- Parameters:
value- value to subtract from the min, opt, max components- Returns:
- the result of the subtraction
-
plusMin
public MinOptMax plusMin(int minOperand) throws java.lang.IllegalArgumentException
Do not use, backwards compatibility only. Returns an instance with the given value added to the minimal value.- Parameters:
minOperand- the minimal value to be added.- Returns:
- an instance with the given value added to the minimal value.
- Throws:
java.lang.IllegalArgumentException- ifmin + minOperand > opt || max < opt.
-
minusMin
public MinOptMax minusMin(int minOperand) throws java.lang.IllegalArgumentException
Do not use, backwards compatibility only. Returns an instance with the given value subtracted to the minimal value.- Parameters:
minOperand- the minimal value to be subtracted.- Returns:
- an instance with the given value subtracted to the minimal value.
- Throws:
java.lang.IllegalArgumentException- ifmin - minOperand > opt || max < opt.
-
plusMax
public MinOptMax plusMax(int maxOperand) throws java.lang.IllegalArgumentException
Do not use, backwards compatibility only. Returns an instance with the given value added to the maximal value.- Parameters:
maxOperand- the maximal value to be added.- Returns:
- an instance with the given value added to the maximal value.
- Throws:
java.lang.IllegalArgumentException- ifmin > opt || max < opt + maxOperand.
-
minusMax
public MinOptMax minusMax(int maxOperand) throws java.lang.IllegalArgumentException
Do not use, backwards compatibility only. Returns an instance with the given value subtracted to the maximal value.- Parameters:
maxOperand- the maximal value to be subtracted.- Returns:
- an instance with the given value subtracted to the maximal value.
- Throws:
java.lang.IllegalArgumentException- ifmin > opt || max < opt - maxOperand.
-
mult
public MinOptMax mult(int factor) throws java.lang.IllegalArgumentException
Returns the product of thisMinOptMaxand the given factor.- Parameters:
factor- the factor- Returns:
- the product of this
MinOptMaxand the given factor - Throws:
java.lang.IllegalArgumentException- if the factor is negative
-
isNonZero
public boolean isNonZero()
Determines whether thisMinOptMaxrepresents a non-zero dimension, which means that not all values (min, opt, max) are zero.- Returns:
trueif thisMinOptMaxrepresents a non-zero dimension;falseotherwise.
-
isStiff
public boolean isStiff()
Determines whether thisMinOptMaxdoesn't allow for shrinking or stretching, which means that all values (min, opt, max) are the same.- Returns:
trueif whether thisMinOptMaxdoesn't allow for shrinking or stretching;falseotherwise.- See Also:
isElastic()
-
isElastic
public boolean isElastic()
Determines whether thisMinOptMaxallows for shrinking or stretching, which means that at least one of the min or max values isn't equal to the opt value.- Returns:
trueif thisMinOptMaxallows for shrinking or stretching;falseotherwise.- See Also:
isStiff()
-
extendMinimum
public MinOptMax extendMinimum(int newMin)
Extends the minimum length to the given length if necessary, and adjusts opt and max accordingly.- Parameters:
newMin- the new minimum length- Returns:
- a
MinOptMaxinstance with the minimum length extended
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-