1 package org.sonatype.aether.repository;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 public final class Proxy
18 {
19
20
21
22
23 public static final String TYPE_HTTP = "http";
24
25
26
27
28 public static final String TYPE_HTTPS = "https";
29
30 private final String type;
31
32 private final String host;
33
34 private final int port;
35
36 private final Authentication auth;
37
38
39
40
41
42
43
44
45
46 public Proxy( String type, String host, int port, Authentication auth )
47 {
48 this.type = ( type != null ) ? type : "";
49 this.host = ( host != null ) ? host : "";
50 this.port = port;
51 this.auth = auth;
52 }
53
54
55
56
57
58
59 public String getType()
60 {
61 return type;
62 }
63
64
65
66
67
68
69
70 public Proxy setType( String type )
71 {
72 if ( this.type.equals( type ) || ( type == null && this.type.length() <= 0 ) )
73 {
74 return this;
75 }
76 return new Proxy( type, host, port, auth );
77 }
78
79
80
81
82
83
84 public String getHost()
85 {
86 return host;
87 }
88
89
90
91
92
93
94
95 public Proxy setHost( String host )
96 {
97 if ( this.host.equals( host ) || ( host == null && this.host.length() <= 0 ) )
98 {
99 return this;
100 }
101 return new Proxy( type, host, port, auth );
102 }
103
104
105
106
107
108
109 public int getPort()
110 {
111 return port;
112 }
113
114
115
116
117
118
119
120 public Proxy setPort( int port )
121 {
122 if ( this.port == port )
123 {
124 return this;
125 }
126 return new Proxy( type, host, port, auth );
127 }
128
129
130
131
132
133
134 public Authentication getAuthentication()
135 {
136 return auth;
137 }
138
139
140
141
142
143
144
145 public Proxy setAuthentication( Authentication auth )
146 {
147 if ( eq( this.auth, auth ) )
148 {
149 return this;
150 }
151 return new Proxy( type, host, port, auth );
152 }
153
154 @Override
155 public String toString()
156 {
157 return getHost() + ':' + getPort();
158 }
159
160 @Override
161 public boolean equals( Object obj )
162 {
163 if ( this == obj )
164 {
165 return true;
166 }
167 if ( obj == null || !getClass().equals( obj.getClass() ) )
168 {
169 return false;
170 }
171
172 Proxy that = (Proxy) obj;
173
174 return eq( type, that.type ) && eq( host, that.host ) && port == that.port && eq( auth, that.auth );
175 }
176
177 private static <T> boolean eq( T s1, T s2 )
178 {
179 return s1 != null ? s1.equals( s2 ) : s2 == null;
180 }
181
182 @Override
183 public int hashCode()
184 {
185 int hash = 17;
186 hash = hash * 31 + hash( host );
187 hash = hash * 31 + hash( type );
188 hash = hash * 31 + port;
189 hash = hash * 31 + hash( auth );
190 return hash;
191 }
192
193 private static int hash( Object obj )
194 {
195 return obj != null ? obj.hashCode() : 0;
196 }
197
198 }