Java Code Examples for com.sun.jmx.snmp.SnmpOid#compareTo()

The following examples show how to use com.sun.jmx.snmp.SnmpOid#compareTo() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SnmpIndex.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Compares two indexes.
 *
 * @param index The index to compare <CODE>this</CODE> with.
 *
 * @return The value 0 if the two OID vectors have the same elements, another value otherwise.
 */
public int compareTo(SnmpIndex index) {

    int length= index.getNbComponents();
    Vector<SnmpOid> 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= oids.elementAt(i);
        oid2= components.elementAt(i);
        comp= oid1.compareTo(oid2);
        if (comp == 0)
            continue;
        return comp;
    }
    return 0;
}
 
Example 2
Source File: SnmpIndex.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Compares two indexes.
 *
 * @param index The index to compare <CODE>this</CODE> with.
 *
 * @return The value 0 if the two OID vectors have the same elements, another value otherwise.
 */
public int compareTo(SnmpIndex index) {

    int length= index.getNbComponents();
    Vector<SnmpOid> 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= oids.elementAt(i);
        oid2= components.elementAt(i);
        comp= oid1.compareTo(oid2);
        if (comp == 0)
            continue;
        return comp;
    }
    return 0;
}
 
Example 3
Source File: SnmpIndex.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Compares two indexes.
 *
 * @param index The index to compare <CODE>this</CODE> with.
 *
 * @return The value 0 if the two OID vectors have the same elements, another value otherwise.
 */
public int compareTo(SnmpIndex index) {

    int length= index.getNbComponents();
    Vector<SnmpOid> 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= oids.elementAt(i);
        oid2= components.elementAt(i);
        comp= oid1.compareTo(oid2);
        if (comp == 0)
            continue;
        return comp;
    }
    return 0;
}
 
Example 4
Source File: SnmpIndex.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Compares two indexes.
 *
 * @param index The index to compare <CODE>this</CODE> with.
 *
 * @return The value 0 if the two OID vectors have the same elements, another value otherwise.
 */
public int compareTo(SnmpIndex index) {

    int length= index.getNbComponents();
    Vector<SnmpOid> 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= oids.elementAt(i);
        oid2= components.elementAt(i);
        comp= oid1.compareTo(oid2);
        if (comp == 0)
            continue;
        return comp;
    }
    return 0;
}
 
Example 5
Source File: SnmpMibTable.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Search the position at which the given oid should be inserted
 * in the OID table (tableoids).
 *
 * <p>
 * @param oid The OID we would like to insert.
 *
 * @param fail Tells whether a SnmpStatusException must be generated
 *             if the given OID is already present in the table.
 *
 * @return The position at which the OID should be inserted in
 *         the table. When the OID is found, it returns the next
 *         position. Note that it is not valid to insert twice the
 *         same OID. This feature is only an optimization to improve
 *         the getNextOid() behaviour.
 *
 * @exception SnmpStatusException if the OID is already present in the
 *            table and <code>fail</code> is <code>true</code>.
 *
 **/
private int getInsertionPoint(SnmpOid oid, boolean fail)
    throws SnmpStatusException {

    final int failStatus = SnmpStatusException.snmpRspNotWritable;
    int low= 0;
    int max= size - 1;
    SnmpOid pos;
    int comp;
    int curr= low + (max-low)/2;
    while (low <= max) {

        // XX pos= (SnmpOid) oids.elementAt(curr);
        pos= tableoids[curr];

        // never know ...we might find something ...
        //
        comp= oid.compareTo(pos);

        if (comp == 0) {
            if (fail)
                throw new SnmpStatusException(failStatus,curr);
            else
                return curr+1;
        }

        if (comp>0) {
            low= curr +1;
        } else {
            max= curr -1;
        }
        curr= low + (max-low)/2;
    }
    return curr;
}
 
