
net.time4j.clock.FixedClock Maven / Gradle / Ivy
/*
* -----------------------------------------------------------------------
* Copyright © 2013-2015 Meno Hochschild,
* -----------------------------------------------------------------------
* This file (FixedClock.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.clock;
import net.time4j.Moment;
import net.time4j.base.UnixTime;
/**
* Represents a fixed clock which always display the same current time.
*
* @author Meno Hochschild
* @since 2.1
* @doctags.concurrency {immutable}
*/
/*[deutsch]
* Repräsentiert eine stillstehende Uhr, die immer die gleiche feste
* Zeit anzeigt.
*
* @author Meno Hochschild
* @since 2.1
* @doctags.concurrency {immutable}
*/
public final class FixedClock
extends AbstractClock {
//~ Instanzvariablen --------------------------------------------------
private final Moment moment;
//~ Konstruktoren -----------------------------------------------------
private FixedClock(Moment moment) {
super();
this.moment = moment;
}
//~ Methoden ----------------------------------------------------------
/**
* Creates a new fixed clock.
*
* @param ut fixed clock time
* @return new clock instance with fixed time
* @since 2.1
*/
/*[deutsch]
* Erzeugt eine neue feststehende Uhr.
*
* @param ut fixed clock time
* @return new clock instance with fixed time
* @since 2.1
*/
public static FixedClock of(UnixTime ut) {
return new FixedClock(Moment.from(ut));
}
@Override
public Moment currentTime() {
return this.moment;
}
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
} else if (obj instanceof FixedClock) {
FixedClock that = (FixedClock) obj;
return this.moment.equals(that.moment);
} else {
return false;
}
}
@Override
public int hashCode() {
return 31 * this.moment.hashCode();
}
/**
* For debugging purposes.
*
* @return description of clock state
*/
/*[deutsch]
* Für Debugging-Zwecke.
*
* @return description of clock state
*/
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("FixedClock[");
sb.append("moment=");
sb.append(this.moment);
sb.append(']');
return sb.toString();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy