1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 package uk.ac.rdg.resc.jstyx.types;
30
31 import java.math.BigInteger;
32 import uk.ac.rdg.resc.jstyx.StyxUtils;
33
34 /***
35 * A 13-byte type representing the server's view of a file
36 *
37 * @author Jon Blower
38 * $Revision: 604 $
39 * $Date: 2006-03-21 14:58:42 +0000 (Tue, 21 Mar 2006) $
40 * $Log$
41 * Revision 1.4 2006/03/21 14:58:42 jonblower
42 * Implemented clear-text password-based authentication and did some simple tests
43 *
44 * Revision 1.3 2005/07/08 12:18:50 jonblower
45 * Implemented equals() methods
46 *
47 * Revision 1.2 2005/02/24 07:46:05 jonblower
48 * Added toFriendlyString() for benefit of StyxMon
49 *
50 * Revision 1.1.1.1 2005/02/16 18:58:35 jonblower
51 * Initial import
52 *
53 */
54 public class Qid
55 {
56
57 private int type;
58 private long version;
59 private ULong path;
60
61 public Qid(int type, long version, ULong path)
62 {
63 this.type = type;
64 this.version = version;
65 this.path = path;
66 }
67
68 public Qid(int type, long version, long path)
69 {
70 this(type, version, new ULong(path));
71 }
72
73 public int getType()
74 {
75 return this.type;
76 }
77
78 public long getVersion()
79 {
80 return this.version;
81 }
82
83 public ULong getPath()
84 {
85 return this.path;
86 }
87
88 /***
89 * @return true if the file represented by this Qid is a directory
90 */
91 public boolean isDirectory()
92 {
93 return ((this.type << 24) & StyxUtils.DMDIR) == StyxUtils.DMDIR;
94 }
95
96 /***
97 * @return true if the file represented by this Qid is an authorization file
98 */
99 public boolean isAuth()
100 {
101 return ((this.type << 24) & StyxUtils.DMAUTH) == StyxUtils.DMAUTH;
102 }
103
104 /***
105 * @return string representation of this Qid
106 */
107 public String toString()
108 {
109 return this.type + ", " + this.version + ", " + this.path.asBigInteger();
110 }
111
112 /***
113 * @return human-readable representation of this Qid
114 */
115 public String toFriendlyString()
116 {
117
118 return "type: " + this.type + ", version: " + this.version +
119 ", pathcode: " + this.path;
120 }
121
122 /***
123 * @return true if the qids are identical
124 */
125 public boolean equals(Qid otherQid)
126 {
127 if (otherQid == null)
128 {
129 return false;
130 }
131 if (otherQid instanceof Qid)
132 {
133 Qid qid2 = (Qid)otherQid;
134 return (this.type == qid2.type &&
135 this.version == qid2.version &&
136 this.path.equals(qid2.path));
137 }
138 else
139 {
140 return false;
141 }
142 }
143
144 /***
145 * TODO: implement hashCode
146 */
147 }