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

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

package functionalj.lens.lenses.java.time;

import java.time.Instant;
import java.time.temporal.ChronoField;

import functionalj.lens.core.LensSpec;
import functionalj.lens.lenses.IntegerLens;
import functionalj.lens.lenses.LongLens;
import functionalj.lens.lenses.ObjectLensImpl;

public class InstantLens
                    extends    ObjectLensImpl
                    implements InstantAccess {
    
    public static final InstantLens theInstant = new InstantLens(LensSpec.of(Instant.class));
    
    public final LongLens    seconds = createSubLens(Instant::getEpochSecond, (inst, secs) -> inst.with(ChronoField.INSTANT_SECONDS, secs), LongLens::of);
    public final IntegerLens nanos   = createSubLens(Instant::getNano,        (inst, secs) -> inst.with(ChronoField.NANO_OF_SECOND, secs),  IntegerLens::of);
    
    public static  InstantLens of(LensSpec spec) {
        return new InstantLens(spec);
    }
    
    public InstantLens(LensSpec spec) {
        super(spec);
    }
    
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy