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 | |
23 | import com.google.common.annotations.Beta; |
24 | import com.google.common.base.Objects; |
25 | import com.google.common.base.Objects.ToStringHelper; |
26 | |
27 | /** |
28 | * Detailed information about e-mail settings for a single domain |
29 | * |
30 | * @author Adam Lowe |
31 | * @see <a href="https://customer.glesys.com/api.php?a=doc#email_overview" /> |
32 | */ |
33 | @Beta |
34 | public class EmailOverviewDomain { |
35 | |
36 | public static Builder<?> builder() { |
37 | return new ConcreteBuilder(); |
38 | } |
39 | |
40 | public Builder<?> toBuilder() { |
41 | return new ConcreteBuilder().fromEmailOverviewDomain(this); |
42 | } |
43 | |
44 | public abstract static class Builder<T extends Builder<T>> { |
45 | protected abstract T self(); |
46 | |
47 | protected String domain; |
48 | protected int accounts; |
49 | protected int aliases; |
50 | |
51 | /** |
52 | * @see EmailOverviewDomain#get() |
53 | */ |
54 | public T domain(String domain) { |
55 | this.domain = checkNotNull(domain, "domain"); |
56 | return self(); |
57 | } |
58 | |
59 | /** |
60 | * @see EmailOverviewDomain#getAccounts() |
61 | */ |
62 | public T accounts(int accounts) { |
63 | this.accounts = accounts; |
64 | return self(); |
65 | } |
66 | |
67 | /** |
68 | * @see EmailOverviewDomain#getAliases() |
69 | */ |
70 | public T aliases(int aliases) { |
71 | this.aliases = aliases; |
72 | return self(); |
73 | } |
74 | |
75 | public EmailOverviewDomain build() { |
76 | return new EmailOverviewDomain(domain, accounts, aliases); |
77 | } |
78 | |
79 | public T fromEmailOverviewDomain(EmailOverviewDomain in) { |
80 | return this.domain(in.get()).accounts(in.getAccounts()).aliases(in.getAliases()); |
81 | } |
82 | } |
83 | |
84 | private static class ConcreteBuilder extends Builder<ConcreteBuilder> { |
85 | @Override |
86 | protected ConcreteBuilder self() { |
87 | return this; |
88 | } |
89 | } |
90 | |
91 | private final String domain; |
92 | private final int accounts; |
93 | private final int aliases; |
94 | |
95 | @ConstructorProperties({ |
96 | "domainname", "accounts", "aliases" |
97 | }) |
98 | protected EmailOverviewDomain(String domain, int accounts, int aliases) { |
99 | this.domain = checkNotNull(domain, "domain"); |
100 | this.accounts = accounts; |
101 | this.aliases = aliases; |
102 | } |
103 | |
104 | /** @return the domain name */ |
105 | public String get() { |
106 | return this.domain; |
107 | } |
108 | |
109 | /** @return the number of e-mail accounts in the domain */ |
110 | public int getAccounts() { |
111 | return this.accounts; |
112 | } |
113 | |
114 | /** @return the number of e-mail aliases in the domain */ |
115 | public int getAliases() { |
116 | return this.aliases; |
117 | } |
118 | |
119 | @Override |
120 | public int hashCode() { |
121 | return Objects.hashCode(domain); |
122 | } |
123 | |
124 | @Override |
125 | public boolean equals(Object obj) { |
126 | if (this == obj) return true; |
127 | if (obj == null || getClass() != obj.getClass()) return false; |
128 | EmailOverviewDomain that = EmailOverviewDomain.class.cast(obj); |
129 | return Objects.equal(this.domain, that.domain); |
130 | } |
131 | |
132 | protected ToStringHelper string() { |
133 | return Objects.toStringHelper("").add("domain", domain).add("accounts", accounts).add("aliases", aliases); |
134 | } |
135 | |
136 | @Override |
137 | public String toString() { |
138 | return string().toString(); |
139 | } |
140 | |
141 | } |