FileDocCategorySizeDatePackage
SnmpIndex.javaAPI DocJava SE 5 API4849Fri Aug 26 14:55:04 BST 2005com.sun.jmx.snmp.agent

SnmpIndex

public class SnmpIndex extends Object implements Serializable
Represents a SNMP index. An SnmpIndex is represented as a Vector of SnmpOid.

This class is used internally and by the classes generated by mibgen. You should not need to use this class directly.

This API is a Sun Microsystems internal API and is subject to change without notice.

version
4.8 12/19/03
author
Sun Microsystems, Inc

Fields Summary
private Vector
oids
The list of OIDs.
private int
size
The number of elements in the index.
Constructors Summary
public SnmpIndex(com.sun.jmx.snmp.SnmpOid[] oidList)
Initializes an SnmpIndex using a vector of object identifiers.

Following the RFC recommendations, every syntax that is used as a table index should have an object identifier representation. There are some guidelines on how to map the different syntaxes into an object identifier. In the different SnmpValue classes provided, there is a toOid method to get the object identifier of the value.

param
oidList The list of Object Identifiers.

        size= oidList.length;
        for(int i= 0; i <size; i++) {
            // The order is important ...
            //
            oids.addElement(oidList[i]);
        }
    
public SnmpIndex(com.sun.jmx.snmp.SnmpOid oid)
Initializes an SnmpIndex using the specified Object Identifier.

param
oid The Object Identifier.

        oids.addElement(oid);
        size= 1;
    
Methods Summary
public intcompareTo(com.sun.jmx.snmp.agent.SnmpIndex index)
Compares two indexes.

param
index The index to compare this with.
return
The value 0 if the two OID vectors have the same elements, another value otherwise.

    
        int length= index.getNbComponents();
        Vector components= index.getComponents();
        SnmpOid oid1;
        SnmpOid oid2;
        int comp;
        for(int i=0; i < size; i++) {
            if ( i > length) {
                // There is no more element in the index
                //
                return 1;
            }
            // Access the element ...
            //
            oid1= (SnmpOid) oids.elementAt(i);
            oid2= (SnmpOid) components.elementAt(i);
            comp= oid1.compareTo(oid2);
            if (comp == 0)
                continue;
            return comp;
        }
        return 0;     
    
public booleanequals(com.sun.jmx.snmp.agent.SnmpIndex index)
Compares two indexes for equality.

param
index The index to compare this with.
return
true if the two indexes are equal, false otherwise.

        
        if (size != index.getNbComponents())
            return false;
    
        // The two vectors have the same length.
        // Compare each single element ...
        //
        SnmpOid oid1;
        SnmpOid oid2;
        Vector components= index.getComponents();
        for(int i=0; i <size; i++) {
            oid1= (SnmpOid) oids.elementAt(i);
            oid2= (SnmpOid) components.elementAt(i);
            if (oid1.equals(oid2) == false)
                return false;
        }
        return true;
    
public java.util.VectorgetComponents()
Gets the index as a vector of Object Identifiers.

return
The index as a vector.

        return oids;
    
public intgetNbComponents()
Gets the number of Object Identifiers the index is made of.

return
The number of Object Identifiers.

        return size;
    
public java.lang.StringtoString()
Returns a String representation of the index. The different elements are separated by "//".

return
A string representation of the index.

        StringBuffer msg= new StringBuffer();
        for(Enumeration e= oids.elements(); e.hasMoreElements(); ) {
            SnmpOid val= (SnmpOid) e.nextElement();
            msg.append( "//" + val.toString());
        }
        return msg.toString();