예제 #1
0
  public SnmpInstId getInstance(SnmpObjId base) {
    if (!base.isPrefixOf(this)) return null;

    int[] instanceIds = new int[length() - base.length()];
    System.arraycopy(m_ids, base.length(), instanceIds, 0, instanceIds.length);
    return new SnmpInstId(instanceIds);
  }
예제 #2
0
  public boolean isPrefixOf(final SnmpObjId other) {
    if (other == null || length() > other.length()) return false;

    for (int i = 0; i < m_ids.length; i++) {
      if (m_ids[i] != other.m_ids[i]) return false;
    }

    return true;
  }
예제 #3
0
  @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();
  }