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 * An event loop turn identifier. 014 */ 015 public final class 016 Turn implements Comparable<Turn>, Powerless, Record, Serializable { 017 static private final long serialVersionUID = 1L; 018 019 /** 020 * URI for the event loop 021 */ 022 public final String loop; 023 024 /** 025 * local turn number 026 */ 027 public final long number; 028 029 /** 030 * Constructs an instance. 031 * @param loop {@link #loop} 032 * @param number {@link #number} 033 */ 034 public @deserializer 035 Turn(@name("loop") final String loop, 036 @name("number") final long number) { 037 this.loop = loop; 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 && Turn.class == o.getClass() && 046 number == ((Turn)o).number && 047 (null!=loop ? loop.equals(((Turn)o).loop) : null == ((Turn)o).loop); 048 } 049 050 public int 051 hashCode() { 052 return (null != loop ? loop.hashCode() : 0) + 053 (int)(number ^ (number >>> 32)) + 054 0x10097C42; 055 } 056 057 // java.lang.Comparable interface 058 059 public int 060 compareTo(final Turn o) { 061 if (!(null != loop ? loop.equals(o.loop) : null == o.loop)) { 062 throw new ClassCastException(); 063 } 064 final long d = number - o.number; 065 return d < 0L ? -1 : d == 0L ? 0 : 1; 066 } 067 }