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

net.time4j.PrecisionElement Maven / Gradle / Ivy

There is a newer version: 4.38
Show newest version
/*
 * -----------------------------------------------------------------------
 * Copyright © 2013-2015 Meno Hochschild, 
 * -----------------------------------------------------------------------
 * This file (PrecisionElement.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.ChronoDisplay;
import net.time4j.engine.ChronoElement;

import java.util.concurrent.TimeUnit;


/**
 * 

Das Element für die Genauigkeit einer Uhrzeitangabe.

* * @author Meno Hochschild */ class PrecisionElement> implements ChronoElement { //~ Statische Felder/Initialisierungen -------------------------------- static final ChronoElement CLOCK_PRECISION = new PrecisionElement(ClockUnit.class, ClockUnit.HOURS, ClockUnit.NANOS); static final ChronoElement TIME_PRECISION = new PrecisionElement(TimeUnit.class, TimeUnit.DAYS, TimeUnit.NANOSECONDS); //~ Instanzvariablen -------------------------------------------------- private final Class type; private transient final U min; private transient final U max; //~ Konstruktoren ----------------------------------------------------- private PrecisionElement( Class type, U min, U max ) { super(); this.type = type; this.min = min; this.max = max; } //~ Methoden ---------------------------------------------------------- @Override public String name() { return "PRECISION"; } @Override public Class getType() { return this.type; } @Override public U getDefaultMinimum() { return this.min; } @Override public U getDefaultMaximum() { return this.max; } @Override public boolean isDateElement() { return false; } @Override public boolean isTimeElement() { return true; } @Override public int compare( ChronoDisplay o1, ChronoDisplay o2 ) { U u1 = o1.get(this); U u2 = o2.get(this); if (this.type == ClockUnit.class) { return u1.compareTo(u2); } else { return u2.compareTo(u1); } } @Override public char getSymbol() { return '\u0000'; } @Override public boolean isLenient() { return false; } /** * @serialData serves for singleton semantic * @return replacement object */ private Object readResolve() { return ((this.type == ClockUnit.class) ? CLOCK_PRECISION : TIME_PRECISION); } }