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 java.beans.ConstructorProperties; |
20 | |
21 | import com.google.common.annotations.Beta; |
22 | import com.google.common.base.Objects; |
23 | import com.google.common.base.Objects.ToStringHelper; |
24 | |
25 | /** |
26 | * Summary information of e-mail settings and limits for a GleSYS account |
27 | * |
28 | * @author Adam Lowe |
29 | * @see <a href="https://customer.glesys.com/api.php?a=doc#email_overview" /> |
30 | */ |
31 | //TODO: find a better name for this class |
32 | @Beta |
33 | public class EmailOverviewSummary { |
34 | |
35 | public static Builder<?> builder() { |
36 | return new ConcreteBuilder(); |
37 | } |
38 | |
39 | public Builder<?> toBuilder() { |
40 | return new ConcreteBuilder().fromEmailOverviewSummary(this); |
41 | } |
42 | |
43 | public abstract static class Builder<T extends Builder<T>> { |
44 | protected abstract T self(); |
45 | |
46 | protected int accounts; |
47 | protected int maxAccounts; |
48 | protected int aliases; |
49 | protected int maxAliases; |
50 | |
51 | /** |
52 | * @see EmailOverviewSummary#getAccounts() |
53 | */ |
54 | public T accounts(int accounts) { |
55 | this.accounts = accounts; |
56 | return self(); |
57 | } |
58 | |
59 | /** |
60 | * @see EmailOverviewSummary#getMaxAccounts() |
61 | */ |
62 | public T maxAccounts(int maxAccounts) { |
63 | this.maxAccounts = maxAccounts; |
64 | return self(); |
65 | } |
66 | |
67 | /** |
68 | * @see EmailOverviewSummary#getAliases() |
69 | */ |
70 | public T aliases(int aliases) { |
71 | this.aliases = aliases; |
72 | return self(); |
73 | } |
74 | |
75 | /** |
76 | * @see EmailOverviewSummary#getMaxAliases() |
77 | */ |
78 | public T maxAliases(int maxAliases) { |
79 | this.maxAliases = maxAliases; |
80 | return self(); |
81 | } |
82 | |
83 | public EmailOverviewSummary build() { |
84 | return new EmailOverviewSummary(accounts, maxAccounts, aliases, maxAliases); |
85 | } |
86 | |
87 | public T fromEmailOverviewSummary(EmailOverviewSummary in) { |
88 | return this.accounts(in.getAccounts()) |
89 | .maxAccounts(in.getMaxAccounts()) |
90 | .aliases(in.getAliases()) |
91 | .maxAliases(in.getMaxAliases()); |
92 | } |
93 | } |
94 | |
95 | private static class ConcreteBuilder extends Builder<ConcreteBuilder> { |
96 | @Override |
97 | protected ConcreteBuilder self() { |
98 | return this; |
99 | } |
100 | } |
101 | |
102 | private final int accounts; |
103 | private final int maxAccounts; |
104 | private final int aliases; |
105 | private final int maxAliases; |
106 | |
107 | @ConstructorProperties({ |
108 | "accounts", "maxaccounts", "aliases", "maxaliases" |
109 | }) |
110 | protected EmailOverviewSummary(int accounts, int maxAccounts, int aliases, int maxAliases) { |
111 | this.accounts = accounts; |
112 | this.maxAccounts = maxAccounts; |
113 | this.aliases = aliases; |
114 | this.maxAliases = maxAliases; |
115 | } |
116 | |
117 | /** |
118 | * @return the number of e-mail accounts |
119 | */ |
120 | public int getAccounts() { |
121 | return this.accounts; |
122 | } |
123 | |
124 | /** |
125 | * @return the maximum number of e-mail accounts |
126 | */ |
127 | public int getMaxAccounts() { |
128 | return this.maxAccounts; |
129 | } |
130 | |
131 | /** |
132 | * @return the number of e-mail aliases |
133 | */ |
134 | public int getAliases() { |
135 | return this.aliases; |
136 | } |
137 | |
138 | /** |
139 | * @return the maximum number of e-mail aliases |
140 | */ |
141 | public int getMaxAliases() { |
142 | return this.maxAliases; |
143 | } |
144 | |
145 | @Override |
146 | public int hashCode() { |
147 | return Objects.hashCode(accounts, maxAccounts, aliases, maxAliases); |
148 | } |
149 | |
150 | @Override |
151 | public boolean equals(Object obj) { |
152 | if (this == obj) return true; |
153 | if (obj == null || getClass() != obj.getClass()) return false; |
154 | EmailOverviewSummary that = EmailOverviewSummary.class.cast(obj); |
155 | return Objects.equal(this.accounts, that.accounts) |
156 | && Objects.equal(this.maxAccounts, that.maxAccounts) |
157 | && Objects.equal(this.aliases, that.aliases) |
158 | && Objects.equal(this.maxAliases, that.maxAliases); |
159 | } |
160 | |
161 | protected ToStringHelper string() { |
162 | return Objects.toStringHelper("") |
163 | .add("accounts", accounts).add("maxAccounts", maxAccounts).add("aliases", aliases).add("maxAliases", maxAliases); |
164 | } |
165 | |
166 | @Override |
167 | public String toString() { |
168 | return string().toString(); |
169 | } |
170 | |
171 | } |