01: /*******************************************************************************
02: * Copyright (c) 2000, 2005 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.jdi.internal.request;
11:
12: import java.io.DataInputStream;
13: import java.io.DataOutputStream;
14: import java.io.IOException;
15:
16: import org.eclipse.jdi.internal.MirrorImpl;
17:
18: public class RequestID {
19: /** Null request ID, returned by Virtual Machine in events that were not requested. */
20: private static final int NULL_REQUEST_ID = 0;
21: public static final RequestID nullID = new RequestID(
22: NULL_REQUEST_ID);
23:
24: /** Integer representation of request ID.*/
25: private int fRequestID;
26:
27: /**
28: * Creates new request ID.
29: */
30: private RequestID(int ID) {
31: fRequestID = ID;
32: }
33:
34: /**
35: * @return Returns whether the request ID is a NULL ID, which means that there is no corresponding request.
36: */
37: public boolean isNull() {
38: return fRequestID == NULL_REQUEST_ID;
39: }
40:
41: /**
42: * @return Returns true if two RequestIDs are the same.
43: * @see java.lang.Object#equals(Object)
44: */
45: public boolean equals(Object object) {
46: return object != null
47: && object.getClass().equals(this .getClass())
48: && fRequestID == ((RequestID) object).fRequestID;
49: }
50:
51: /**
52: * @return Returns a has code for this object.
53: * @see java.lang.Object#hashCode
54: */
55: public int hashCode() {
56: return fRequestID;
57: }
58:
59: /**
60: * @return Returns string representation.
61: */
62: public String toString() {
63: return new Long(fRequestID).toString();
64: }
65:
66: /**
67: * Writes IDto stream.
68: */
69: public void write(MirrorImpl target, DataOutputStream out)
70: throws IOException {
71: target.writeInt(fRequestID, "request ID", out); //$NON-NLS-1$
72: }
73:
74: /**
75: * @return Returns a new request ID read from stream.
76: */
77: public static RequestID read(MirrorImpl target, DataInputStream in)
78: throws IOException {
79: int result = target.readInt("request ID", in); //$NON-NLS-1$
80: return new RequestID(result);
81: }
82: }
|