nl.vpro.domain.media.search.Range Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of media-domain Show documentation
Show all versions of media-domain Show documentation
The basic domain classes for 'media', the core of POMS. Also, the 'update' XML bindings for it.
It also contains some closely related domain classes like the enum to contain NICAM kijkwijzer settings.
package nl.vpro.domain.media.search;
import lombok.Data;
import java.util.function.Predicate;
import java.util.function.Supplier;
import jakarta.xml.bind.annotation.*;
/**
* @author Michiel Meeuwissen
* @since 5.3
*/
public interface Range> extends Predicate {
Range.RangeValue getStart();
default void setStart(Range.RangeValue start) {
throw new UnsupportedOperationException();
}
Range.RangeValue getStop();
default void setStop(Range.RangeValue stop) {
throw new UnsupportedOperationException();
}
default T getStartValue() {
Range.RangeValue start = getStart();
return start == null ? null : start.get();
}
default T getStopValue() {
Range.RangeValue stop= getStop();
return stop == null ? null : stop.get();
}
@Override
default boolean test(T other) {
return testStart(other) && testStop(other);
}
default boolean testStart(T other) {
Range.RangeValue start = getStart();
if (start == null || start.get() == null) {
return true;
}
if (start.isInclusive()) {
return start.get().compareTo(other) <= 0;
} else {
return start.get().compareTo(other) < 0;
}
}
default boolean testStop(T other) {
Range.RangeValue stop = getStop();
if (stop == null || stop.get() == null) {
return true;
}
if (stop.isInclusive()) {
return stop.get().compareTo(other) >= 0;
} else {
return stop.get().compareTo(other) > 0;
}
}
default boolean hasValues() {
return getStartValue() != null || getStopValue() != null;
}
@Data
@XmlAccessorType(XmlAccessType.NONE)
@XmlTransient
abstract class RangeValue> implements Supplier {
// a boxed version for xml binding. So inclusive=true default it not specified.
@XmlAttribute
Boolean inclusive = null;
RangeValue() {
}
public RangeValue(Boolean inclusive) {
setInclusive(inclusive);
}
public boolean isInclusive() {
return inclusive == null || inclusive;
}
public void setInclusive(Boolean inclusive) {
this.inclusive = inclusive == null || inclusive ? null : inclusive;
}
@Override
public T get() {
return getValue();
}
public abstract T getValue();
@Override
public String toString() {
return String.valueOf(getValue());
}
}
}