1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 package org.apache.http.nio.conn.scheme;
28
29 import java.util.Locale;
30
31 import org.apache.http.util.Args;
32 import org.apache.http.util.LangUtils;
33
34 @Deprecated
35 public final class AsyncScheme {
36
37
38 private final String name;
39
40
41 private final LayeringStrategy strategy;
42
43
44 private final int defaultPort;
45
46
47 private String stringRep;
48
49
50
51
52
53
54 public AsyncScheme(final String name, final int port, final LayeringStrategy strategy) {
55 Args.notNull(name, "Scheme name");
56 if ((port <= 0) || (port > 0xffff)) {
57 throw new IllegalArgumentException("Port is invalid: " + port);
58 }
59 this.name = name.toLowerCase(Locale.ROOT);
60 this.strategy = strategy;
61 this.defaultPort = port;
62 }
63
64 public final int getDefaultPort() {
65 return defaultPort;
66 }
67
68 public final LayeringStrategy getLayeringStrategy() {
69 return this.strategy;
70 }
71
72 public final String getName() {
73 return name;
74 }
75
76 public final int resolvePort(final int port) {
77 return port <= 0 ? defaultPort : port;
78 }
79
80 @Override
81 public final String toString() {
82 if (stringRep == null) {
83 final StringBuilder buffer = new StringBuilder();
84 buffer.append(this.name);
85 buffer.append(':');
86 buffer.append(Integer.toString(this.defaultPort));
87 stringRep = buffer.toString();
88 }
89 return stringRep;
90 }
91
92 @Override
93 public final boolean equals(final Object obj) {
94 if (this == obj) {
95 return true;
96 }
97 if (obj instanceof AsyncScheme) {
98 final AsyncScheme../../../../../org/apache/http/nio/conn/scheme/AsyncScheme.html#AsyncScheme">AsyncScheme that = (AsyncScheme) obj;
99 return this.name.equals(that.name)
100 && this.defaultPort == that.defaultPort
101 && this.strategy.equals(that.strategy);
102 }
103 return false;
104 }
105
106 @Override
107 public int hashCode() {
108 int hash = LangUtils.HASH_SEED;
109 hash = LangUtils.hashCode(hash, this.defaultPort);
110 hash = LangUtils.hashCode(hash, this.name);
111 hash = LangUtils.hashCode(hash, this.strategy);
112 return hash;
113 }
114
115 }