net.time4j.DecimalTimeElement Maven / Gradle / Ivy
/*
* -----------------------------------------------------------------------
* Copyright © 2013-2016 Meno Hochschild,
* -----------------------------------------------------------------------
* This file (DecimalTimeElement.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.BasicElement;
import net.time4j.engine.ChronoFunction;
import net.time4j.tz.TZID;
import net.time4j.tz.Timezone;
import net.time4j.tz.ZonalOffset;
import java.io.InvalidObjectException;
import java.io.ObjectStreamException;
import java.math.BigDecimal;
/**
* Ein dezimales Uhrzeitelement.
*
* @author Meno Hochschild
* @doctags.concurrency {immutable}
*/
final class DecimalTimeElement
extends BasicElement
implements ZonalElement {
//~ Statische Felder/Initialisierungen --------------------------------
private static final long serialVersionUID = -4837430960549551204L;
//~ Instanzvariablen --------------------------------------------------
private transient final BigDecimal defaultMax;
//~ Konstruktoren -----------------------------------------------------
/**
* Erzeugt eine neue Instanz.
*
* @param name name of element
* @param defaultMax default maximum
*/
DecimalTimeElement(
String name,
BigDecimal defaultMax
) {
super(name);
this.defaultMax = defaultMax;
}
//~ Methoden ----------------------------------------------------------
@Override
public Class getType() {
return BigDecimal.class;
}
@Override
public BigDecimal getDefaultMinimum() {
return BigDecimal.ZERO;
}
@Override
public BigDecimal getDefaultMaximum() {
return this.defaultMax;
}
@Override
public boolean isDateElement() {
return false;
}
@Override
public boolean isTimeElement() {
return true;
}
@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);
}
@Override
protected boolean isSingleton() {
return true;
}
private Object readResolve() throws ObjectStreamException {
Object element = PlainTime.lookupElement(this.name());
if (element == null) {
throw new InvalidObjectException(this.name());
} else {
return element;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy