functionalj.lens.lenses.java.time.InstantAccess Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of functionalj-core Show documentation
Show all versions of functionalj-core Show documentation
The module for FunctionalJ Core.
package functionalj.lens.lenses.java.time;
import java.time.Instant;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.temporal.TemporalAdjuster;
import java.time.temporal.TemporalAmount;
import java.time.temporal.TemporalField;
import java.time.temporal.TemporalUnit;
import java.util.function.Function;
import functionalj.lens.lenses.BooleanAccess;
import functionalj.lens.lenses.ConcreteAccess;
import functionalj.lens.lenses.IntegerAccess;
import functionalj.lens.lenses.LongAccess;
import lombok.val;
@FunctionalInterface
public interface InstantAccess
extends TemporalAccess
, TemporalAdjusterAccess
, ConcreteAccess >{
public static InstantAccess of(Function func) {
return func::apply;
}
public default InstantAccess newAccess(Function accessToValue) {
return accessToValue::apply;
}
public default LongAccess getEpochSecond() {
return host -> {
val value = apply(host);
return value.getEpochSecond();
};
}
public default IntegerAccess getNano() {
return host -> {
val value = apply(host);
return value.getNano();
};
}
public default InstantAccess with(TemporalAdjuster adjuster) {
return host -> {
val value = apply(host);
return value.with(adjuster);
};
}
public default InstantAccess with(TemporalField field, long newValue) {
return host -> {
val value = apply(host);
return value.with(field, newValue);
};
}
public default InstantAccess truncatedTo(TemporalUnit unit) {
return host -> {
val value = apply(host);
return value.truncatedTo(unit);
};
}
@Override
public default InstantAccess plus(TemporalAmount amountToAdd) {
return host -> {
val value = apply(host);
return value.plus(amountToAdd);
};
}
@Override
public default InstantAccess plus(long amountToAdd, TemporalUnit unit) {
return host -> {
val value = apply(host);
return value.plus(amountToAdd, unit);
};
}
public default InstantAccess plusSeconds(long secondsToAdd) {
return host -> {
val value = apply(host);
return value.plusSeconds(secondsToAdd);
};
}
public default InstantAccess plusMillis(long millisToAdd) {
return host -> {
val value = apply(host);
return value.plusMillis(millisToAdd);
};
}
public default InstantAccess plusNanos(long nanosToAdd) {
return host -> {
val value = apply(host);
return value.plusNanos(nanosToAdd);
};
}
public default InstantAccess minus(TemporalAmount amountToSubtract) {
return host -> {
val value = apply(host);
return value.minus(amountToSubtract);
};
}
public default InstantAccess minus(long amountToSubtract, TemporalUnit unit) {
return host -> {
val value = apply(host);
return value.minus(amountToSubtract, unit);
};
}
public default InstantAccess minusSeconds(long secondsToSubtract) {
return host -> {
val value = apply(host);
return value.minusSeconds(secondsToSubtract);
};
}
public default InstantAccess minusMillis(long millisToSubtract) {
return host -> {
val value = apply(host);
return value.minusMillis(millisToSubtract);
};
}
public default InstantAccess minusNanos(long nanosToSubtract) {
return host -> {
val value = apply(host);
return value.minusNanos(nanosToSubtract);
};
}
public default OffsetDateTimeAccess atOffset(ZoneOffset offset) {
return host -> {
val value = apply(host);
return value.atOffset(offset);
};
}
public default ZonedDateTimeAccess atZone(ZoneId zone) {
return host -> {
val value = apply(host);
return value.atZone(zone);
};
}
public default LongAccess toEpochMilli() {
return host -> {
val value = apply(host);
return value.toEpochMilli();
};
}
public default IntegerAccess compareTo(Instant other) {
return host -> {
val value = apply(host);
return value.compareTo(other);
};
}
public default BooleanAccess thatGreaterThan(Instant anotherValue) {
return booleanAccess(false, any -> any.compareTo(anotherValue) > 0);
}
public default BooleanAccess thatLessThan(Instant anotherValue) {
return booleanAccess(false, any -> any.compareTo(anotherValue) < 0);
}
public default BooleanAccess thatGreaterThanOrEqualsTo(Instant anotherValue) {
return booleanAccess(false, any -> any.compareTo(anotherValue) >= 0);
}
public default BooleanAccess thatLessThanOrEqualsTo(Instant anotherValue) {
return booleanAccess(false, any -> any.compareTo(anotherValue) <= 0);
}
public default BooleanAccess thatIsAfter(Instant other) {
return host -> {
val value = apply(host);
return value.isAfter(other);
};
}
public default BooleanAccess thatIsBefore(Instant other) {
return host -> {
val value = apply(host);
return value.isBefore(other);
};
}
}