1 22 package org.jboss.jmx.adaptor.snmp.agent; 23 24 import org.opennms.protocols.snmp.SnmpObjectId; 25 26 32 public class ComparableSnmpObjectId extends SnmpObjectId implements Comparable 33 { 34 35 public ComparableSnmpObjectId(String oid) 36 { 37 super(oid); 38 } 39 40 public ComparableSnmpObjectId(SnmpObjectId oid) 41 { 42 super(oid); 43 } 44 45 public ComparableSnmpObjectId(int[] identifiers) 46 { 47 super(identifiers); 48 } 49 50 57 public int compareTo(Object o) 58 { 59 60 if (o==null) 61 return -1; 62 63 if (!(o instanceof SnmpObjectId)) 64 return -1; 65 66 return this.compare((SnmpObjectId)o); 67 } 68 69 73 public boolean isLeaf() 74 { 75 int[] ids = getIdentifiers(); 76 if (ids.length==0) { return false; 78 } 79 if (ids[ids.length-1]==0) 80 { 81 return true; 82 } 83 return false; 84 } 85 86 91 public ComparableSnmpObjectId removeLastPart() 92 { 93 int[] ids = getIdentifiers(); 94 95 int[] outs = new int[ids.length-1]; 96 int len = ids.length-1; 97 for (int i = 0; i<len ; i++) 98 { 99 outs[i]=ids[i]; 100 } 101 ComparableSnmpObjectId out = new ComparableSnmpObjectId(outs); 102 return out; 103 } 104 105 115 public ComparableSnmpObjectId getNextArc() 116 { 117 ComparableSnmpObjectId cid = this; 118 if (isLeaf()) 119 { 120 cid = removeLastPart(); 121 } 122 cid = cid.removeLastPart(); 123 124 int[] ids = cid.getIdentifiers(); 125 int[] ods = new int[ids.length]; 126 System.arraycopy(ids, 127 0, 128 ods, 129 0, 130 ids.length); 131 132 int len = ods.length-1; 133 ods[len]++; 134 135 ComparableSnmpObjectId ret = new ComparableSnmpObjectId(ods); 136 return ret; 137 } 138 139 } 140 | Popular Tags |