All Downloads are FREE. Search and download functionalities are using the official Maven repository.

functionalj.lens.lenses.java.time.PeriodAccess Maven / Gradle / Ivy

There is a newer version: 1.0.17
Show newest version
package functionalj.lens.lenses.java.time;

import java.time.Period;
import java.time.temporal.TemporalAmount;
import java.time.temporal.TemporalUnit;
import java.util.function.Function;

import functionalj.lens.lenses.AnyAccess;
import functionalj.lens.lenses.BooleanAccessPrimitive;
import functionalj.lens.lenses.ConcreteAccess;
import functionalj.lens.lenses.IntegerAccessPrimitive;
import functionalj.lens.lenses.ListAccess;
import functionalj.lens.lenses.LongAccessPrimitive;
import lombok.val;


@FunctionalInterface
public interface PeriodAccess
                    extends AnyAccess
                    ,       ChronoPeriodAccess
                    ,       ConcreteAccess> {
    
    public static  PeriodAccess of(Function func) {
        return func::apply;
    }
    
    public default PeriodAccess newAccess(Function accessToValue) {
        return host -> accessToValue.apply(host);
    }
    
    public default LongAccessPrimitive get(TemporalUnit unit) {
        return host -> {
            val value = apply(host);
            return value.get(unit);
        };
    }
    
    public default ListAccess> getUnits() {
        return ListAccess.of(this.then(TemporalAmount::getUnits), TemporalUnitAccess::of);
    }
    
    public default IsoChronologyAccess getChronology() {
        return host -> {
            val value = apply(host);
            return value.getChronology();
        };
    }
    public default BooleanAccessPrimitive isZero() {
        return host -> {
            val value = apply(host);
            return value.isZero();
        };
    }
    public default BooleanAccessPrimitive isNegative() {
        return host -> {
            val value = apply(host);
            return value.isNegative();
        };
    }
    public default IntegerAccessPrimitive getYears() {
        return host -> {
            val value = apply(host);
            return value.getYears();
        };
    }
    public default IntegerAccessPrimitive getMonths() {
        return host -> {
            val value = apply(host);
            return value.getMonths();
        };
    }
    public default IntegerAccessPrimitive getDays() {
        return host -> {
            val value = apply(host);
            return value.getDays();
        };
    }
    public default PeriodAccess withYears(int years) {
        return host -> {
            val value = apply(host);
            return value.withYears(years);
        };
    }
    public default PeriodAccess withMonths(int months) {
        return host -> {
            val value = apply(host);
            return value.withMonths(months);
        };
    }
    public default PeriodAccess withDays(int days) {
        return host -> {
            val value = apply(host);
            return value.withDays(days);
        };
    }
    public default PeriodAccess plus(TemporalAmount amountToAdd) {
        return host -> {
            val value = apply(host);
            return value.plus(amountToAdd);
        };
    }
    public default PeriodAccess plusYears(long yearsToAdd) {
        return host -> {
            val value = apply(host);
            return value.plusYears(yearsToAdd);
        };
    }
    public default PeriodAccess plusMonths(long monthsToAdd) {
        return host -> {
            val value = apply(host);
            return value.plusMonths(monthsToAdd);
        };
    }
    public default PeriodAccess plusDays(long daysToAdd) {
        return host -> {
            val value = apply(host);
            return value.plusDays(daysToAdd);
        };
    }
    public default PeriodAccess minus(TemporalAmount amountToSubtract) {
        return host -> {
            val value = apply(host);
            return value.minus(amountToSubtract);
        };
    }
    public default PeriodAccess minusYears(long yearsToSubtract) {
        return host -> {
            val value = apply(host);
            return value.minusYears(yearsToSubtract);
        };
    }
    public default PeriodAccess minusMonths(long monthsToSubtract) {
        return host -> {
            val value = apply(host);
            return value.minusMonths(monthsToSubtract);
        };
    }
    public default PeriodAccess minusDays(long daysToSubtract) {
        return host -> {
            val value = apply(host);
            return value.minusDays(daysToSubtract);
        };
    }
    public default PeriodAccess multipliedBy(int scalar) {
        return host -> {
            val value = apply(host);
            return value.multipliedBy(scalar);
        };
    }
    public default PeriodAccess negated() {
        return host -> {
            val value = apply(host);
            return value.negated();
        };
    }
    public default PeriodAccess normalized() {
        return host -> {
            val value = apply(host);
            return value.normalized();
        };
    }
    public default LongAccessPrimitive toTotalMonths() {
        return host -> {
            val value = apply(host);
            return value.toTotalMonths();
        };
    }
    
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy