1 //
2 // ServerItem.java
3 // CocoDonkey
4 // $Id: ServerItem.java,v 1.4 2002/07/09 22:13:33 fortun Exp $
5 //
6 // Created by Fred Bonzoun on Sun May 12 2002.
7 // Copyright (c) 2002 Bonzoun. All rights reserved.
8 //
9 // This library is free software; you can redistribute it and/or modify
10 // it under the terms of the GNU Lesser General Public License as published
11 // by the Free Software Foundation; either version 2.1 of the License, or
12 // (at your option) any later version.
13 //
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU Lesser General Public License for more details.
18 //
19 // You should have received a copy of the GNU Lesser General Public License
20 // along with this program; if not, write to the Free Software
21 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 //
23
24 package net.bonzoun.cocodonkey;
25
26 import com.apple.cocoa.foundation;
27
28 public class ServerItem {
29
30 protected int id;
31 protected String ip;
32 protected String name;
33 protected int n1;
34 protected int n2;
35 protected String realIp;
36 protected String realPort;
37
38 /*package*/ ServerItem(int id, String ip, String name, int n1, int n2) {
39 this.id = id;
40 this.ip = ip;
41 this.name = name;
42 this.n1 = n1;
43 this.n2 = n2;
44 int p = ip.indexOf(':');
45 if (p>0) {
46 realIp = ip.substring(0, p);
47 realPort = ip.substring(p+1);
48 }
49 }
50
51 public void updateWith(ServerItem server) {
52 n1 = server.n1;
53 n2 = server.n2;
54 }
55
56 public int id() {
57 return id;
58 }
59
60 public String ip() {
61 return ip;
62 }
63
64 public String realIp() {
65 return realIp;
66 }
67
68 public String realPort() {
69 return realPort;
70 }
71
72 public String name() {
73 return name;
74 }
75
76 public int n1() {
77 return n1;
78 }
79
80 public int n2() {
81 return n2;
82 }
83
84 public static abstract class MyComparator implements java.util.Comparator {
85 public boolean equals(Object o) {
86 return equals(o);
87 }
88 }
89
90 public static class CompareName extends MyComparator {
91 public final int compare(Object o1, Object o2) {
92 ServerItem item1 = (ServerItem)o1;
93 ServerItem item2 = (ServerItem)o2;
94 if (item1.name()!=null)
95 return item1.name().compareToIgnoreCase(item2.name());
96 else
97 return 1;
98 }
99 }
100
101 public static class CompareIP extends MyComparator {
102 public final int compare(Object o1, Object o2) {
103 ServerItem item1 = (ServerItem)o1;
104 ServerItem item2 = (ServerItem)o2;
105 if (item1.ip()!=null)
106 return item1.ip().compareToIgnoreCase(item2.ip());
107 else
108 return 1;
109 }
110 }
111
112 public static class CompareN1 extends MyComparator {
113 public final int compare(Object o1, Object o2) {
114 ServerItem item1 = (ServerItem)o1;
115 ServerItem item2 = (ServerItem)o2;
116 if (item1.n1()<item2.n1())
117 return -1;
118 else if (item1.n1()==item2.n1())
119 return 0;
120 else
121 return 1;
122 }
123 }
124
125 public static class CompareN2 extends MyComparator {
126 public final int compare(Object o1, Object o2) {
127 ServerItem item1 = (ServerItem)o1;
128 ServerItem item2 = (ServerItem)o2;
129 if (item1.n2()<item2.n2())
130 return -1;
131 else if (item1.n2()==item2.n2())
132 return 0;
133 else
134 return 1;
135 }
136 }
137 }
138
139 // $Log: ServerItem.java,v $
140 // Revision 1.4 2002/07/09 22:13:33 fortun
141 // New realIp() and realPort() methods (unused but fun)
142 //
143 // Revision 1.3 2002/07/07 12:39:31 fortun
144 // Sorting now ignores case
145 //
146 // Revision 1.2 2002/05/27 22:10:27 fortun
147 // Added some comparators (for sorting)
148 //
149 // Revision 1.1.1.1 2002/05/21 21:26:13 fortun
150 //
151 //