net.time4j.AbstractTimeElement Maven / Gradle / Ivy
/*
* -----------------------------------------------------------------------
* Copyright © 2013-2014 Meno Hochschild,
* -----------------------------------------------------------------------
* This file (AbstractTimeElement.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.AdvancedElement;
import net.time4j.engine.ChronoFunction;
import net.time4j.tz.TZID;
import net.time4j.tz.Timezone;
import net.time4j.tz.ZonalOffset;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
/**
* Abstrakte Basisklasse für Uhrzeit-Elemente, die bereits alle
* Methoden des Interface {@code AdjustableElement} vordefiniert.
*
* @param generic type of element values
* @author Meno Hochschild
*/
abstract class AbstractTimeElement>
extends AdvancedElement
implements AdjustableElement {
//~ Instanzvariablen --------------------------------------------------
private transient final Map> cache;
//~ Konstruktoren -----------------------------------------------------
AbstractTimeElement(String name) {
super(name);
Map> ops =
new HashMap>();
ops.put(
ElementOperator.OP_MINIMIZE,
new TimeOperator(this, ElementOperator.OP_MINIMIZE));
ops.put(
ElementOperator.OP_MAXIMIZE,
new TimeOperator(this, ElementOperator.OP_MAXIMIZE));
ops.put(
ElementOperator.OP_DECREMENT,
new TimeOperator(this, ElementOperator.OP_DECREMENT));
ops.put(
ElementOperator.OP_INCREMENT,
new TimeOperator(this, ElementOperator.OP_INCREMENT));
ops.put(
ElementOperator.OP_FLOOR,
new TimeOperator(this, ElementOperator.OP_FLOOR));
ops.put(
ElementOperator.OP_CEILING,
new TimeOperator(this, ElementOperator.OP_CEILING));
this.cache = Collections.unmodifiableMap(ops);
}
//~ Methoden ----------------------------------------------------------
@Override
public ElementOperator newValue(V value) {
return new TimeOperator(this, ElementOperator.OP_NEW_VALUE, value);
}
@Override
public ElementOperator minimized() {
return this.cache.get(Integer.valueOf(ElementOperator.OP_MINIMIZE));
}
@Override
public ElementOperator maximized() {
return this.cache.get(Integer.valueOf(ElementOperator.OP_MAXIMIZE));
}
@Override
public ElementOperator decremented() {
return this.cache.get(Integer.valueOf(ElementOperator.OP_DECREMENT));
}
@Override
public ElementOperator incremented() {
return this.cache.get(Integer.valueOf(ElementOperator.OP_INCREMENT));
}
@Override
public ElementOperator atFloor() {
return this.cache.get(Integer.valueOf(ElementOperator.OP_FLOOR));
}
@Override
public ElementOperator atCeiling() {
return this.cache.get(Integer.valueOf(ElementOperator.OP_CEILING));
}
public ElementOperator setLenient(V value) {
return new TimeOperator(this, ElementOperator.OP_LENIENT, value);
}
@Override
public ChronoFunction inStdTimezone() {
return this.in(Timezone.ofSystem());
}
@Override
public ChronoFunction inTimezone(TZID tzid) {
return this.in(Timezone.of(tzid));
}
@Override
public ChronoFunction in(Timezone tz) {
return new ZonalQuery(this, tz);
}
@Override
public ChronoFunction atUTC() {
return this.at(ZonalOffset.UTC);
}
@Override
public ChronoFunction at(ZonalOffset offset) {
return new ZonalQuery(this, offset);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy