1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.jclouds.cloudloadbalancers.domain;
20
21 import org.jclouds.cloudloadbalancers.domain.internal.BaseLoadBalancer;
22
23
24
25
26
27
28
29
30 public class LoadBalancerAttributes {
31 protected String name;
32 protected String protocol;
33 protected Integer port;
34 protected String algorithm;
35
36 public LoadBalancerAttributes name(String name) {
37 this.name = name;
38 return this;
39 }
40
41 public LoadBalancerAttributes protocol(String protocol) {
42 this.protocol = protocol;
43 return this;
44 }
45
46 public LoadBalancerAttributes port(int port) {
47 this.port = port;
48 return this;
49 }
50
51 public LoadBalancerAttributes algorithm(String algorithm) {
52 this.algorithm = algorithm;
53 return this;
54 }
55
56 public static <T extends BaseLoadBalancer<?, T>> LoadBalancerAttributes fromLoadBalancer(T lb) {
57 return Builder.name(lb.getName()).port(lb.getPort()).protocol(lb.getProtocol()).algorithm(lb.getAlgorithm());
58 }
59
60 public static class Builder {
61 public static LoadBalancerAttributes name(String name) {
62 return new LoadBalancerAttributes().name(name);
63 }
64
65 public static LoadBalancerAttributes protocol(String protocol) {
66 return new LoadBalancerAttributes().protocol(protocol);
67 }
68
69 public static LoadBalancerAttributes port(int port) {
70 return new LoadBalancerAttributes().port(port);
71 }
72
73 public static LoadBalancerAttributes algorithm(String algorithm) {
74 return new LoadBalancerAttributes().algorithm(algorithm);
75 }
76 }
77
78 @Override
79 public String toString() {
80 return String.format("[algorithm=%s, name=%s, port=%s, protocol=%s]", algorithm, name, port, protocol);
81 }
82
83 @Override
84 public int hashCode() {
85 final int prime = 31;
86 int result = 1;
87 result = prime * result + ((algorithm == null) ? 0 : algorithm.hashCode());
88 result = prime * result + ((name == null) ? 0 : name.hashCode());
89 result = prime * result + ((port == null) ? 0 : port.hashCode());
90 result = prime * result + ((protocol == null) ? 0 : protocol.hashCode());
91 return result;
92 }
93
94 @Override
95 public boolean equals(Object obj) {
96 if (this == obj)
97 return true;
98 if (obj == null)
99 return false;
100 if (getClass() != obj.getClass())
101 return false;
102 LoadBalancerAttributes other = (LoadBalancerAttributes) obj;
103 if (algorithm == null) {
104 if (other.algorithm != null)
105 return false;
106 } else if (!algorithm.equals(other.algorithm))
107 return false;
108 if (name == null) {
109 if (other.name != null)
110 return false;
111 } else if (!name.equals(other.name))
112 return false;
113 if (port == null) {
114 if (other.port != null)
115 return false;
116 } else if (!port.equals(other.port))
117 return false;
118 if (protocol == null) {
119 if (other.protocol != null)
120 return false;
121 } else if (!protocol.equals(other.protocol))
122 return false;
123 return true;
124 }
125 }