| 1 | /* |
| 2 | * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | * contributor license agreements. See the NOTICE file distributed with |
| 4 | * this work for additional information regarding copyright ownership. |
| 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | * (the "License"); you may not use this file except in compliance with |
| 7 | * the License. You may obtain a copy of the License at |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | package org.jclouds.glesys.domain; |
| 18 | |
| 19 | import static com.google.common.base.Preconditions.checkNotNull; |
| 20 | |
| 21 | import java.beans.ConstructorProperties; |
| 22 | import java.util.List; |
| 23 | |
| 24 | import com.google.common.base.Objects; |
| 25 | import com.google.common.base.Objects.ToStringHelper; |
| 26 | import com.google.common.collect.ImmutableList; |
| 27 | |
| 28 | /** |
| 29 | * The allowed arguments for archive manipulation, such as archivesize |
| 30 | * |
| 31 | * @author Adam Lowe |
| 32 | * @see <a href= "https://customer.glesys.com/api.php?a=doc#archive_allowedarguments" /> |
| 33 | */ |
| 34 | public class ArchiveAllowedArguments { |
| 35 | |
| 36 | public static Builder<?> builder() { |
| 37 | return new ConcreteBuilder(); |
| 38 | } |
| 39 | |
| 40 | public Builder<?> toBuilder() { |
| 41 | return new ConcreteBuilder().fromArchiveAllowedArguments(this); |
| 42 | } |
| 43 | |
| 44 | public abstract static class Builder<T extends Builder<T>> { |
| 45 | protected abstract T self(); |
| 46 | |
| 47 | protected List<Integer> archiveSizes = ImmutableList.of(); |
| 48 | |
| 49 | /** |
| 50 | * @see ArchiveAllowedArguments#getSizes() |
| 51 | */ |
| 52 | public T archiveSizes(List<Integer> archiveSizes) { |
| 53 | this.archiveSizes = ImmutableList.copyOf(checkNotNull(archiveSizes, "archiveSizes")); |
| 54 | return self(); |
| 55 | } |
| 56 | |
| 57 | public T archiveSizes(Integer... in) { |
| 58 | return archiveSizes(ImmutableList.copyOf(in)); |
| 59 | } |
| 60 | |
| 61 | public ArchiveAllowedArguments build() { |
| 62 | return new ArchiveAllowedArguments(archiveSizes); |
| 63 | } |
| 64 | |
| 65 | public T fromArchiveAllowedArguments(ArchiveAllowedArguments in) { |
| 66 | return this.archiveSizes(in.getSizes()); |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | private static class ConcreteBuilder extends Builder<ConcreteBuilder> { |
| 71 | @Override |
| 72 | protected ConcreteBuilder self() { |
| 73 | return this; |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | private final List<Integer> archiveSizes; |
| 78 | |
| 79 | @ConstructorProperties({ |
| 80 | "archivesize" |
| 81 | }) |
| 82 | protected ArchiveAllowedArguments(List<Integer> archiveSizes) { |
| 83 | this.archiveSizes = ImmutableList.copyOf(checkNotNull(archiveSizes, "archiveSizes")); |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * @return the list of allowed archive sizes, in GB |
| 88 | */ |
| 89 | public List<Integer> getSizes() { |
| 90 | return this.archiveSizes; |
| 91 | } |
| 92 | |
| 93 | @Override |
| 94 | public int hashCode() { |
| 95 | return Objects.hashCode(archiveSizes); |
| 96 | } |
| 97 | |
| 98 | @Override |
| 99 | public boolean equals(Object obj) { |
| 100 | if (this == obj) return true; |
| 101 | if (obj == null || getClass() != obj.getClass()) return false; |
| 102 | ArchiveAllowedArguments that = ArchiveAllowedArguments.class.cast(obj); |
| 103 | return Objects.equal(this.archiveSizes, that.archiveSizes); |
| 104 | } |
| 105 | |
| 106 | protected ToStringHelper string() { |
| 107 | return Objects.toStringHelper("") |
| 108 | .add("archiveSizes", archiveSizes); |
| 109 | } |
| 110 | |
| 111 | @Override |
| 112 | public String toString() { |
| 113 | return string().toString(); |
| 114 | } |
| 115 | |
| 116 | } |