io.army.mapping.postgre.ArmyPostgreRange Maven / Gradle / Ivy
package io.army.mapping.postgre;
import javax.annotation.Nullable;
import io.army.type.DaoLayer;
/**
*
* This interface representing postgre range type. The implementations of this interface must provide public static
* emptyRange() for return empty range instance.
*
* NOTE :
*
* - This interface present only in DAO layer,not service layer,business layer,web layer.
* - Your class must declare the methods of this interface,but your class possibly isn't the subclass of this interface.
*
* example:
*
* public static final class Int4Range {
* public static Int4Range create(@Nullable Integer lower, boolean includeLower,
* @Nullable Integer upper, boolean includeUpper) {
* return new Int4Range(lower, includeLower, upper, includeUpper);
* }
* private static final Int4Range EMPTY = new Int4Range(null, false, null, false);
* //must provide this public static factory method
* public static Int4Range emptyRange() {
* return EMPTY;
* }
* private final Integer lower;
* private final boolean includeLower;
* private final Integer upper;
* private final boolean includeUpper;
* private Int4Range(@Nullable Integer lower, boolean includeLower, @Nullable Integer upper,
* boolean includeUpper) {
* this.lower = lower;
* // when lower is null includeLower is false
* this.includeLower = lower != null && includeLower;
* this.upper = upper;
* // when upper is null includeUpper is false
* this.includeUpper = upper != null && includeUpper;
* }
* public boolean isEmpty() {
* return this == EMPTY;
* }
*
* public boolean isIncludeLowerBound() {
* if (this == EMPTY) {
* throw new IllegalStateException();
* }
* return this.includeLower;
* }
*
* public boolean isIncludeUpperBound() {
* if (this == EMPTY) {
* throw new IllegalStateException();
* }
* return this.includeUpper;
* }
* @Nullable
* public Integer getLowerBound() {
* if (this == EMPTY) {
* throw new IllegalStateException();
* }
* return this.lower;
* }
* @Nullable
* public Integer getUpperBound() {
* if (this == EMPTY) {
* throw new IllegalStateException();
* }
* return this.upper;
* }
* @Override
* public int hashCode() {
* return Objects.hash(this.lower, this.includeLower, this.upper, this.includeUpper);
* }
* @Override
* public boolean equals(final Object obj) {
* final boolean match;
* if (obj == this) {
* match = true;
* } else if (obj instanceof Int4Range) {
* final Int4Range o = (Int4Range) obj;
* match = Objects.equals(o.lower, this.lower)
* && o.includeLower == this.includeLower
* && Objects.equals(o.upper, this.upper)
* && o.includeUpper == this.includeUpper;
* } else {
* match = false;
* }
* return match;
* }
*
* }//Int4Range
*
*
* @see RangeFunction
* @see Range Types
* @since 1.0
*/
@DaoLayer
public interface ArmyPostgreRange {
/**
* @return true : empty
* @see Range Input/Output
*/
boolean isEmpty();
/**
* @return true: when only include lower bound
* @throws IllegalStateException when {@link #isEmpty()} is true.
*/
boolean isIncludeLowerBound();
/**
*
* null representing infinity bound.
*
*
* @throws IllegalStateException when {@link #isEmpty()} is true.
*/
@Nullable
T getLowerBound();
/**
*
* null representing infinity bound.
*
*
* @throws IllegalStateException when {@link #isEmpty()} is true.
*/
@Nullable
T getUpperBound();
/**
* @return true: when only include upper bound
* @throws IllegalStateException when {@link #isEmpty()} is true.
*/
boolean isIncludeUpperBound();
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy