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

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

package functionalj.lens.lenses.java.time;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.Month;

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

public class LocalDateTimeLens
                    extends    ObjectLensImpl
                    implements LocalDateTimeAccess {
    
    public static final LocalDateTimeLens theLocalDateTime = new LocalDateTimeLens(LensSpec.of(LocalDateTime.class));
    
    public final LocalDateLens date  = createSubLens(LocalDateTime::toLocalDate, (LocalDateTime dt, LocalDate d) -> LocalDateTime.of(d.getYear(),  d.getMonthValue(),  d.getDayOfMonth(),  dt.getHour(), dt.getMinute(), dt.getSecond(), dt.getNano()), LocalDateLens::new);
    public final LocalTimeLens time = createSubLens(LocalDateTime::toLocalTime, (LocalDateTime dt, LocalTime t) -> LocalDateTime.of(dt.getYear(), dt.getMonthValue(), dt.getDayOfMonth(), t.getHour(),  t.getMinute(),  t.getSecond(),  t.getNano()),  LocalTimeLens::new);
    
    public final IntegerLens year  = createSubLens(LocalDateTime::getYear,       LocalDateTime::withYear,                                IntegerLens::of);
    public final MonthLens   month = createSubLens(LocalDateTime::getMonth,      (dt, month) -> dt.withMonth(((Month)month).getValue()), MonthLens::new);
    public final IntegerLens day   = createSubLens(LocalDateTime::getDayOfMonth, LocalDateTime::withDayOfMonth,                          IntegerLens::of);
    
    public final IntegerLens monthValue = createSubLens(LocalDateTime::getMonthValue, LocalDateTime::withMonth,     IntegerLens::of);
    public final IntegerLens dayOfYear  = createSubLens(LocalDateTime::getDayOfYear,  LocalDateTime::withDayOfYear, IntegerLens::of);
    
    public final IntegerLens hour   = createSubLens(LocalDateTime::getHour,   LocalDateTime::withHour,   IntegerLens::of);
    public final IntegerLens minute = createSubLens(LocalDateTime::getMinute, LocalDateTime::withMinute, IntegerLens::of);
    public final IntegerLens second = createSubLens(LocalDateTime::getSecond, LocalDateTime::withSecond, IntegerLens::of);
    public final IntegerLens nano   = createSubLens(LocalDateTime::getNano,   LocalDateTime::withNano,   IntegerLens::of);
    
    public static  LocalDateTimeLens of(LensSpec spec) {
        return new LocalDateTimeLens(spec);
    }
    
    public LocalDateTimeLens(LensSpec spec) {
        super(spec);
    }
    
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy