View Javadoc

1   /**
2    *
3    * Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
4    *
5    * ====================================================================
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   * ====================================================================
18   */
19  package org.jclouds.cloudsigma.domain;
20  
21  import static com.google.common.base.Preconditions.checkNotNull;
22  
23  import java.util.Set;
24  
25  import javax.annotation.Nullable;
26  
27  import com.google.common.collect.ImmutableSet;
28  
29  /**
30   * 
31   * @author Adrian Cole
32   */
33  public class Drive extends Item {
34     public static class Builder extends Item.Builder {
35        protected long size;
36        protected ClaimType claimType = ClaimType.EXCLUSIVE;
37        protected Set<String> readers = ImmutableSet.of();
38  
39        public Builder claimType(ClaimType claimType) {
40           this.claimType = claimType;
41           return this;
42        }
43  
44        public Builder readers(Iterable<String> readers) {
45           this.readers = ImmutableSet.copyOf(checkNotNull(readers, "readers"));
46           return this;
47        }
48  
49        public Builder size(long size) {
50           this.size = size;
51           return this;
52        }
53  
54        /**
55         * {@inheritDoc}
56         */
57        @Override
58        public Builder uuid(String uuid) {
59           return Builder.class.cast(super.uuid(uuid));
60        }
61  
62        /**
63         * {@inheritDoc}
64         */
65        @Override
66        public Builder name(String name) {
67           return Builder.class.cast(super.name(name));
68        }
69  
70        /**
71         * {@inheritDoc}
72         */
73        @Override
74        public Builder use(Iterable<String> use) {
75           return Builder.class.cast(super.use(use));
76        }
77  
78        public Drive build() {
79           return new Drive(uuid, name, size, claimType, readers, use);
80        }
81  
82        @Override
83        public int hashCode() {
84           final int prime = 31;
85           int result = super.hashCode();
86           result = prime * result + ((claimType == null) ? 0 : claimType.hashCode());
87           result = prime * result + ((readers == null) ? 0 : readers.hashCode());
88           result = prime * result + (int) (size ^ (size >>> 32));
89           return result;
90        }
91  
92        @Override
93        public boolean equals(Object obj) {
94           if (this == obj)
95              return true;
96           if (!super.equals(obj))
97              return false;
98           if (getClass() != obj.getClass())
99              return false;
100          Builder other = (Builder) obj;
101          if (claimType != other.claimType)
102             return false;
103          if (readers == null) {
104             if (other.readers != null)
105                return false;
106          } else if (!readers.equals(other.readers))
107             return false;
108          if (size != other.size)
109             return false;
110          return true;
111       }
112    }
113 
114    protected final long size;
115    protected final ClaimType claimType;
116    protected final Set<String> readers;
117 
118    public Drive(@Nullable String uuid, String name, long size, @Nullable ClaimType claimType, Iterable<String> readers,
119          Iterable<String> use) {
120       super(uuid, name, use);
121       this.size = size;
122       this.claimType = checkNotNull(claimType, "set claimType to exclusive, not null");
123       this.readers = ImmutableSet.copyOf(checkNotNull(readers, "readers"));
124    }
125 
126    /**
127     * 
128     * @return either 'exclusive' (the default) or 'shared' to allow multiple servers to access a
129     *         drive simultaneously
130     */
131    @Nullable
132    public ClaimType getClaimType() {
133       return claimType;
134    }
135 
136    /**
137     * 
138     * @return list of users allowed to read from a drive or 'ffffffff-ffff-ffff-ffff-ffffffffffff'
139     *         for all users
140     */
141    public Set<String> getReaders() {
142       return readers;
143    }
144 
145    /**
146     * 
147     * @return size of drive in bytes
148     */
149    public long getSize() {
150       return size;
151    }
152 
153    @Override
154    public int hashCode() {
155       final int prime = 31;
156       int result = 1;
157       result = prime * result + ((claimType == null) ? 0 : claimType.hashCode());
158       result = prime * result + ((name == null) ? 0 : name.hashCode());
159       result = prime * result + ((readers == null) ? 0 : readers.hashCode());
160       result = prime * result + (int) (size ^ (size >>> 32));
161       result = prime * result + ((use == null) ? 0 : use.hashCode());
162       return result;
163    }
164 
165    @Override
166    public boolean equals(Object obj) {
167       if (this == obj)
168          return true;
169       if (obj == null)
170          return false;
171       if (getClass() != obj.getClass())
172          return false;
173       Drive other = (Drive) obj;
174       if (claimType != other.claimType)
175          return false;
176       if (name == null) {
177          if (other.name != null)
178             return false;
179       } else if (!name.equals(other.name))
180          return false;
181       if (readers == null) {
182          if (other.readers != null)
183             return false;
184       } else if (!readers.equals(other.readers))
185          return false;
186       if (size != other.size)
187          return false;
188       if (use == null) {
189          if (other.use != null)
190             return false;
191       } else if (!use.equals(other.use))
192          return false;
193       return true;
194    }
195 
196    @Override
197    public String toString() {
198       return "[uuid=" + uuid + ", name=" + name + ", use=" + use + ", size=" + size + ", claimType=" + claimType
199             + ", readers=" + readers + "]";
200    }
201 
202 }