KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdi > internal > request > RequestID


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdi.internal.request;
12
13
14 import java.io.DataInputStream JavaDoc;
15 import java.io.DataOutputStream JavaDoc;
16 import java.io.IOException JavaDoc;
17
18 import org.eclipse.jdi.internal.MirrorImpl;
19
20 public class RequestID {
21     /** Null request ID, returned by Virtual Machine in events that were not requested. */
22     private static final int NULL_REQUEST_ID = 0;
23     public static final RequestID nullID = new RequestID(NULL_REQUEST_ID);
24
25     /** Integer representation of request ID.*/
26     private int fRequestID;
27     
28     /**
29      * Creates new request ID.
30      */

31     private RequestID(int ID) {
32         fRequestID = ID;
33     }
34     
35     /**
36      * @return Returns whether the request ID is a NULL ID, which means that there is no corresponding request.
37      */

38     public boolean isNull() {
39         return fRequestID == NULL_REQUEST_ID;
40     }
41     
42     /**
43      * @return Returns true if two RequestIDs are the same.
44      * @see java.lang.Object#equals(Object)
45      */

46     public boolean equals(Object JavaDoc object) {
47         return object != null && object.getClass().equals(this.getClass()) && fRequestID == ((RequestID)object).fRequestID;
48     }
49     
50     /**
51      * @return Returns a has code for this object.
52      * @see java.lang.Object#hashCode
53      */

54     public int hashCode() {
55         return fRequestID;
56     }
57     
58     /**
59      * @return Returns string representation.
60      */

61     public String JavaDoc toString() {
62         return new Long JavaDoc(fRequestID).toString();
63     }
64
65     /**
66      * Writes IDto stream.
67      */

68     public void write(MirrorImpl target, DataOutputStream JavaDoc out) throws IOException JavaDoc {
69         target.writeInt(fRequestID, "request ID", out); //$NON-NLS-1$
70
}
71     
72     /**
73      * @return Returns a new request ID read from stream.
74      */

75     public static RequestID read(MirrorImpl target, DataInputStream JavaDoc in) throws IOException JavaDoc {
76         int result = target.readInt("request ID", in); //$NON-NLS-1$
77
return new RequestID(result);
78     }
79 }
80
Popular Tags