1 25 package org.jrobin.mrtg.client; 26 27 import java.util.Comparator ; 28 29 class RouterInfo implements TreeElementInfo { 30 private String 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 getHost() { 43 return host; 44 } 45 46 void setHost(String host) { 47 this.host = host; 48 } 49 50 String getDescr() { 51 return descr; 52 } 53 54 void setDescr(String descr) { 55 this.descr = descr; 56 } 57 58 String getCommunity() { 59 return community; 60 } 61 62 void setCommunity(String 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 toString() { 75 return host; 76 } 77 78 public String getInfo() { 79 StringBuffer buffer = new StringBuffer (); 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 getComparator() { 89 return new Comparator () { 90 public int compare(Object o1, Object 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 obj) { 99 if(obj instanceof RouterInfo) { 100 Comparator c = getComparator(); 101 return c.compare(this, obj) == 0; 102 } 103 return false; 104 } 105 106 String [] getInterfaces() { 107 String [] interfaces = new String [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 |