| 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 com.google.common.collect.ImmutableSet; |
| 22 | import com.google.common.collect.Sets; |
| 23 | |
| 24 | import java.util.Set; |
| 25 | |
| 26 | import static com.google.common.base.Preconditions.checkNotNull; |
| 27 | |
| 28 | /** |
| 29 | * Extends the SoftLayer_Software_Component data type to include operating system specific properties. |
| 30 | * |
| 31 | * @author Jason King |
| 32 | * @see <a href= |
| 33 | * "http://sldn.softlayer.com/reference/datatypes/SoftLayer_Software_Component_OperatingSystem" |
| 34 | * /> |
| 35 | */ |
| 36 | public class OperatingSystem implements Comparable<OperatingSystem> { |
| 37 | |
| 38 | // There are other properties |
| 39 | |
| 40 | public static Builder builder() { |
| 41 | return new Builder(); |
| 42 | } |
| 43 | |
| 44 | public static class Builder { |
| 45 | private int id = -1; |
| 46 | private Set<Password> passwords = Sets.newLinkedHashSet(); |
| 47 | |
| 48 | public Builder id(int id) { |
| 49 | this.id = id; |
| 50 | return this; |
| 51 | } |
| 52 | |
| 53 | public Builder password(Password password) { |
| 54 | this.passwords.add(checkNotNull(password, "password")); |
| 55 | return this; |
| 56 | } |
| 57 | |
| 58 | public Builder passwords(Iterable<Password> passwords) { |
| 59 | this.passwords = ImmutableSet.<Password> copyOf(checkNotNull(passwords, "passwords")); |
| 60 | return this; |
| 61 | } |
| 62 | |
| 63 | public OperatingSystem build() { |
| 64 | return new OperatingSystem(id, passwords); |
| 65 | } |
| 66 | |
| 67 | public static Builder fromOperatingSystem(OperatingSystem in) { |
| 68 | return OperatingSystem.builder() |
| 69 | .id(in.getId()) |
| 70 | .passwords(in.getPasswords()); |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | private int id = -1; |
| 75 | private Set<Password> passwords = Sets.newLinkedHashSet(); |
| 76 | |
| 77 | // for deserializer |
| 78 | OperatingSystem() { |
| 79 | |
| 80 | } |
| 81 | |
| 82 | public OperatingSystem(int id,Iterable<Password> passwords) { |
| 83 | this.id = id; |
| 84 | this.passwords = ImmutableSet.<Password> copyOf(checkNotNull(passwords, "passwords")); |
| 85 | } |
| 86 | |
| 87 | @Override |
| 88 | public int compareTo(OperatingSystem arg0) { |
| 89 | return new Integer(id).compareTo(arg0.getId()); |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * @return An ID number identifying this Software Component (Software Installation) |
| 94 | */ |
| 95 | public int getId() { |
| 96 | return id; |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * |
| 101 | * @return Username/Password pairs used for access to this Software Installation. |
| 102 | */ |
| 103 | public Set<Password> getPasswords() { |
| 104 | return passwords; |
| 105 | } |
| 106 | |
| 107 | public Builder toBuilder() { |
| 108 | return Builder.fromOperatingSystem(this); |
| 109 | } |
| 110 | |
| 111 | @Override |
| 112 | public int hashCode() { |
| 113 | final int prime = 31; |
| 114 | int result = 1; |
| 115 | result = prime * result + (id ^ (id >>> 32)); |
| 116 | return result; |
| 117 | } |
| 118 | |
| 119 | @Override |
| 120 | public boolean equals(Object obj) { |
| 121 | if (this == obj) |
| 122 | return true; |
| 123 | if (obj == null) |
| 124 | return false; |
| 125 | if (getClass() != obj.getClass()) |
| 126 | return false; |
| 127 | OperatingSystem other = (OperatingSystem) obj; |
| 128 | if (id != other.id) |
| 129 | return false; |
| 130 | return true; |
| 131 | } |
| 132 | |
| 133 | @Override |
| 134 | public String toString() { |
| 135 | return "[id=" + id + ", passwords=" + passwords + "]"; |
| 136 | } |
| 137 | } |