EMMA Coverage Report (generated Mon Oct 17 05:41:20 EDT 2011)
[all classes][org.jclouds.cloudloadbalancers.domain.internal]

COVERAGE SUMMARY FOR SOURCE FILE [BaseLoadBalancer.java]

nameclass, %method, %block, %line, %
BaseLoadBalancer.java100% (2/2)64%  (14/22)44%  (104/234)58%  (29.9/52)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class BaseLoadBalancer$Builder100% (1/1)56%  (5/9)34%  (26/77)62%  (10/16)
build (): BaseLoadBalancer 0%   (0/1)0%   (0/14)0%   (0/1)
from (BaseLoadBalancer): BaseLoadBalancer$Builder 0%   (0/1)0%   (0/17)0%   (0/1)
node (BaseNode): BaseLoadBalancer$Builder 0%   (0/1)0%   (0/11)0%   (0/2)
nodes (Iterable): BaseLoadBalancer$Builder 0%   (0/1)0%   (0/9)0%   (0/2)
BaseLoadBalancer$Builder (): void 100% (1/1)100% (6/6)100% (2/2)
algorithm (String): BaseLoadBalancer$Builder 100% (1/1)100% (5/5)100% (2/2)
name (String): BaseLoadBalancer$Builder 100% (1/1)100% (5/5)100% (2/2)
port (Integer): BaseLoadBalancer$Builder 100% (1/1)100% (5/5)100% (2/2)
protocol (String): BaseLoadBalancer$Builder 100% (1/1)100% (5/5)100% (2/2)
     
