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

functionalj.lens.lenses.PrimitiveLensSpecs Maven / Gradle / Ivy

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

import java.util.function.Predicate;
import java.util.function.ToDoubleFunction;
import java.util.function.ToIntFunction;
import java.util.function.ToLongFunction;

import functionalj.lens.core.LensSpec;
import functionalj.lens.core.WriteLens;
import lombok.val;


public class PrimitiveLensSpecs {
    
    public static class IntegerLensSpecPrimitive extends LensSpec {
        private final ToIntFunction readInt;

        public IntegerLensSpecPrimitive(ToIntFunction readInt, WriteLens.PrimitiveInt writeInt) {
            super(host -> readInt.applyAsInt(host), writeInt);
            this.readInt = readInt;
        }
        
        public ToIntFunction getReadInt() {
            return readInt;
        }
        
        public WriteLens.PrimitiveInt getWriteInt() {
            return (WriteLens.PrimitiveInt)getWrite();
        }
        
        public int applyAsInt(HOST value) {
            return readInt.applyAsInt(value);
        }
        public HOST applyWithInt(HOST host, int newValue) {
            val writePrimitive = (WriteLens.PrimitiveInt)getWrite();
            return writePrimitive.applyWithInt(host, newValue);
        }
    }
    
    public static class LongLensSpecPrimitive extends LensSpec {
        private final ToLongFunction readLong;
        
        public LongLensSpecPrimitive(ToLongFunction readLong, WriteLens.PrimitiveLong writeLong) {
            super(host -> readLong.applyAsLong(host), writeLong);
            this.readLong = readLong;
        }
        
        public ToLongFunction getReadLong() {
            return readLong;
        }
        
        public WriteLens.PrimitiveLong getWriteLong() {
            return (WriteLens.PrimitiveLong)getWrite();
        }
        
        public long applyAsLong(HOST value) {
            return readLong.applyAsLong(value);
        }
        public HOST applyWithLong(HOST host, long newValue) {
            val writePrimitive = (WriteLens.PrimitiveLong)getWrite();
            return writePrimitive.applyWithLong(host, newValue);
        }
    }
    
    public static class DoubleLensSpecPrimitive extends LensSpec {
        private final ToDoubleFunction readDouble;

        public DoubleLensSpecPrimitive(ToDoubleFunction readDouble, WriteLens.PrimitiveDouble writeDouble) {
            super(host -> readDouble.applyAsDouble(host), writeDouble);
            this.readDouble = readDouble;
        }
        
        public ToDoubleFunction getReadDouble() {
            return readDouble;
        }
        
        public WriteLens.PrimitiveDouble getWriteDouble() {
            return (WriteLens.PrimitiveDouble)getWrite();
        }
        
        public double applyAsDouble(HOST value) {
            return readDouble.applyAsDouble(value);
        }
        public HOST applyWithDouble(HOST host, double newValue) {
            val writePrimitive = (WriteLens.PrimitiveDouble)getWrite();
            return writePrimitive.applyWithDouble(host, newValue);
        }
    }
    
    public static class BooleanLensSpecPrimitive extends LensSpec {
        private final Predicate readBoolean;
        
        public BooleanLensSpecPrimitive(Predicate readBoolean, WriteLens.PrimitiveBoolean writeBoolean) {
            super(host -> readBoolean.test(host), writeBoolean);
            this.readBoolean = readBoolean;
        }
        
        public Predicate getReadBoolean() {
            return readBoolean;
        }
        
        public WriteLens.PrimitiveBoolean getWriteBoolean() {
            return (WriteLens.PrimitiveBoolean)getWrite();
        }
        
        public boolean test(HOST value) {
            return readBoolean.test(value);
        }
        public HOST applyWithBoolean(HOST host, boolean newValue) {
            val writePrimitive = (WriteLens.PrimitiveBoolean)getWrite();
            return writePrimitive.applyWithBoolean(host, newValue);
        }
    }
    
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy