KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jrobin > mrtg > client > RouterInfo


1 /* ============================================================
2  * JRobin : Pure java implementation of RRDTool's functionality
3  * ============================================================
4  *
5  * Project Info: http://www.jrobin.org
6  * Project Lead: Sasa Markovic (saxon@jrobin.org);
7  *
8  * (C) Copyright 2003, by Sasa Markovic.
9  *
10  * Developers: Sasa Markovic (saxon@jrobin.org)
11  * Arne Vandamme (cobralord@jrobin.org)
12  *
13  * This library is free software; you can redistribute it and/or modify it under the terms
14  * of the GNU Lesser General Public License as published by the Free Software Foundation;
15  * either version 2.1 of the License, or (at your option) any later version.
16  *
17  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
18  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19  * See the GNU Lesser General Public License for more details.
20  *
21  * You should have received a copy of the GNU Lesser General Public License along with this
22  * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
23  * Boston, MA 02111-1307, USA.
24  */

25 package org.jrobin.mrtg.client;
26
27 import java.util.Comparator JavaDoc;
28
29 class RouterInfo implements TreeElementInfo {
30     private String JavaDoc host, descr, community;
31     private boolean active;
32     private LinkInfo[] linksInfo;
33
34     LinkInfo[] getLinkInfo() {
35         return linksInfo;
36     }
37
38     void setLinkInfo(LinkInfo[] linksInfo) {
39         this.linksInfo = linksInfo;
40     }
41
42     String JavaDoc getHost() {
43         return host;
44     }
45
46     void setHost(String JavaDoc host) {
47         this.host = host;
48     }
49
50     String JavaDoc getDescr() {
51         return descr;
52     }
53
54     void setDescr(String JavaDoc descr) {
55         this.descr = descr;
56     }
57
58     String JavaDoc getCommunity() {
59         return community;
60     }
61
62     void setCommunity(String JavaDoc community) {
63         this.community = community;
64     }
65
66     boolean isActive() {
67         return active;
68     }
69
70     void setActive(boolean active) {
71         this.active = active;
72     }
73
74     public String JavaDoc toString() {
75         return host;
76     }
77
78     public String JavaDoc getInfo() {
79         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
80         buffer.append("Router address: " + getHost() + "\n");
81         buffer.append("Community: " + getCommunity() + "\n");
82         buffer.append("Description: " + getDescr() + "\n");
83         buffer.append("Active: " + isActive() + "\n");
84         buffer.append("Sampled links: " + getLinkInfo().length + "\n");
85         return buffer.toString();
86     }
87
88     static Comparator JavaDoc getComparator() {
89         return new Comparator JavaDoc() {
90             public int compare(Object JavaDoc o1, Object JavaDoc o2) {
91                 RouterInfo router1 = (RouterInfo) o1;
92                 RouterInfo router2 = (RouterInfo) o2;
93                 return router1.getHost().compareToIgnoreCase(router2.getHost());
94             }
95         };
96     }
97
98     public boolean equals(Object JavaDoc obj) {
99         if(obj instanceof RouterInfo) {
100             Comparator JavaDoc c = getComparator();
101             return c.compare(this, obj) == 0;
102         }
103         return false;
104     }
105
106     String JavaDoc[] getInterfaces() {
107         String JavaDoc[] interfaces = new String JavaDoc[linksInfo.length];
108         for(int i = 0; i < linksInfo.length; i++) {
109             interfaces[i] = linksInfo[i].getIfDescr();
110         }
111         return interfaces;
112     }
113
114 }
115
Popular Tags