Example 6
Source File: SnmpRequestTree.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private static int getInsertionPoint(SnmpOid[] oids, int count,
                                     SnmpOid oid) {
    final SnmpOid[] localoids = oids;
    final int size = count;
    int low= 0;
    int max= size - 1;
    int curr= low + (max-low)/2;


    while (low <= max) {

        final SnmpOid pos = localoids[curr];

        // never know ...we might find something ...
        //
        final int comp= oid.compareTo(pos);

        // In the calling method we will have to check for this case...
        //    if (comp == 0)
        //       return -1;
        // Returning curr instead of -1 avoids having to call
        // findOid() first and getInsertionPoint() afterwards.
        // We can simply call getInsertionPoint() and then checks whether
        // there's an OID at the returned position which equals the
        // given OID.
        if (comp == 0)
            return curr;

        if (comp>0) {
            low= curr +1;
        } else {
            max= curr -1;
        }
        curr= low + (max-low)/2;
    }
    return curr;
}
 
Example 7
Source File: SnmpMibTable.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Search the position at which the given oid should be inserted
 * in the OID table (tableoids).
 *
 * <p>
 * @param oid The OID we would like to insert.
 *
 * @param fail Tells whether a SnmpStatusException must be generated
 *             if the given OID is already present in the table.
 *
 * @return The position at which the OID should be inserted in
 *         the table. When the OID is found, it returns the next
 *         position. Note that it is not valid to insert twice the
 *         same OID. This feature is only an optimization to improve
 *         the getNextOid() behaviour.
 *
 * @exception SnmpStatusException if the OID is already present in the
 *            table and <code>fail</code> is <code>true</code>.
 *
 **/
private int getInsertionPoint(SnmpOid oid, boolean fail)
    throws SnmpStatusException {

    final int failStatus = SnmpStatusException.snmpRspNotWritable;
    int low= 0;
    int max= size - 1;
    SnmpOid pos;
    int comp;
    int curr= low + (max-low)/2;
    while (low <= max) {

        // XX pos= (SnmpOid) oids.elementAt(curr);
        pos= tableoids[curr];

        // never know ...we might find something ...
        //
        comp= oid.compareTo(pos);

        if (comp == 0) {
            if (fail)
                throw new SnmpStatusException(failStatus,curr);
            else
                return curr+1;
        }

        if (comp>0) {
            low= curr +1;
        } else {
            max= curr -1;
        }
        curr= low + (max-low)/2;
    }
    return curr;
}
 
Example 8
Source File: SnmpRequestTree.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static int getInsertionPoint(SnmpOid[] oids, int count,
                                     SnmpOid oid) {
    final SnmpOid[] localoids = oids;
    final int size = count;
    int low= 0;
    int max= size - 1;
    int curr= low + (max-low)/2;


    while (low <= max) {

        final SnmpOid pos = localoids[curr];

        // never know ...we might find something ...
        //
        final int comp= oid.compareTo(pos);

        // In the calling method we will have to check for this case...
        //    if (comp == 0)
        //       return -1;
        // Returning curr instead of -1 avoids having to call
        // findOid() first and getInsertionPoint() afterwards.
        // We can simply call getInsertionPoint() and then checks whether
        // there's an OID at the returned position which equals the
        // given OID.
        if (comp == 0)
            return curr;

        if (comp>0) {
            low= curr +1;
        } else {
            max= curr -1;
        }
        curr= low + (max-low)/2;
    }
    return curr;
}
 
Example 9
Source File: SnmpRequestTree.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private static int getInsertionPoint(SnmpOid[] oids, int count,
                                     SnmpOid oid) {
    final SnmpOid[] localoids = oids;
    final int size = count;
    int low= 0;
    int max= size - 1;
    int curr= low + (max-low)/2;


    while (low <= max) {

        final SnmpOid pos = localoids[curr];

        // never know ...we might find something ...
        //
        final int comp= oid.compareTo(pos);

        // In the calling method we will have to check for this case...
        //    if (comp == 0)
        //       return -1;
        // Returning curr instead of -1 avoids having to call
        // findOid() first and getInsertionPoint() afterwards.
        // We can simply call getInsertionPoint() and then checks whether
        // there's an OID at the returned position which equals the
        // given OID.
        if (comp == 0)
            return curr;

        if (comp>0) {
            low= curr +1;
        } else {
            max= curr -1;
        }
        curr= low + (max-low)/2;
    }
    return curr;
}
 
