1
2
3
4
5
6
7
8
9
10
11 package org.eclipse.aether.repository;
12
13
14
15
16 public final class Proxy
17 {
18
19
20
21
22 public static final String TYPE_HTTP = "http";
23
24
25
26
27 public static final String TYPE_HTTPS = "https";
28
29 private final String type;
30
31 private final String host;
32
33 private final int port;
34
35 private final Authentication auth;
36
37
38
39
40
41
42
43
44 public Proxy( String type, String host, int port )
45 {
46 this( type, host, port, null );
47 }
48
49
50
51
52
53
54
55
56
57 public Proxy( String type, String host, int port, Authentication auth )
58 {
59 this.type = ( type != null ) ? type : "";
60 this.host = ( host != null ) ? host : "";
61 this.port = port;
62 this.auth = auth;
63 }
64
65
66
67
68
69
70 public String getType()
71 {
72 return type;
73 }
74
75
76
77
78
79
80 public String getHost()
81 {
82 return host;
83 }
84
85
86
87
88
89
90 public int getPort()
91 {
92 return port;
93 }
94
95
96
97
98
99
100 public Authentication getAuthentication()
101 {
102 return auth;
103 }
104
105 @Override
106 public String toString()
107 {
108 return getHost() + ':' + getPort();
109 }
110
111 @Override
112 public boolean equals( Object obj )
113 {
114 if ( this == obj )
115 {
116 return true;
117 }
118 if ( obj == null || !getClass().equals( obj.getClass() ) )
119 {
120 return false;
121 }
122
123 Proxy that = (Proxy) obj;
124
125 return eq( type, that.type ) && eq( host, that.host ) && port == that.port && eq( auth, that.auth );
126 }
127
128 private static <T> boolean eq( T s1, T s2 )
129 {
130 return s1 != null ? s1.equals( s2 ) : s2 == null;
131 }
132
133 @Override
134 public int hashCode()
135 {
136 int hash = 17;
137 hash = hash * 31 + hash( host );
138 hash = hash * 31 + hash( type );
139 hash = hash * 31 + port;
140 hash = hash * 31 + hash( auth );
141 return hash;
142 }
143
144 private static int hash( Object obj )
145 {
146 return obj != null ? obj.hashCode() : 0;
147 }
148
149 }