1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.xnap.util;
21
22 import org.xnap.XNap;
23
24 /***
25 * Provides a mapping between connection speed and common internet acces
26 * hardware.
27 */
28 public class LinkType implements Comparable
29 {
30
31
32
33 /***
34 * Unknown link type.
35 */
36 public static final LinkType UNKNOWN = new LinkType(XNap.tr("Unknown"), 0);
37
38 /***
39 * The modem link.
40 */
41 public static final LinkType MODEM = new LinkType(XNap.tr("Modem"), 56);
42
43 /***
44 * The ISDN link.
45 */
46 public static final LinkType ISDN = new LinkType(XNap.tr("ISDN"), 64);
47
48 /***
49 * The cable link.
50 */
51 public static final LinkType CABLE = new LinkType(XNap.tr("Cable"), 500);
52
53 /***
54 * The DSL link.
55 */
56 public static final LinkType DSL = new LinkType(XNap.tr("DSL"), 768);
57
58 /***
59 * The T3 link.
60 */
61 public static final LinkType T3 = new LinkType(XNap.tr("T3"), 5000);
62
63 /***
64 * The local area network link.
65 */
66 public static final LinkType LAN
67 = new LinkType(XNap.tr("Local Network"), 10000);
68
69 /***
70 * An array of common link types.
71 */
72 public static final LinkType[] COMMON_TYPES = {
73 UNKNOWN, MODEM, ISDN, CABLE, DSL, T3, LAN
74 };
75
76
77
78 private String type;
79 private int speed;
80
81
82
83 /***
84 * Constructs a link speed object.
85 *
86 * @param type the name of the link type.
87 * @param speed the maximum speed of the link type in kbps
88 */
89 public LinkType(String type, int speed)
90 {
91 this.type = type;
92 this.speed = speed;
93 }
94
95
96
97 public static int getIndexOfType(LinkType[] types, int speed)
98 {
99 for (int i = 0; i < types.length; i++) {
100 if (types[i].getSpeed() >= speed) {
101 return i;
102 }
103 }
104
105
106 return types.length - 1;
107 }
108
109
110 /***
111 * Returns the type that is closest to <code>speed</code>
112 *
113 * @param speed the speed of the link type in kbps
114 */
115 public static LinkType getType(LinkType[] types, int speed)
116 {
117 return types[getIndexOfType(types, speed)];
118 }
119
120 /***
121 * Returns the common type that is closest to <code>speed</code>
122 *
123 * @param speed the speed of the link type in kbps
124 */
125 public static LinkType getType(int speed)
126 {
127 return COMMON_TYPES[getIndexOfType(COMMON_TYPES, speed)];
128 }
129
130 /***
131 * Returns the speed of the link type in kpbs.
132 */
133 public int getSpeed()
134 {
135 return speed;
136 }
137
138 public int compareTo(Object o)
139 {
140 return speed - ((LinkType)o).speed;
141 }
142
143 public String toString()
144 {
145 return type;
146 }
147
148 }