class BaseLoadBalancer100% (1/1)69%  (9/13)50%  (78/157)55%  (19.9/36)
builder (): BaseLoadBalancer$Builder 0%   (0/1)0%   (0/4)0%   (0/1)
equals (Object): boolean 0%   (0/1)0%   (0/37)0%   (0/13)
toBuilder (): BaseLoadBalancer$Builder 0%   (0/1)0%   (0/6)0%   (0/1)
toString (): String 0%   (0/1)0%   (0/30)0%   (0/1)
hashCode (): int 100% (1/1)92%  (23/25)98%  (3.9/4)
BaseLoadBalancer (): void 100% (1/1)100% (6/6)100% (3/3)
BaseLoadBalancer (String, String, Integer, String, Iterable): void 100% (1/1)100% (28/28)100% (8/8)
compareTo (BaseLoadBalancer): int 100% (1/1)100% (6/6)100% (1/1)
getAlgorithm (): String 100% (1/1)100% (3/3)100% (1/1)
getName (): String 100% (1/1)100% (3/3)100% (1/1)
getNodes (): Set 100% (1/1)100% (3/3)100% (1/1)
getPort (): Integer 100% (1/1)100% (3/3)100% (1/1)
getProtocol (): String 100% (1/1)100% (3/3)100% (1/1)

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 */
19package org.jclouds.cloudloadbalancers.domain.internal;
20 
21import static com.google.common.base.Preconditions.checkNotNull;
22 
23import java.util.Set;
24import java.util.SortedSet;
25 
26import com.google.common.collect.ImmutableSet;
27import com.google.common.collect.ImmutableSortedSet;
28import com.google.common.collect.Sets;
29 
30/**
31 * 
32 * @author Adrian Cole
33 * @see <a href=
34 *      "http://docs.rackspacecloud.com/loadbalancers/api/v1.0/clb-devguide/content/ch04s01s02.html"
35 *      />
36 */
37public class BaseLoadBalancer<N extends BaseNode<N>, T extends BaseLoadBalancer<N, T>> implements
38         Comparable<BaseLoadBalancer<N, T>> {
39 
40   public static <N extends BaseNode<N>, T extends BaseLoadBalancer<N, T>> Builder<N, T> builder() {
41      return new Builder<N, T>();
42   }
43 
44   @SuppressWarnings("unchecked")
45   public Builder<N, T> toBuilder() {
46      return new Builder<N, T>().from((T) this);
47   }
48 
49   public static class Builder<N extends BaseNode<N>, T extends BaseLoadBalancer<N, T>> {
50      protected String name;
51      protected String protocol;
52      protected Integer port;
53      protected String algorithm;
54      protected Set<N> nodes = Sets.newLinkedHashSet();
55 
56      public Builder<N, T> name(String name) {
57         this.name = name;
58         return this;
59      }
60 
61      public Builder<N, T> protocol(String protocol) {
62         this.protocol = protocol;
63         return this;
64      }
65 
66      public Builder<N, T> port(Integer port) {
67         this.port = port;
68         return this;
69      }
70 
71      public Builder<N, T> algorithm(String algorithm) {
72         this.algorithm = algorithm;
73         return this;
74      }
75 
76      public Builder<N, T> nodes(Iterable<N> nodes) {
77         this.nodes = ImmutableSet.<N> copyOf(checkNotNull(nodes, "nodes"));
78         return this;
79      }
80 
81      @SuppressWarnings("unchecked")
82      public Builder<N, T> node(N node) {
83         this.nodes.add((N) checkNotNull(nodes, "nodes"));
84         return this;
85      }
86 
87      public BaseLoadBalancer<N, T> build() {
88         return new BaseLoadBalancer<N, T>(name, protocol, port, algorithm, nodes);
89      }
90 
91      public Builder<N, T> from(T baseLoadBalancer) {
92         return name(baseLoadBalancer.getName()).port(baseLoadBalancer.getPort()).protocol(
93                  baseLoadBalancer.getProtocol()).algorithm(baseLoadBalancer.getAlgorithm()).nodes(
94                  baseLoadBalancer.getNodes());
95      }
96   }
97 
98   // for serialization only
99   protected BaseLoadBalancer() {
100 
101   }
102 
103   protected String name;
104   protected String protocol;
105   protected Integer port;
106   protected String algorithm;
107   // so tests will come out consistently
108   protected SortedSet<N> nodes = ImmutableSortedSet.of();
109 
110   public BaseLoadBalancer(String name, String protocol, Integer port, String algorithm, Iterable<N> nodes) {
111      this.name = checkNotNull(name, "name");
112      this.protocol = protocol;// null on deleted LB
113      this.port = port;// null on deleted LB
114      this.algorithm = algorithm;// null on deleted LB
115      this.nodes = ImmutableSortedSet.copyOf(checkNotNull(nodes, "nodes"));
116   }
117 
118   @Override
119   public int compareTo(BaseLoadBalancer<N, T> arg0) {
120      return name.compareTo(arg0.name);
121   }
122 
123   public String getName() {
124      return name;
125   }
126 
127   public String getProtocol() {
128      return protocol;
129   }
130 
131   public Integer getPort() {
132      return port;
133   }
134 
135   public String getAlgorithm() {
136      return algorithm;
137   }
138 
139   public Set<N> getNodes() {
140      return nodes;
141   }
142 
143   @Override
144   public int hashCode() {
145      final Integer prime = 31;
146      Integer result = 1;
147      result = prime * result + ((name == null) ? 0 : name.hashCode());
148      return result;
149   }
150 
151   @Override
152   public boolean equals(Object obj) {
153      if (this == obj)
154         return true;
155      if (obj == null)
156         return false;
157      if (getClass() != obj.getClass())
158         return false;
159      BaseLoadBalancer<?, ?> other = (BaseLoadBalancer<?, ?>) obj;
160      if (name == null) {
161         if (other.name != null)
162            return false;
163      } else if (!name.equals(other.name))
164         return false;
165      return true;
166   }
167 
168   @Override
169   public String toString() {
170      return String.format("[name=%s, port=%s, protocol=%s, algorithm=%s, nodes=%s]", name, port, protocol, algorithm,
171               nodes);
172   }
173}

[all classes][org.jclouds.cloudloadbalancers.domain.internal]
EMMA 2.0.5312 (C) Vladimir Roubtsov