Example 10
Source File: SnmpMibTable.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Look for the given oid in the OID table (tableoids) and returns
 * its position.
 *
 * <p>
 * @param oid The OID we're looking for.
 *
 * @return The position of the OID in the table. -1 if the given
 *         OID was not found.
 *
 **/
private int findObject(SnmpOid oid) {
    int low= 0;
    int max= size - 1;
    SnmpOid pos;
    int comp;
    int curr= low + (max-low)/2;
    //System.out.println("Try to retrieve: " + oid.toString());
    while (low <= max) {

        // XX pos = (SnmpOid) oids.elementAt(curr);
        pos = tableoids[curr];

        //System.out.println("Compare with" + pos.toString());
        // never know ...we might find something ...
        //
        comp = oid.compareTo(pos);
        if (comp == 0)
            return curr;

        if (oid.equals(pos) == true) {
            return curr;
        }
        if (comp > 0) {
            low = curr + 1;
        } else {
            max = curr - 1;
        }
        curr = low + (max-low)/2;
    }
    return -1;
}
 
Example 11
Source File: SnmpMibTable.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Search the position at which the given oid should be inserted
 * in the OID table (tableoids).
 *
 * <p>
 * @param oid The OID we would like to insert.
 *
 * @param fail Tells whether a SnmpStatusException must be generated
 *             if the given OID is already present in the table.
 *
 * @return The position at which the OID should be inserted in
 *         the table. When the OID is found, it returns the next
 *         position. Note that it is not valid to insert twice the
 *         same OID. This feature is only an optimization to improve
 *         the getNextOid() behaviour.
 *
 * @exception SnmpStatusException if the OID is already present in the
 *            table and <code>fail</code> is <code>true</code>.
 *
 **/
private int getInsertionPoint(SnmpOid oid, boolean fail)
    throws SnmpStatusException {

    final int failStatus = SnmpStatusException.snmpRspNotWritable;
    int low= 0;
    int max= size - 1;
    SnmpOid pos;
    int comp;
    int curr= low + (max-low)/2;
    while (low <= max) {

        // XX pos= (SnmpOid) oids.elementAt(curr);
        pos= tableoids[curr];

        // never know ...we might find something ...
        //
        comp= oid.compareTo(pos);

        if (comp == 0) {
            if (fail)
                throw new SnmpStatusException(failStatus,curr);
            else
                return curr+1;
        }

        if (comp>0) {
            low= curr +1;
        } else {
            max= curr -1;
        }
        curr= low + (max-low)/2;
    }
    return curr;
}
 
Example 12
Source File: SnmpMibTable.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * Look for the given oid in the OID table (tableoids) and returns
 * its position.
 *
 * <p>
 * @param oid The OID we're looking for.
 *
 * @return The position of the OID in the table. -1 if the given
 *         OID was not found.
 *
 **/
private int findObject(SnmpOid oid) {
    int low= 0;
    int max= size - 1;
    SnmpOid pos;
    int comp;
    int curr= low + (max-low)/2;
    //System.out.println("Try to retrieve: " + oid.toString());
    while (low <= max) {

        // XX pos = (SnmpOid) oids.elementAt(curr);
        pos = tableoids[curr];

        //System.out.println("Compare with" + pos.toString());
        // never know ...we might find something ...
        //
        comp = oid.compareTo(pos);
        if (comp == 0)
            return curr;

        if (oid.equals(pos) == true) {
            return curr;
        }
        if (comp > 0) {
            low = curr + 1;
        } else {
            max = curr - 1;
        }
        curr = low + (max-low)/2;
    }
    return -1;
}
 
Example 13
Source File: SnmpRequestTree.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
private static int findOid(SnmpOid[] oids, int count, SnmpOid oid) {
    final int size = count;
    int low= 0;
    int max= size - 1;
    int curr= low + (max-low)/2;
    //System.out.println("Try to retrieve: " + oid.toString());
    while (low <= max) {

        final SnmpOid pos = oids[curr];

        //System.out.println("Compare with" + pos.toString());
        // never know ...we might find something ...
        //
        final int comp = oid.compareTo(pos);
        if (comp == 0)
            return curr;

        if (oid.equals(pos)) {
            return curr;
        }
        if (comp > 0) {
            low = curr + 1;
        } else {
            max = curr - 1;
        }
        curr = low + (max-low)/2;
    }
    return -1;
}
 
Example 14
Source File: SnmpMibTable.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Search the position at which the given oid should be inserted
 * in the OID table (tableoids).
 *
 * <p>
 * @param oid The OID we would like to insert.
 *
 * @param fail Tells whether a SnmpStatusException must be generated
 *             if the given OID is already present in the table.
 *
 * @return The position at which the OID should be inserted in
 *         the table. When the OID is found, it returns the next
 *         position. Note that it is not valid to insert twice the
 *         same OID. This feature is only an optimization to improve
 *         the getNextOid() behaviour.
 *
 * @exception SnmpStatusException if the OID is already present in the
 *            table and <code>fail</code> is <code>true</code>.
 *
 **/
private int getInsertionPoint(SnmpOid oid, boolean fail)
    throws SnmpStatusException {

    final int failStatus = SnmpStatusException.snmpRspNotWritable;
    int low= 0;
    int max= size - 1;
    SnmpOid pos;
    int comp;
    int curr= low + (max-low)/2;
    while (low <= max) {

        // XX pos= (SnmpOid) oids.elementAt(curr);
        pos= tableoids[curr];

        // never know ...we might find something ...
        //
        comp= oid.compareTo(pos);

        if (comp == 0) {
            if (fail)
                throw new SnmpStatusException(failStatus,curr);
            else
                return curr+1;
        }

        if (comp>0) {
            low= curr +1;
        } else {
            max= curr -1;
        }
        curr= low + (max-low)/2;
    }
    return curr;
}
 
Example 15
Source File: SnmpMibTable.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Look for the given oid in the OID table (tableoids) and returns
 * its position.
 *
 * <p>
 * @param oid The OID we're looking for.
 *
 * @return The position of the OID in the table. -1 if the given
 *         OID was not found.
 *
 **/
private int findObject(SnmpOid oid) {
    int low= 0;
    int max= size - 1;
    SnmpOid pos;
    int comp;
    int curr= low + (max-low)/2;
    //System.out.println("Try to retrieve: " + oid.toString());
    while (low <= max) {

        // XX pos = (SnmpOid) oids.elementAt(curr);
        pos = tableoids[curr];

        //System.out.println("Compare with" + pos.toString());
        // never know ...we might find something ...
        //
        comp = oid.compareTo(pos);
        if (comp == 0)
            return curr;

        if (oid.equals(pos) == true) {
            return curr;
        }
        if (comp > 0) {
            low = curr + 1;
        } else {
            max = curr - 1;
        }
        curr = low + (max-low)/2;
    }
    return -1;
}
 
Example 16
Source File: SnmpRequestTree.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static int findOid(SnmpOid[] oids, int count, SnmpOid oid) {
    final int size = count;
    int low= 0;
    int max= size - 1;
    int curr= low + (max-low)/2;
    //System.out.println("Try to retrieve: " + oid.toString());
    while (low <= max) {

        final SnmpOid pos = oids[curr];

        //System.out.println("Compare with" + pos.toString());
        // never know ...we might find something ...
        //
        final int comp = oid.compareTo(pos);
        if (comp == 0)
            return curr;

        if (oid.equals(pos)) {
            return curr;
        }
        if (comp > 0) {
            low = curr + 1;
        } else {
            max = curr - 1;
        }
        curr = low + (max-low)/2;
    }
    return -1;
}
 
Example 17
Source File: SnmpCachedData.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public int compare(SnmpOid o1, SnmpOid o2) {
    return o1.compareTo(o2);
}
 
Example 18
Source File: SnmpCachedData.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public int compare(SnmpOid o1, SnmpOid o2) {
    return o1.compareTo(o2);
}
 
