public int compareTo(Object o) { if (o == null) throw new NullPointerException("o is null"); SnmpObjId other = (SnmpObjId)o; // compare each element in order for as much length as they have in common // which is the entire length of one or both oids int minLen = Math.min(length(), other.length()); for(int i = 0; i < minLen; i++) { int diff = m_ids[i] - other.m_ids[i]; // the first one that is not equal indicates which is bigger if (diff != 0) return diff; } // if they get to hear then both are identifical for their common length // so which ever is longer is then greater return length() - other.length(); }
@Override public int compareTo(SnmpObjId o) { if (o == null) throw new NullPointerException("o is null"); SnmpObjId other = (SnmpObjId)o; // compare each element in order for as much length as they have in common // which is the entire length of one or both oids int minLen = Math.min(length(), other.length()); for(int i = 0; i < minLen; i++) { long diff = toLong(m_ids[i]) - toLong(other.m_ids[i]); // the first one that is not equal indicates which is bigger if (diff != 0) { return diff > 0 ? 1 : -1; } } // if they get to hear then both are identifical for their common length // so which ever is longer is then greater return length() - other.length(); }
@Override public String toString() { final StringBuilder buf = new StringBuilder(length()*2+10); // a guess at the str len for(int i = 0; i < length(); i++) { if (i > 0 || addPrefixDotInToString()) { buf.append('.'); } // we use toLong to account for unsigned ints > Integer.MAX_INT buf.append(toLong(m_ids[i])); } return buf.toString(); }
public int getLastSubId() { return getSubIdAt(length()-1); }
public int getLastSubId() { return getSubIdAt(length()-1); }
public SnmpObjId getPrefix(int length) { if (length >= length()) { throw new IllegalArgumentException("Invalid length: " + length +" is longer than length of ObjId"); } int[] newIds = cloneIds(m_ids, length); return new SnmpObjId(newIds, false); }
final SnmpObjId requestOid = SnmpObjId.get(metricObjId.substring(0, metricObjId.lastIndexOf("_"))); SnmpObjId base = requestOid.getPrefix(requestOid.length() - 1); int lastId = requestOid.getLastSubId();
SnmpObjId base = requestOid.getPrefix(requestOid.length()-1); int lastId = requestOid.getLastSubId();