Package com.storedobject.common
Class Range<T>
java.lang.Object
com.storedobject.common.Range<T>
- Type Parameters:
T- the type of the values representing the range boundaries
- Direct Known Subclasses:
AbstractPeriod,IntegerRange,LongRange
Represents a generic range of values of type T. This abstract class is intended to
be extended by specific range implementations that define behavior for particular types.
The range is defined by two endpoints: a starting point ("from") and an ending point ("to").
- Author:
- Syam
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected TCreates a shallow copy of the provided object.final booleanfinal booleanCompares the given range boundaries with the current range for equality.getFrom()Retrieves the starting value of the range.getTo()Retrieves the ending value of the range.booleanisValid()Checks if the range is considered valid based on its boundaries.protected booleanCompares two objects of type T for equality.toString()protected StringConverts the provided data of type T to its string representation.protected longCalculates a numeric representation of the given data.
-
Field Details
-
from
Represents the starting point of the range. This variable defines the inclusive lower boundary of the range for the specified typeT. It is immutable and retains the initial value provided at the time of instantiation of the range. The interpretation of the value is specific to the typeTand may depend on the implementation of the subclass. For example, in a numeric range, this could represent the minimum value, while in a date range, this could represent the earlier date. The variable is protected, allowing access to subclasses ofRange, and final, ensuring that its value cannot be modified after initialization. -
to
Represents the starting point of the range. This variable defines the inclusive lower boundary of the range for the specified typeT. It is immutable and retains the initial value provided at the time of instantiation of the range. The interpretation of the value is specific to the typeTand may depend on the implementation of the subclass. For example, in a numeric range, this could represent the minimum value, while in a date range, this could represent the earlier date. The variable is protected, allowing access to subclasses ofRange, and final, ensuring that its value cannot be modified after initialization.
-
-
Constructor Details
-
Range
-
-
Method Details
-
getFrom
Retrieves the starting value of the range.- Returns:
- the starting value of the range, cloned from the internal "from" field
-
getTo
Retrieves the ending value of the range.- Returns:
- the ending value of the range, cloned from the internal "to" field
-
clone
-
equals
-
equals
Compares the given range boundaries with the current range for equality.- Parameters:
from- the starting value of the range to compare; can be nullto- the ending value of the range to compare; can be null- Returns:
- true if both the starting and ending values match the current range; false otherwise
-
same
-
isValid
public boolean isValid()Checks if the range is considered valid based on its boundaries. A range is valid if neither boundary is null and one of the following is true: the starting boundary value is less than the ending boundary value, or both boundaries are considered equal.- Returns:
- true if the range is valid; false otherwise
-
value
Calculates a numeric representation of the given data. The implementation currently returns a default value.- Parameters:
data- the input data, potentially used to determine the numeric value; must be of type T- Returns:
- a numeric representation of the input data, which is currently a fixed value of 0L
-
toString
-
toString
-