View Javadoc

1   /**
2    * Licensed to jclouds, Inc. (jclouds) under one or more
3    * contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  jclouds licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  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,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.jclouds.trmk.vcloud_0_8.domain;
20  
21  import java.net.URI;
22  
23  import org.jclouds.javax.annotation.Nullable;
24  
25  /**
26   * an SSH keypair
27   * 
28   * @author Adrian Cole
29   */
30  public class KeyPair {
31     private final URI id;
32     private final String name;
33     private final boolean isDefault;
34     @Nullable
35     private final String privateKey;
36     private final String fingerPrint;
37  
38     public KeyPair(URI id, String name, boolean isDefault, @Nullable String privateKey, String fingerPrint) {
39        this.id = id;
40        this.name = name;
41        this.isDefault = isDefault;
42        this.privateKey = privateKey;
43        this.fingerPrint = fingerPrint;
44     }
45  
46     public URI getId() {
47        return id;
48     }
49  
50     public String getName() {
51        return name;
52     }
53  
54     public boolean isDefault() {
55        return isDefault;
56     }
57  
58     @Nullable
59     public String getPrivateKey() {
60        return privateKey;
61     }
62  
63     public String getFingerPrint() {
64        return fingerPrint;
65     }
66  
67     @Override
68     public int hashCode() {
69        final int prime = 31;
70        int result = 1;
71        result = prime * result + ((fingerPrint == null) ? 0 : fingerPrint.hashCode());
72        result = prime * result + ((id == null) ? 0 : id.hashCode());
73        result = prime * result + (isDefault ? 1231 : 1237);
74        result = prime * result + ((name == null) ? 0 : name.hashCode());
75        result = prime * result + ((privateKey == null) ? 0 : privateKey.hashCode());
76        return result;
77     }
78  
79     @Override
80     public boolean equals(Object obj) {
81        if (this == obj)
82           return true;
83        if (obj == null)
84           return false;
85        if (getClass() != obj.getClass())
86           return false;
87        KeyPair other = (KeyPair) obj;
88        if (fingerPrint == null) {
89           if (other.fingerPrint != null)
90              return false;
91        } else if (!fingerPrint.equals(other.fingerPrint))
92           return false;
93        if (id == null) {
94           if (other.id != null)
95              return false;
96        } else if (!id.equals(other.id))
97           return false;
98        if (isDefault != other.isDefault)
99           return false;
100       if (name == null) {
101          if (other.name != null)
102             return false;
103       } else if (!name.equals(other.name))
104          return false;
105       if (privateKey == null) {
106          if (other.privateKey != null)
107             return false;
108       } else if (!privateKey.equals(other.privateKey))
109          return false;
110       return true;
111    }
112 
113    @Override
114    public String toString() {
115       return "Key [fingerPrint=" + fingerPrint + ", id=" + id + ", isDefault=" + isDefault + ", name=" + name
116             + ", privateKey=" + (privateKey != null) + "]";
117    }
118 
119 }