package org.openlcb; // For annotations import net.jcip.annotations.*; import edu.umd.cs.findbugs.annotations.*; /** * Common EventID implementation. *

* EventID objects are immutable once created. * * @author Bob Jacobsen Copyright 2009 * @version $Revision: 2275 $ */ @Immutable @ThreadSafe public class EventID { static final int BYTECOUNT = 8; @CheckReturnValue public EventID(@NonNull NodeID node, int b7, int b8) { this.contents = new byte[BYTECOUNT]; System.arraycopy(node.contents, 0, this.contents, 0, BYTECOUNT-2); this.contents[6] = (byte)b7; this.contents[7] = (byte)b8; } @CheckReturnValue public EventID(@NonNull byte[] contents) { if (contents == null) throw new java.lang.IllegalArgumentException("null argument invalid"); if (contents.length != BYTECOUNT) throw new java.lang.IllegalArgumentException("Wrong EventID length: "+contents.length); this.contents = new byte[BYTECOUNT]; System.arraycopy(contents, 0, this.contents, 0, BYTECOUNT); } @CheckReturnValue public EventID(@NonNull String value) { if (value == null) throw new java.lang.IllegalArgumentException("null argument invalid"); byte[] data = org.openlcb.Utilities.bytesFromHexString(value); if (data.length != BYTECOUNT) throw new java.lang.IllegalArgumentException("Wrong EventID length: "+data.length); this.contents = new byte[BYTECOUNT]; System.arraycopy(data, 0, this.contents, 0, BYTECOUNT); } byte[] contents; @CheckReturnValue @NonNull public byte[] getContents() { // copy to ensure immutable byte[] retval = new byte[BYTECOUNT]; System.arraycopy(contents, 0, retval, 0, BYTECOUNT); return retval; } @CheckReturnValue @Override public boolean equals(@NonNull Object o){ // try to cast, else not equal try { EventID other = (EventID) o; for (int i = 0; i