EMMA Coverage Report (generated Mon Oct 17 05:41:20 EDT 2011)
[all classes][org.jclouds.ec2.domain]

COVERAGE SUMMARY FOR SOURCE FILE [KeyPair.java]

nameclass, %method, %block, %line, %
KeyPair.java100% (2/2)67%  (14/21)64%  (219/341)68%  (49.4/73)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class KeyPair100% (1/1)54%  (7/13)61%  (165/271)61%  (35.4/58)
compareTo (KeyPair): int 0%   (0/1)0%   (0/11)0%   (0/1)
getKeyFingerprint (): String 0%   (0/1)0%   (0/3)0%   (0/1)
getKeyName (): String 0%   (0/1)0%   (0/3)0%   (0/1)
getRegion (): String 0%   (0/1)0%   (0/3)0%   (0/1)
toBuilder (): KeyPair$Builder 0%   (0/1)0%   (0/3)0%   (0/1)
toString (): String 0%   (0/1)0%   (0/36)0%   (0/1)
equals (Object): boolean 100% (1/1)65%  (66/101)52%  (17/33)
hashCode (): int 100% (1/1)83%  (59/71)92%  (7.4/8)
KeyPair (String, String, String, String, String): void 100% (1/1)100% (27/27)100% (7/7)
builder (): KeyPair$Builder 100% (1/1)100% (4/4)100% (1/1)
getFingerprint (): String 100% (1/1)100% (3/3)100% (1/1)
getKeyMaterial (): String 100% (1/1)100% (3/3)100% (1/1)
getSha1OfPrivateKey (): String 100% (1/1)100% (3/3)100% (1/1)
     
