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

net.time4j.DateOperator Maven / Gradle / Ivy

There is a newer version: 4.38
Show newest version
/*
 * -----------------------------------------------------------------------
 * Copyright © 2013-2015 Meno Hochschild, 
 * -----------------------------------------------------------------------
 * This file (DateOperator.java) is part of project Time4J.
 *
 * Time4J is free software: You can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published
 * by the Free Software Foundation, either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * Time4J is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with Time4J. If not, see .
 * -----------------------------------------------------------------------
 */

package net.time4j;

import net.time4j.engine.ChronoElement;
import net.time4j.engine.ChronoEntity;
import net.time4j.engine.ChronoOperator;
import net.time4j.engine.StdOperator;


/**
 * 

Definiert eine Manipulation von Datumsobjekten nach * dem Strategy-Entwurfsmuster.

* * @author Meno Hochschild * @doctags.concurrency {immutable} */ final class DateOperator extends ElementOperator { //~ Instanzvariablen -------------------------------------------------- private final Object opDelegate; //~ Konstruktoren ----------------------------------------------------- /** *

Konstruiert eine neue Instanz.

* * @param element element an operator will be applied on * @param type type of operator */ DateOperator( ChronoElement element, int type ) { this(element, type, null); } /** *

Konstruiert eine neue Instanz.

* * @param element element an operator will be applied on * @param type operator type * @param value lenient or new value of element */ DateOperator( ChronoElement element, int type, Object value // optional ) { super(element, type); switch (type) { case OP_NEW_VALUE: this.opDelegate = newValue(element, value); break; case OP_MINIMIZE: this.opDelegate = StdOperator.minimized(element); break; case OP_MAXIMIZE: this.opDelegate = StdOperator.maximized(element); break; case OP_DECREMENT: this.opDelegate = StdOperator.decremented(element); break; case OP_INCREMENT: this.opDelegate = StdOperator.incremented(element); break; case OP_FLOOR: this.opDelegate = StdOperator.atFloor(element); break; case OP_CEILING: this.opDelegate = StdOperator.atCeiling(element); break; case OP_LENIENT: this.opDelegate = lenient(element, value); break; default: throw new AssertionError("Unknown: " + this.getType()); } } //~ Methoden ---------------------------------------------------------- @Override @SuppressWarnings("unchecked") public PlainDate apply(PlainDate entity) { ChronoOperator operator = (ChronoOperator) this.opDelegate; return operator.apply(entity); } @Override @SuppressWarnings("unchecked") ChronoOperator onTimestamp() { return (ChronoOperator) this.opDelegate; } private static > Object newValue( ChronoElement element, Object value ) { V v = element.getType().cast(value); ChronoOperator operator = StdOperator.newValue(v, element); return ValueOperator.of(operator, value); } private static > Object lenient( ChronoElement element, Object value ) { V v = element.getType().cast(value); ChronoOperator operator = StdOperator.setLenient(v, element); return ValueOperator.of(operator, value); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy