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  /**
24   * 
25   * @author Adrian Cole
26   */
27  public abstract class Device {
28     public static abstract class Builder {
29        protected String uuid;
30        protected MediaType mediaType = MediaType.DISK;
31  
32        public Builder mediaType(MediaType mediaType) {
33           this.mediaType = mediaType;
34           return this;
35        }
36  
37        public Builder uuid(String uuid) {
38           this.uuid = uuid;
39           return this;
40        }
41  
42        public abstract Device build();
43     }
44  
45     protected final String driveUuid;
46     protected final MediaType mediaType;
47  
48     public Device(String driveUuid, MediaType mediaType) {
49        this.driveUuid = checkNotNull(driveUuid, "driveUuid");
50        this.mediaType = checkNotNull(mediaType, "mediaType");
51     }
52  
53     /**
54      * id generated based on the device bus, unit, and/or index numbers;
55      */
56     public abstract String getId();
57  
58     /**
59      * 
60      * @return Drive UUID to connect as specified device.
61      */
62     public String getDriveUuid() {
63        return driveUuid;
64     }
65  
66     /**
67      * 
68      * @return set to 'cdrom' to simulate a cdrom, set to 'disk' or leave unset to simulate a hard
69      *         disk.
70      */
71     public MediaType getMediaType() {
72        return mediaType;
73     }
74  
75     @Override
76     public int hashCode() {
77        final int prime = 31;
78        int result = 1;
79        result = prime * result + ((driveUuid == null) ? 0 : driveUuid.hashCode());
80        result = prime * result + ((mediaType == null) ? 0 : mediaType.hashCode());
81        return result;
82     }
83  
84     @Override
85     public boolean equals(Object obj) {
86        if (this == obj)
87           return true;
88        if (obj == null)
89           return false;
90        if (getClass() != obj.getClass())
91           return false;
92        Device other = (Device) obj;
93        if (driveUuid == null) {
94           if (other.driveUuid != null)
95              return false;
96        } else if (!driveUuid.equals(other.driveUuid))
97           return false;
98        if (mediaType != other.mediaType)
99           return false;
100       return true;
101    }
102 
103    @Override
104    public String toString() {
105       return "[driveUuid=" + driveUuid + ", mediaType=" + mediaType + "]";
106    }
107 }