Class AsnObjectId

java.lang.Object
uk.co.westhawk.snmp.stack.AsnObject
uk.co.westhawk.snmp.stack.AsnObjectId
All Implemented Interfaces:
Comparable, SnmpConstants

public class AsnObjectId extends AsnObject implements Comparable
This class represents the ASN.1 ObjectID class. An Object ID (OID) identifies a variable in a MIB.
Version:
$Revision: 3.25 $ $Date: 2008/08/19 13:34:13 $
Author:
Tim Panton
  • Constructor Details

    • AsnObjectId

      public AsnObjectId(String s) throws IllegalArgumentException
      Constructs an AsnObjectId out of an OID string.
      Parameters:
      s - The OID, format a[.b]*
      Throws:
      IllegalArgumentException
    • AsnObjectId

      public AsnObjectId(long[] oida)
      Constructs an AsnObjectId out of an array of long.
      Parameters:
      oida - The OID, as an array of long
      Since:
      4_14
  • Method Details

    • startsWith

      public boolean startsWith(AsnObjectId prefix)
      Checks if this OID starts with the specified prefix.
      Returns:
      true if starts with the prefix, false otherwise
    • add

      public void add(long sub_oid)
      Adds a single sub-identifier to the end of the OID.
      Parameters:
      sub_oid - The sub-identifier
    • add

      public void add(long[] sub_oid)
      Adds a number of sub-identifiers to the end of the OID.
      Parameters:
      sub_oid - The sub-identifiers
      See Also:
    • add

      public void add(String s) throws IllegalArgumentException
      Adds sub-identifiers to the end of the OID.
      Parameters:
      s - The sub-identifiers, format a[.b]*
      Throws:
      IllegalArgumentException
    • removeLast

      public long removeLast()
      Removes the last sub-identifier (if available) from this OID and returns it.
      Returns:
      The sub-identifier or -1 if there is no sub-identifier
      Since:
      6.1
    • getValue

      public String getValue()
      Returns the value of the AsnObjectId.
      Returns:
      The value (the OID)
    • toString

      public String toString()
      Returns the string representation of the AsnObjectId.
      Specified by:
      toString in class AsnObject
      Returns:
      The string of the AsnObjectId
    • toString

      public String toString(long[] v)
      Returns the string representation of the AsnObjectId.
      Returns:
      The string of the AsnObjectId
    • getSize

      public int getSize()
      Returns the number of elements in the AsnObjectId. We cannot use size(), since that is already in use.
      Returns:
      the number of elements
    • getElementAt

      public long getElementAt(int index) throws ArrayIndexOutOfBoundsException
      Returns the element in the AsnObjectId at the specified index.
      Parameters:
      index - The index
      Returns:
      the element at the specified index
      Throws:
      ArrayIndexOutOfBoundsException - if an invalid index was given
    • lastElement

      public long lastElement() throws ArrayIndexOutOfBoundsException
      Returns the last element in the AsnObjectId.
      Returns:
      the last element
      Throws:
      ArrayIndexOutOfBoundsException - if the AsnObjectId is empty.
      Since:
      6.1
    • getOid

      public long[] getOid()
      Returns the value of the AsnObjectId as an array of long. The value returned is a copy.
      Returns:
      The OID value
      Since:
      4_14
    • getSubOid

      public long[] getSubOid(int beginIndex, int endIndex) throws ArrayIndexOutOfBoundsException
      Returns a subset of the value of the AsnObjectId as an array of long. The value returned is a copy.
      Returns:
      The sub OID value
      Throws:
      ArrayIndexOutOfBoundsException
      Since:
      4_14
    • equals

      public boolean equals(Object anObject)
      Compares this OID to the specified object. The result is true if and only if the argument is not null and is a AsnObjectId object that represents the same sequence of numbers as this object.

      Thanks to Eli Bishop (eli@graphesthesia.com) for the suggestion of adding it.

      Overrides:
      equals in class Object
      Parameters:
      anObject - The object to compare this AsnObjectId against.
      Returns:
      true if the AsnObjectId are equal; false otherwise.
    • hashCode

      public int hashCode()
      Returns a hash code for this OID. The hash value of the empty OID is zero.
      Overrides:
      hashCode in class Object
      Returns:
      a hash code value for this object.
    • compareTo

      public int compareTo(Object o)
      Specified by:
      compareTo in interface Comparable
      Since:
      6.1
      See Also:
    • compareTo

      public int compareTo(AsnObjectId b)
      Since:
      6.1
      See Also:
    • leftMostCompare

      public int leftMostCompare(int n, AsnObjectId b)
      Compares the n leftmost sub-identifiers with the given AsnObject in left-to-right direction.
      Parameters:
      n - The number of sub-identifiers to compare.
      b - An AsnObject to compare with this object
      Returns:
      • 0, when the first 'n' sub-identifiers are the same.
      • -1 when the first 'n' sub-identifiers of this object are lexicographic less than those of b. This includes the case where this object is shorter than 'n' AND shorter than b.
      • 1 when the first 'n' sub-identifiers of this object are lexicographic greater than those of b.
      Since:
      6.1