public abstract class Measure<T extends MeasureEnum> extends java.lang.Object implements java.lang.Comparable<Measure<T>>
Modifier and Type | Field and Description |
---|---|
protected RationalNumber |
amount |
protected static java.util.regex.Pattern |
PARSE_PATTERN
The general pattern for parsing measurements
|
protected static java.lang.String |
PARSED_AMOUNT_NAME
The group name representing the amount of the measure
|
protected static java.lang.String |
PARSED_UNIT_NAME
The group name representing the unit of measure
|
protected T |
size |
Modifier | Constructor and Description |
---|---|
protected |
Measure(double amount,
T measure)
Creates a storage amount
|
protected |
Measure(Measure<T> other)
Creates a copy of the other measurement and returns it
|
protected |
Measure(RationalNumber amount,
T measure)
Creates a storage amount
|
Modifier and Type | Method and Description |
---|---|
<U extends Measure<T>> |
add(U other)
Adds an amount to the current amount
|
int |
compareTo(Measure<T> other) |
<U extends Measure<T>> |
convertSize(T newSize)
Converts one measure to another, by changing the size type.
|
<U extends Measure<T>> |
convertToBaseSize()
Converts this measurement to it's base size
|
<U extends Measure<T>> |
convertToBestSize()
Converts this to the best size fit to write out with the smallest fraction part in acceptable sizes
|
<U extends Measure<T>> |
convertToBestSize(MeasurementSystem... allowedSystems)
Converts this to the best size fit to write out with the smallest fraction part in acceptable sizes
|
<U extends Measure<T>> |
divideBy(double amount)
Divides the current amount by a given constant
|
<U extends Measure<T>> |
divideBy(RationalNumber amount)
Divides the current amount by a given constant
|
<U extends Measure<T>> |
divideBy(U amount)
Divides the current amount by a given amount
|
boolean |
equals(java.lang.Object o)
Checks to see if this is equal to another measurement, but converts to the same units first.
|
RationalNumber |
getAmount()
Returns the amount of the measurement
|
RationalNumber |
getAmountAs(T measure)
Returns the amount of this measure in a different size
|
protected RationalNumber |
getAmountInBaseSize()
Returns the size of this measurement in it's base form, as an amount
|
protected int |
getGoodDenominator()
The value at which a value is "good" if it has a denominator less than this.
|
T |
getSize()
Returns the current measurement unit
|
java.lang.String |
getSizeString()
Returns the name portion of the measure
|
boolean |
greaterThan(Measure<T> other)
Returns this > other
|
boolean |
greaterThanOrEqualTo(Measure<T> other)
Returns this >= other
|
int |
hashCode() |
boolean |
lessThan(Measure<T> other)
Returns this < other
|
boolean |
lessThanOrEqualTo(Measure<T> other)
Returns this <= other
|
protected java.util.List<T> |
listSizes(T smallestSize,
T largestSize,
MeasurementSystem... allowedSystems)
Lists all the sizes in this size, from largest to smallest with the given filtering criteria
|
<U extends Measure<T>> |
minus(U other)
Subtracts an amount from the current amount
|
<U extends Measure<T>> |
multiply(double amount)
Multiplies the current amount by a given constant
|
<U extends Measure<T>> |
multiply(RationalNumber amount)
Multiplies the current amount by a given constant
|
(package private) static <U extends MeasureEnum,V extends Measure<U>> |
parseGeneric(java.lang.String text,
java.lang.Class<V> measureClass,
U baseSize)
Generic parse method
|
static <U extends Measure> |
parseMeasure(java.lang.String text)
Parses the text to the given type of measure
|
<U extends Measure<T>> |
plus(U other)
Adds an amount to the current amount
|
<U extends Measure<T>> |
roundToNearestFraction(RationalNumber multiple)
Returns a measurement in the current size that is the nearest whole multiple of the given size.
|
<U extends Measure<T>> |
roundToNearestFractionInSize(RationalNumber multiple,
T newSize)
Returns a measurement in the given size that is the nearest whole multiple of the given size.
|
<U extends Measure<T>> |
subtract(U other)
Subtracts an amount from the current amount
|
<U extends Measure<T>> |
times(double amount)
Multiplies the current amount by a given constant
|
<U extends Measure<T>> |
times(RationalNumber amount)
Multiplies the current amount by a given constant
|
java.lang.String |
toExpandedDecimalString(T smallestSize,
T largestSize,
int maxToShow,
boolean showIntermediateZeroValues,
boolean limitFromFirstFound,
int decimalPlacesToShow,
MeasurementSystem... allowedSystems)
Outputs the measurement in a pretty string format.
|
java.lang.String |
toExpandedString()
Outputs the measurement in a pretty string format.
|
java.lang.String |
toExpandedString(int maxToShow)
Outputs the measurement in a pretty string format.
|
java.lang.String |
toExpandedString(int maxToShow,
boolean limitFromFirstFound)
Outputs the measurement in a pretty string format.
|
java.lang.String |
toExpandedString(T smallestSize,
T largestSize)
Outputs the measurement in a pretty string format.
|
java.lang.String |
toExpandedString(T smallestSize,
T largestSize,
int maxToShow,
boolean showIntermediateZeroValues,
boolean limitFromFirstFound)
Outputs the measurement in a pretty string format.
|
java.lang.String |
toExpandedString(T smallestSize,
T largestSize,
int maxToShow,
boolean showIntermediateZeroValues,
boolean limitFromFirstFound,
boolean truncateFinalValue,
MeasurementSystem... allowedSystems)
Outputs the measurement in a pretty string format.
|
java.lang.String |
toExpandedString(T smallestSize,
T largestSize,
int maxToShow,
boolean showIntermediateZeroValues,
boolean limitFromFirstFound,
MeasurementSystem... allowedSystems)
Outputs the measurement in a pretty string format.
|
java.lang.String |
toString() |
java.lang.String |
toStringWithWholePart()
Returns a string representation of this measurement, but splits the number portion into both a whole quantity and a fraction
|
static <U extends Measure> |
valueOf(java.lang.String text)
Parses the text to the given type of measure.
|
protected final RationalNumber amount
protected final T extends MeasureEnum size
protected static final java.util.regex.Pattern PARSE_PATTERN
protected static final java.lang.String PARSED_AMOUNT_NAME
protected static final java.lang.String PARSED_UNIT_NAME
protected Measure(double amount, T measure)
amount
- The amountmeasure
- The measurement measureprotected Measure(RationalNumber amount, T measure)
amount
- The amountmeasure
- The measurement measure@NotNull public static <U extends Measure> U valueOf(java.lang.String text) throws java.text.ParseException
text
- The text to parsejava.text.ParseException
- If the text could not be parsed into the measurement@NotNull public static <U extends Measure> U parseMeasure(java.lang.String text) throws java.text.ParseException
text
- The text to parsejava.text.ParseException
- If the text could not be parsed into the measurement@Nullable static <U extends MeasureEnum,V extends Measure<U>> V parseGeneric(@NotNull java.lang.String text, java.lang.Class<V> measureClass, @NotNull U baseSize) throws java.text.ParseException
U
- The Measurement Size typeV
- The Measure typetext
- The text to parsemeasureClass
- The measurement classbaseSize
- The base sizejava.text.ParseException
- If an error occurs while parsing the given textprotected int getGoodDenominator()
public <U extends Measure<T>> U convertSize(T newSize)
U
- The same type of measurementnewSize
- The new size typepublic <U extends Measure<T>> U roundToNearestFraction(@NotNull RationalNumber multiple)
RationalNumber.roundToNearestMultiple(RationalNumber)
for more details.U
- The same type of measurementmultiple
- The multiple to fraction multiple topublic <U extends Measure<T>> U roundToNearestFractionInSize(@NotNull RationalNumber multiple, T newSize)
RationalNumber.roundToNearestMultiple(RationalNumber)
for more details.U
- The same type of measurementmultiple
- The multiple to fraction multiple tonewSize
- The new measurement size for the measurementpublic <U extends Measure<T>> U plus(@NotNull U other)
U
- The same type of measurementother
- The amount to addpublic <U extends Measure<T>> U add(@NotNull U other)
U
- The same type of measurementother
- The amount to addpublic <U extends Measure<T>> U minus(@NotNull U other)
U
- The same type of measurementother
- The amount to subtractpublic <U extends Measure<T>> U subtract(@NotNull U other)
U
- The same type of measurementother
- The amount to subtractpublic <U extends Measure<T>> U multiply(double amount)
U
- The same type of measurementamount
- The amount to multiply bypublic <U extends Measure<T>> U multiply(@NotNull RationalNumber amount)
U
- The same type of measurementamount
- The amount to multiply bypublic <U extends Measure<T>> U times(double amount)
U
- The same type of measurementamount
- The amount to multiply bypublic <U extends Measure<T>> U times(@NotNull RationalNumber amount)
U
- The same type of measurementamount
- The amount to multiply bypublic <U extends Measure<T>> U divideBy(double amount)
U
- The same type of measurementamount
- The amount to divide bypublic <U extends Measure<T>> U divideBy(@NotNull RationalNumber amount)
U
- The same type of measurementamount
- The amount to divide bypublic <U extends Measure<T>> RationalNumber divideBy(@NotNull U amount)
U
- The same type of measurementamount
- The amount to divide bypublic T getSize()
public RationalNumber getAmount()
protected RationalNumber getAmountInBaseSize()
public java.lang.String getSizeString()
public <U extends Measure<T>> U convertToBaseSize()
U
- The measure type@NotNull public java.lang.String toExpandedString()
@NotNull public java.lang.String toExpandedString(@Nullable T smallestSize, @Nullable T largestSize)
smallestSize
- The smallest size that should be output (smaller values are truncated)largestSize
- The largest size that should be output (larger values are added in, so you may get something like 3600 seconds)@NotNull public java.lang.String toExpandedString(int maxToShow)
maxToShow
- The maximum sizes to show total. This can be used so if a value is output in years, milliseconds won't have to be shown. Set to <=0 to show all
values@NotNull public java.lang.String toExpandedString(int maxToShow, boolean limitFromFirstFound)
maxToShow
- The maximum sizes to show total. This can be used so if a value is output in years, milliseconds won't have to be shown. Set to <=0 to show all
valueslimitFromFirstFound
- True if the maxToShow should count each zero value after the first non-zero value. False to only count values >= 1@NotNull public java.lang.String toExpandedString(@Nullable T smallestSize, @Nullable T largestSize, int maxToShow, boolean showIntermediateZeroValues, boolean limitFromFirstFound)
smallestSize
- The smallest size that should be output (smaller values are truncated)largestSize
- The largest size that should be output (larger values are added in, so you may get something like 3600 seconds)maxToShow
- The maximum sizes to show total. This can be used so if a value is output in years, milliseconds won't have to be shown. Set to <=0 to show all
valuesshowIntermediateZeroValues
- True if values after the first non-zero value should still show, even if they are 0. False to only show values >=1limitFromFirstFound
- True if the maxToShow should count each zero value after the first non-zero value. False to only count values >= 1@NotNull public java.lang.String toExpandedString(@Nullable T smallestSize, @Nullable T largestSize, int maxToShow, boolean showIntermediateZeroValues, boolean limitFromFirstFound, MeasurementSystem... allowedSystems)
smallestSize
- The smallest size that should be output (smaller values are truncated)largestSize
- The largest size that should be output (larger values are added in, so you may get something like 3600 seconds)maxToShow
- The maximum sizes to show total. This can be used so if a value is output in years, milliseconds won't have to be shown. Set to <=0 to show all
valuesshowIntermediateZeroValues
- True if values after the first non-zero value should still show, even if they are 0. False to only show values >=1limitFromFirstFound
- True if the maxToShow should count each zero value after the first non-zero value. False to only count values >= 1allowedSystems
- The systems of measurement to allow in the expanded string version@NotNull public java.lang.String toExpandedString(@Nullable T smallestSize, @Nullable T largestSize, int maxToShow, boolean showIntermediateZeroValues, boolean limitFromFirstFound, boolean truncateFinalValue, @Nullable MeasurementSystem... allowedSystems)
smallestSize
- The smallest size that should be output (smaller values are truncated)largestSize
- The largest size that should be output (larger values are added in, so you may get something like 3600 seconds)maxToShow
- The maximum sizes to show total. This can be used so if a value is output in years, milliseconds won't have to be shown. Set to <=0 to show all
valuesshowIntermediateZeroValues
- True if values after the first non-zero value should still show, even if they are 0. False to only show values >=1limitFromFirstFound
- True if the maxToShow should count each zero value after the first non-zero value. False to only count values >= 1truncateFinalValue
- True if the final value should be shown only as a whole number (as opposed to a fraction). If the fraction has a good denominator, it
will not be truncatedallowedSystems
- The systems of measurement to allow in the expanded string version@NotNull public java.lang.String toExpandedDecimalString(@Nullable T smallestSize, @Nullable T largestSize, int maxToShow, boolean showIntermediateZeroValues, boolean limitFromFirstFound, int decimalPlacesToShow, @Nullable MeasurementSystem... allowedSystems)
smallestSize
- The smallest size that should be output (smaller values are truncated)largestSize
- The largest size that should be output (larger values are added in, so you may get something like 3600 seconds)maxToShow
- The maximum sizes to show total. This can be used so if a value is output in years, milliseconds won't have to be shown. Set to <=0 to show all
valuesshowIntermediateZeroValues
- True if values after the first non-zero value should still show, even if they are 0. False to only show values >=1limitFromFirstFound
- True if the maxToShow should count each zero value after the first non-zero value. False to only count values >= 1decimalPlacesToShow
- The number of decimal places to display instead of a fractional value for the final value. If truncateFinalValue is true, this value does nothing. Negative means force trailing 0s on the decimal, with the magnitude being how many to show maxallowedSystems
- The systems of measurement to allow in the expanded string version@NotNull protected java.util.List<T> listSizes(@Nullable T smallestSize, @Nullable T largestSize, MeasurementSystem... allowedSystems)
smallestSize
- The smallest size to allowlargestSize
- The largest size to allowallowedSystems
- The allowed measurement systemspublic <U extends Measure<T>> U convertToBestSize()
public RationalNumber getAmountAs(T measure)
measure
- The new sizepublic <U extends Measure<T>> U convertToBestSize(MeasurementSystem... allowedSystems)
allowedSystems
- What measurement systems are allowed to be used@NotNull public java.lang.String toStringWithWholePart()
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
o
- The other measurementpublic boolean greaterThan(Measure<T> other)
other
- The other number. Null is smaller than everythingpublic boolean greaterThanOrEqualTo(Measure<T> other)
other
- The other number. Null is smaller than everythingpublic boolean lessThan(Measure<T> other)
other
- The other number. Null is smaller than everythingpublic boolean lessThanOrEqualTo(Measure<T> other)
other
- The other number. Null is smaller than everythingpublic int compareTo(@Nullable Measure<T> other)
compareTo
in interface java.lang.Comparable<Measure<T extends MeasureEnum>>
public int hashCode()
hashCode
in class java.lang.Object
@NotNull public java.lang.String toString()
toString
in class java.lang.Object