Example 19
Source File: SnmpRequestTree.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public void addVarbind(SnmpVarBind varbind, SnmpOid entryoid,
                               boolean isnew, SnmpVarBind statusvb)
            throws SnmpStatusException {
            Vector<SnmpVarBind> v = null;
            SnmpVarBind rs = statusvb;

            if (entryoids == null) {
//              entryoids = new ArrayList();
//              entrylists = new ArrayList();
//              isentrynew = new ArrayList();
                v = new Vector<>();
//              entryoids.add(entryoid);
//              entrylists.add(v);
//              isentrynew.add(new Boolean(isnew));
                add(0,entryoid,v,isnew,rs);
            } else {
                // int pos = findOid(entryoids,entryoid);
                // int pos = findOid(entryoids,entrycount,entryoid);
                final int pos =
                    getInsertionPoint(entryoids,entrycount,entryoid);
                if (pos > -1 && pos < entrycount &&
                    entryoid.compareTo(entryoids[pos]) == 0) {
                    v  = entrylists[pos];
                    rs = rowstatus[pos];
                } else {
                    // if (pos == -1 || pos >= entryoids.size() ) {
                    // if (pos == -1 || pos >= entrycount ) {
                    // pos = getInsertionPoint(entryoids,entryoid);
                    // pos = getInsertionPoint(entryoids,entrycount,entryoid);
                    v = new Vector<>();
//                  entryoids.add(pos,entryoid);
//                  entrylists.add(pos,v);
//                  isentrynew.add(pos,new Boolean(isnew));
                    add(pos,entryoid,v,isnew,rs);
                }
//              } else v = (Vector) entrylists.get(pos);
                    // } else v = entrylists[pos];
                if (statusvb != null) {
                    if ((rs != null) && (rs != statusvb) &&
                        ((type == SnmpDefinitions.pduWalkRequest) ||
                         (type == SnmpDefinitions.pduSetRequestPdu))) {
                        throw new SnmpStatusException(
                              SnmpStatusException.snmpRspInconsistentValue);
                    }
                    rowstatus[pos] = statusvb;
                }
            }

            // We do not include the status variable in the varbind,
            // because we're going to set it separately...
            //
            if (statusvb != varbind)
                v.addElement(varbind);
        }
 
Example 20
Source File: SnmpRequestTree.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public void addVarbind(SnmpVarBind varbind, SnmpOid entryoid,
                               boolean isnew, SnmpVarBind statusvb)
            throws SnmpStatusException {
            Vector<SnmpVarBind> v = null;
            SnmpVarBind rs = statusvb;

            if (entryoids == null) {
//              entryoids = new ArrayList();
//              entrylists = new ArrayList();
//              isentrynew = new ArrayList();
                v = new Vector<>();
//              entryoids.add(entryoid);
//              entrylists.add(v);
//              isentrynew.add(new Boolean(isnew));
                add(0,entryoid,v,isnew,rs);
            } else {
                // int pos = findOid(entryoids,entryoid);
                // int pos = findOid(entryoids,entrycount,entryoid);
                final int pos =
                    getInsertionPoint(entryoids,entrycount,entryoid);
                if (pos > -1 && pos < entrycount &&
                    entryoid.compareTo(entryoids[pos]) == 0) {
                    v  = entrylists[pos];
                    rs = rowstatus[pos];
                } else {
                    // if (pos == -1 || pos >= entryoids.size() ) {
                    // if (pos == -1 || pos >= entrycount ) {
                    // pos = getInsertionPoint(entryoids,entryoid);
                    // pos = getInsertionPoint(entryoids,entrycount,entryoid);
                    v = new Vector<>();
//                  entryoids.add(pos,entryoid);
//                  entrylists.add(pos,v);
//                  isentrynew.add(pos,new Boolean(isnew));
                    add(pos,entryoid,v,isnew,rs);
                }
//              } else v = (Vector) entrylists.get(pos);
                    // } else v = entrylists[pos];
                if (statusvb != null) {
                    if ((rs != null) && (rs != statusvb) &&
                        ((type == SnmpDefinitions.pduWalkRequest) ||
                         (type == SnmpDefinitions.pduSetRequestPdu))) {
                        throw new SnmpStatusException(
                              SnmpStatusException.snmpRspInconsistentValue);
                    }
                    rowstatus[pos] = statusvb;
                }
            }

            // We do not include the status variable in the varbind,
            // because we're going to set it separately...
            //
            if (statusvb != varbind)
                v.addElement(varbind);
        }