| 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.softlayer.domain; |
| 20 | |
| 21 | import static com.google.common.base.Preconditions.checkNotNull; |
| 22 | import static com.google.common.base.Strings.emptyToNull; |
| 23 | |
| 24 | /** |
| 25 | * |
| 26 | * Contains a password for a specific software component instance |
| 27 | * |
| 28 | * @author Jason King |
| 29 | * @see <a href= "http://sldn.softlayer.com/reference/datatypes/SoftLayer_Software_Component_Password" |
| 30 | * /> |
| 31 | */ |
| 32 | public class Password implements Comparable<Password> { |
| 33 | public static Builder builder() { |
| 34 | return new Builder(); |
| 35 | } |
| 36 | |
| 37 | public static class Builder { |
| 38 | private int id = -1; |
| 39 | private String username; |
| 40 | private String password; |
| 41 | |
| 42 | public Builder id(int id) { |
| 43 | this.id = id; |
| 44 | return this; |
| 45 | } |
| 46 | |
| 47 | public Builder username(String username) { |
| 48 | this.username = username; |
| 49 | return this; |
| 50 | } |
| 51 | |
| 52 | public Builder password(String password) { |
| 53 | this.password = password; |
| 54 | return this; |
| 55 | } |
| 56 | |
| 57 | public Password build() { |
| 58 | return new Password(id, username, password); |
| 59 | } |
| 60 | |
| 61 | public static Builder fromPassword(Password in) { |
| 62 | return Password.builder().id(in.getId()) |
| 63 | .username(in.getUsername()) |
| 64 | .password(in.getPassword()); |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | private int id = -1; |
| 69 | private String username; |
| 70 | private String password; |
| 71 | |
| 72 | // for deserializer |
| 73 | Password() { |
| 74 | |
| 75 | } |
| 76 | |
| 77 | public Password(int id, String username, String password) { |
| 78 | this.id = id; |
| 79 | this.username = checkNotNull(emptyToNull(username),"username cannot be null or empty:"+username); |
| 80 | this.password = password; |
| 81 | } |
| 82 | |
| 83 | @Override |
| 84 | public int compareTo(Password arg0) { |
| 85 | return new Integer(id).compareTo(arg0.getId()); |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * @return An id number for this specific username/password pair. |
| 90 | */ |
| 91 | public int getId() { |
| 92 | return id; |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * @return The username part of the username/password pair. |
| 97 | */ |
| 98 | public String getUsername() { |
| 99 | return username; |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * @return The password part of the username/password pair. |
| 104 | */ |
| 105 | public String getPassword() { |
| 106 | return password; |
| 107 | } |
| 108 | |
| 109 | public Builder toBuilder() { |
| 110 | return Builder.fromPassword(this); |
| 111 | } |
| 112 | |
| 113 | @Override |
| 114 | public int hashCode() { |
| 115 | final int prime = 31; |
| 116 | int result = 1; |
| 117 | result = prime * result + (id ^ (id >>> 32)); |
| 118 | return result; |
| 119 | } |
| 120 | |
| 121 | @Override |
| 122 | public boolean equals(Object obj) { |
| 123 | if (this == obj) |
| 124 | return true; |
| 125 | if (obj == null) |
| 126 | return false; |
| 127 | if (getClass() != obj.getClass()) |
| 128 | return false; |
| 129 | Password other = (Password) obj; |
| 130 | if (id != other.id) |
| 131 | return false; |
| 132 | return true; |
| 133 | } |
| 134 | |
| 135 | @Override |
| 136 | public String toString() { |
| 137 | return "Password [id=" + id + ", username=" + username + ", password=**********]"; |
| 138 | } |
| 139 | |
| 140 | |
| 141 | } |