class KeyPair$Builder100% (1/1)88%  (7/8)77%  (54/70)93%  (14/15)
fromKeyPair (KeyPair): KeyPair$Builder 0%   (0/1)0%   (0/16)0%   (0/1)
KeyPair$Builder (): void 100% (1/1)100% (3/3)100% (1/1)
build (): KeyPair 100% (1/1)100% (26/26)100% (3/3)
fingerprint (String): KeyPair$Builder 100% (1/1)100% (5/5)100% (2/2)
keyMaterial (String): KeyPair$Builder 100% (1/1)100% (5/5)100% (2/2)
keyName (String): KeyPair$Builder 100% (1/1)100% (5/5)100% (2/2)
region (String): KeyPair$Builder 100% (1/1)100% (5/5)100% (2/2)
sha1OfPrivateKey (String): KeyPair$Builder 100% (1/1)100% (5/5)100% (2/2)

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 */
19package org.jclouds.ec2.domain;
20 
21import static com.google.common.base.Preconditions.checkNotNull;
22 
23import org.jclouds.crypto.SshKeys;
24import org.jclouds.javax.annotation.Nullable;
25 
26/**
27 * 
28 * @see <a href=
29 *      "http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-CreateKeyPair.html"
30 *      />
31 * @author Adrian Cole
32 */
33public class KeyPair implements Comparable<KeyPair> {
34   @Override
35   public String toString() {
36      return "[region=" + region + ", keyName=" + keyName + ", fingerprint=" + fingerprint + ", sha1OfPrivateKey="
37               + sha1OfPrivateKey + ", keyMaterial?=" + (keyMaterial != null) + "]";
38   }
39 
40   public static Builder builder() {
41      return new Builder();
42   }
43 
44   public static class Builder {
45      private String region;
46      private String keyName;
47      private String fingerprint;
48      private String sha1OfPrivateKey;
49      private String keyMaterial;
50 
51      public Builder region(String region) {
52         this.region = region;
53         return this;
54      }
55 
56      public Builder keyName(String keyName) {
57         this.keyName = keyName;
58         return this;
59      }
60 
61      public Builder sha1OfPrivateKey(String sha1OfPrivateKey) {
62         this.sha1OfPrivateKey = sha1OfPrivateKey;
63         return this;
64      }
65 
66      public Builder keyMaterial(String keyMaterial) {
67         this.keyMaterial = keyMaterial;
68         return this;
69      }
70 
71      public Builder fingerprint(String fingerprint) {
72         this.fingerprint = fingerprint;
73         return this;
74      }
75 
76      public KeyPair build() {
77         if (fingerprint == null && keyMaterial != null)
78            fingerprint(SshKeys.fingerprintPrivateKey(keyMaterial));
79         return new KeyPair(region, keyName, sha1OfPrivateKey, keyMaterial, fingerprint);
80      }
81 
82      public static Builder fromKeyPair(KeyPair in) {
83         return new Builder().region(in.getRegion()).keyName(in.getKeyName()).sha1OfPrivateKey(in.getKeyFingerprint())
84                  .keyMaterial(in.getKeyMaterial());
85      }
86   }
87 
88   private final String region;
89   private final String keyName;
90   private final String sha1OfPrivateKey;
91   @Nullable
92   private final String keyMaterial;
93   @Nullable
94   private final String fingerprint;
95 
96   public KeyPair(String region, String keyName, String sha1OfPrivateKey, @Nullable String keyMaterial,
97            @Nullable String fingerprint) {
98      this.region = checkNotNull(region, "region");
99      this.keyName = checkNotNull(keyName, "keyName");
100      this.sha1OfPrivateKey = checkNotNull(sha1OfPrivateKey, "sha1OfPrivateKey");
101      this.keyMaterial = keyMaterial;// nullable on list
102      this.fingerprint = fingerprint;// nullable on list
103   }
104 
105   /**
106    * Key pairs (to connect to instances) are Region-specific.
107    */
108   public String getRegion() {
109      return region;
110   }
111 
112   /**
113    * {@inheritDoc}
114    */
115   public int compareTo(KeyPair o) {
116      return (this == o) ? 0 : getKeyName().compareTo(o.getKeyName());
117   }
118 
119   /**
120    * @see #getSha1OfPrivateKey
121    */
122   @Deprecated
123   public String getKeyFingerprint() {
124      return sha1OfPrivateKey;
125   }
126 
127   /**
128    * A SHA-1 digest of the DER encoded private key.
129    * 
130    * @see SshKeys#sha1
131    */
132   public String getSha1OfPrivateKey() {
133      return sha1OfPrivateKey;
134   }
135 
136   /**
137    * fingerprint per the following <a
138    * href="http://tools.ietf.org/html/draft-friedl-secsh-fingerprint-00" >spec</a>
139    * 
140    * @see SshKeys#fingerprint
141    */
142   public String getFingerprint() {
143      return fingerprint;
144   }
145 
146   /**
147    * An unencrypted PEM encoded RSA private key.
148    */
149   public String getKeyMaterial() {
150      return keyMaterial;
151   }
152 
153   /**
154    * The key pair name provided in the original request.
155    */
156   public String getKeyName() {
157      return keyName;
158   }
159 
160   @Override
161   public int hashCode() {
162      final int prime = 31;
163      int result = 1;
164      result = prime * result + ((fingerprint == null) ? 0 : fingerprint.hashCode());
165      result = prime * result + ((keyMaterial == null) ? 0 : keyMaterial.hashCode());
166      result = prime * result + ((keyName == null) ? 0 : keyName.hashCode());
167      result = prime * result + ((region == null) ? 0 : region.hashCode());
168      result = prime * result + ((sha1OfPrivateKey == null) ? 0 : sha1OfPrivateKey.hashCode());
169      return result;
170   }
171 
172   @Override
173   public boolean equals(Object obj) {
174      if (this == obj)
175         return true;
176      if (obj == null)
177         return false;
178      if (getClass() != obj.getClass())
179         return false;
180      KeyPair other = (KeyPair) obj;
181      if (fingerprint == null) {
182         if (other.fingerprint != null)
183            return false;
184      } else if (!fingerprint.equals(other.fingerprint))
185         return false;
186      if (keyMaterial == null) {
187         if (other.keyMaterial != null)
188            return false;
189      } else if (!keyMaterial.equals(other.keyMaterial))
190         return false;
191      if (keyName == null) {
192         if (other.keyName != null)
193            return false;
194      } else if (!keyName.equals(other.keyName))
195         return false;
196      if (region == null) {
197         if (other.region != null)
198            return false;
199      } else if (!region.equals(other.region))
200         return false;
201      if (sha1OfPrivateKey == null) {
202         if (other.sha1OfPrivateKey != null)
203            return false;
204      } else if (!sha1OfPrivateKey.equals(other.sha1OfPrivateKey))
205         return false;
206      return true;
207   }
208 
209   public Builder toBuilder() {
210      return Builder.fromKeyPair(this);
211   }
212}

[all classes][org.jclouds.ec2.domain]
EMMA 2.0.5312 (C) Vladimir Roubtsov