View Javadoc

1   /*
2    * Copyright (c) 2005 The University of Reading
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions
7    * are met:
8    * 1. Redistributions of source code must retain the above copyright
9    *    notice, this list of conditions and the following disclaimer.
10   * 2. Redistributions in binary form must reproduce the above copyright
11   *    notice, this list of conditions and the following disclaimer in the
12   *    documentation and/or other materials provided with the distribution.
13   * 3. Neither the name of the University of Reading, nor the names of the
14   *    authors or contributors may be used to endorse or promote products
15   *    derived from this software without specific prior written permission.
16   * 
17   * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18   * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20   * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21   * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22   * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23   * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24   * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25   * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26   * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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;        // The type of the file as an unsigned byte
58      private long version;    // The version of the file as an unsigned 4-byte integer
59      private ULong path;      // The path of the file as an unsigned 8-byte integer
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         // TODO: friendlier representation of type
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 }