1 11 12 13 package com.sun.jmx.snmp.agent; 14 15 16 17 import java.io.Serializable ; 20 import java.util.Vector ; 21 import java.util.Enumeration ; 22 23 import com.sun.jmx.snmp.SnmpOid; 26 27 39 40 public class SnmpIndex implements Serializable { 41 42 52 public SnmpIndex(SnmpOid[] oidList) { 53 size= oidList.length; 54 for(int i= 0; i <size; i++) { 55 oids.addElement(oidList[i]); 58 } 59 } 60 61 66 public SnmpIndex(SnmpOid oid) { 67 oids.addElement(oid); 68 size= 1; 69 } 70 71 76 public int getNbComponents() { 77 return size; 78 } 79 80 85 public Vector getComponents() { 86 return oids; 87 } 88 89 96 public boolean equals(SnmpIndex index) { 97 98 if (size != index.getNbComponents()) 99 return false; 100 101 SnmpOid oid1; 105 SnmpOid oid2; 106 Vector components= index.getComponents(); 107 for(int i=0; i <size; i++) { 108 oid1= (SnmpOid) oids.elementAt(i); 109 oid2= (SnmpOid) components.elementAt(i); 110 if (oid1.equals(oid2) == false) 111 return false; 112 } 113 return true; 114 } 115 116 123 public int compareTo(SnmpIndex index) { 124 125 int length= index.getNbComponents(); 126 Vector components= index.getComponents(); 127 SnmpOid oid1; 128 SnmpOid oid2; 129 int comp; 130 for(int i=0; i < size; i++) { 131 if ( i > length) { 132 return 1; 135 } 136 oid1= (SnmpOid) oids.elementAt(i); 139 oid2= (SnmpOid) components.elementAt(i); 140 comp= oid1.compareTo(oid2); 141 if (comp == 0) 142 continue; 143 return comp; 144 } 145 return 0; 146 } 147 148 154 public String toString() { 155 StringBuffer msg= new StringBuffer (); 156 for(Enumeration e= oids.elements(); e.hasMoreElements(); ) { 157 SnmpOid val= (SnmpOid) e.nextElement(); 158 msg.append( "//" + val.toString()); 159 } 160 return msg.toString(); 161 } 162 163 166 170 private Vector oids = new Vector (); 171 172 176 private int size = 0; 177 } 178 | Popular Tags |