001 // Copyright 2008 Waterken Inc. under the terms of the MIT X license
002 // found at http://www.opensource.org/licenses/mit-license.html
003 package org.ref_send.log;
004
005 import java.io.Serializable;
006
007 import org.joe_e.Powerless;
008 import org.ref_send.Record;
009 import org.ref_send.deserializer;
010 import org.ref_send.name;
011
012 /**
013 * A marker for a point in an event loop turn where an event originated.
014 */
015 public class
016 Anchor implements Comparable<Anchor>, Powerless, Record, Serializable {
017 static private final long serialVersionUID = 1L;
018
019 /**
020 * event loop turn in which the event originated
021 */
022 public final Turn turn;
023
024 /**
025 * intra-{@linkplain #turn turn} event number
026 */
027 public final long number;
028
029 /**
030 * Constructs an instance.
031 * @param turn {@link #turn}
032 * @param number {@link #number}
033 */
034 public @deserializer
035 Anchor(@name("turn") final Turn turn,
036 @name("number") final long number) {
037 this.turn = turn;
038 this.number = number;
039 }
040
041 // org.joe_e.Selfless interface
042
043 public boolean
044 equals(final Object o) {
045 return null != o && Anchor.class == o.getClass() &&
046 number == ((Anchor)o).number &&
047 (null!=turn?turn.equals(((Anchor)o).turn):null==((Anchor)o).turn);
048 }
049
050 public int
051 hashCode() {
052 return (null != turn ? turn.hashCode() : 0) +
053 (int)(number ^ (number >>> 32)) +
054 0x7C42A2C4;
055 }
056
057 // java.lang.Comparable interface
058
059 public int
060 compareTo(final Anchor o) {
061 final int major = turn.compareTo(o.turn);
062 if (0 != major) { return major; }
063 final long minor = number - o.number;
064 return minor < 0L ? -1 : minor == 0L ? 0 : 1;
065 }
066 }