📄 snmpvarbindlist.java
字号:
public synchronized void addVarBind(String list[]) throws SnmpStatusException { addVarBind(list, null) ; } /** * Removes the array of SNMP MIB variables from the existing <CODE>SnmpVarBindList</CODE>. * @param list Array of strings containing MIB variable names. * @return <CODE>true</CODE> if all the SNMP MIB variables were components of this <CODE>SnmpVarBindList</CODE>, * <CODE>false</CODE> otherwise. * @exception SnmpStatusException An error occurred while accessing a MIB node. */ public synchronized boolean removeVarBind(String list[]) throws SnmpStatusException { return removeVarBind(list, null) ; } /** * Creates an <CODE>SnmpVarBind</CODE> object from the given MIB variable and appends it to the existing * <CODE>SnmpVarBindList</CODE>. * It creates a new <CODE>SnmpVarBindList</CODE> if one did not exist. * @param name A MIB variable name. * @exception SnmpStatusException An error occurred while accessing a MIB node. */ public synchronized void addVarBind(String name) throws SnmpStatusException { SnmpVarBind avar ; avar = new SnmpVarBind(name) ; addVarBind(avar) ; } /** * Removes the <CODE>SnmpVarBind</CODE> object corresponding to the given MIB variable from the existing * <CODE>SnmpVarBindList</CODE>. * @param name A MIB variable name. * @return <CODE>true</CODE> if the SNMP MIB variable was a component of this <CODE>SnmpVarBindList</CODE>, * <CODE>false</CODE> otherwise. * @exception SnmpStatusException An error occurred while accessing a MIB node. */ public synchronized boolean removeVarBind(String name) throws SnmpStatusException { SnmpVarBind avar ; int indexOid ; avar = new SnmpVarBind(name) ; indexOid = indexOfOid(avar) ; try { removeElementAt(indexOid) ; return true ; } catch (ArrayIndexOutOfBoundsException e) { return false ; } } /** * Appends the given <CODE>SnmpVarBind</CODE> object to the existing <CODE>SnmpVarBindList</CODE>. * It creates a new <CODE>SnmpVarBindList</CODE> if one did not exist. * @param var The <CODE>SnmpVarBind</CODE> object to be appended. */ public synchronized void addVarBind(SnmpVarBind var) { addElement(var) ; } /** * Removes the given <CODE>SnmpVarBind</CODE> object from the existing <CODE>SnmpVarBindList</CODE>. * @param var The <CODE>SnmpVarBind</CODE> object to be removed. * @return <CODE>true</CODE> if the <CODE>SnmpVarBind</CODE> object was a component of this * <CODE>SnmpVarBindList</CODE>, <CODE>false</CODE> otherwise. */ public synchronized boolean removeVarBind(SnmpVarBind var) { return removeElement(var) ; } /** * Adds the string as an instance part to all OIDs in this list. * This method should be used with caution because it affects all OIDs in the list. * @param inst The <CODE>String</CODE> to add as an instance part. * @exception SnmpStatusException An error occurred while accessing a MIB node. */ public synchronized void addInstance(String inst) throws SnmpStatusException { int max= size(); for (int i = 0; i < max; i++) { ((SnmpVarBind)elementData[i]).addInstance(inst) ; } } /** * Adds elements in the specified <CODE>SnmpVarBindList</CODE> to this list. * The elements are not cloned. * @param list A vector of <CODE>SnmpVarBind</CODE>. */ final public synchronized void concat(Vector list) { ensureCapacity(size() + list.size()) ; for (Enumeration e = list.elements() ; e.hasMoreElements() ; ) { addElement(e.nextElement()) ; } } /** * Returns <CODE>false</CODE> if any of the variables does not contain a valid value. * Typically used for <CODE>SnmpSet</CODE> operations. * @return <CODE>false</CODE> if any of the variables does not contain a valid value, <CODE>true</CODE> otherwise. */ public synchronized boolean checkForValidValues() { int max= this.size(); for (int i = 0; i < max ; i++) { SnmpVarBind avar = (SnmpVarBind)elementData[i] ; if (avar.isValidValue() == false) return false ; } return true ; } /** * Returns <CODE>true</CODE> if there is a value that is not specified. * @return <CODE>true</CODE> if there is a value that is not specified, <CODE>false</CODE> otherwise. */ public synchronized boolean checkForUnspecifiedValue() { int max= this.size(); for (int i = 0; i < max ; i++) { SnmpVarBind avar = (SnmpVarBind)elementData[i] ; if (avar.isUnspecifiedValue()) return true ; } return false ; } /** * Splits the <CODE>SnmpVarBindList</CODE>. * @param pos The position at which to split the <CODE>SnmpVarBindList</CODE> * @return The <CODE>SnmpVarBindList</CODE> list from the beginning up to the split position. */ public synchronized SnmpVarBindList splitAt(int pos) { SnmpVarBindList splitVb = null ; if (pos > elementCount) return splitVb ; splitVb = new SnmpVarBindList() ; // size() - atPosition) ; int max= size(); for (int i = pos; i < max ; i++) splitVb.addElement(elementData[i]) ; elementCount = pos ; trimToSize() ; return splitVb ; } /** * Gives the index of an OID in the <CODE>SnmpVarBindList</CODE>. * The index returned must be greater than or equal to the <CODE>start</CODE> parameter * and smaller than the <CODE>end</CODE> parameter. Otherwise the method returns -1. * @param var The <CODE>SnmpVarBind</CODE> object with the requested OID. * @param min The min index in <CODE>SnmpVarBindList</CODE>. * @param max The max index in <CODE>SnmpVarBindList</CODE>. * @return The index of the OID in <CODE>SnmpVarBindList</CODE>. */ public synchronized int indexOfOid(SnmpVarBind var, int min, int max) { SnmpOid oidarg = var.getOid() ; for (int i = min; i < max ; i++) { SnmpVarBind avar = (SnmpVarBind)elementData[i] ; if (oidarg.equals(avar.getOid())) return i ; } return -1 ; } /** * Gives the index of an OID in the <CODE>SnmpVarBindList</CODE>. * @param var The <CODE>SnmpVarBind</CODE> object with the requested OID. * @return The index of the OID in <CODE>SnmpVarBindList</CODE>. */ public synchronized int indexOfOid(SnmpVarBind var) { return indexOfOid(var, 0, size()) ; } /** * Gives the index of an OID in the <CODE>SnmpVarBindList</CODE>. * @param oid The <CODE>SnmpOid</CODE> object with the requested OID. * @return The index of the OID in <CODE>SnmpVarBindList</CODE>. */ public synchronized int indexOfOid(SnmpOid oid) { int max = size(); for (int i = 0; i < max ; i++) { SnmpVarBind avar = (SnmpVarBind)elementData[i] ; if (oid.equals(avar.getOid())) return i ; } return -1 ; } /** * Clones the <CODE>SnmpVarBindList</CODE>. A new copy of the <CODE>SnmpVarBindList</CODE> is created. * It is a real deep copy. * @return The <CODE>SnmpVarBindList</CODE> clone. */ public synchronized SnmpVarBindList cloneWithValue() { SnmpVarBindList newvb = new SnmpVarBindList() ; newvb.setTimestamp(this.getTimestamp()) ; newvb.ensureCapacity(this.size()) ; for (int i = 0; i < this.size() ; i++) { SnmpVarBind avar = (SnmpVarBind)elementData[i] ; newvb.addElement(avar.clone()) ; } return newvb ; } /** * Clones the <CODE>SnmpVarBindList</CODE>. It does not clone the value part of the variable. * It is a deep copy (except for the value portion). * @return The <CODE>SnmpVarBindList</CODE> clone. */ public synchronized SnmpVarBindList cloneWithoutValue() { SnmpVarBindList newvb = new SnmpVarBindList() ; int max = this.size(); newvb.ensureCapacity(max) ; for (int i = 0; i < max ; i++) { SnmpVarBind avar = (SnmpVarBind)elementData[i] ; newvb.addElement(avar.cloneWithoutValue()) ; } return newvb ; } /** * Clones the <CODE>SnmpVarBindList</CODE>. A new copy of the <CODE>SnmpVarBindList</CODE> is created. * It is a real deep copy. * @return The object clone. */ public synchronized Object clone() { return cloneWithValue() ; } /** * Copies the <CODE>SnmpVarBindList</CODE> into a plain vector of <CODE>SnmpVarBind</CODE> objects. * If the <code>copy</code> flag is false, does a shallow copy of the list. Otherwise, * individual elements will be cloned. * @param copy The flag indicating whether each object in the list should be cloned. * @return A new vector of <CODE>SnmpVarBind</CODE> objects. */ public synchronized Vector toVector(boolean copy) { final int count = elementCount; if (copy == false) return (Vector) super.clone(); Vector result = new Vector(count,5); for (int i = 0; i < count ; i++) { SnmpVarBind avar = (SnmpVarBind)elementData[i] ; result.addElement(avar.clone()) ; } return result; } /** * Returns a <CODE>String</CODE> containing the ASCII representation of all OIDs in the list. * @return An ASCII list of all OIDs in this list. */ public String oidListToString() { StringBuffer s = new StringBuffer(300) ; for (int i = 0 ; i < elementCount ; i++) { SnmpVarBind avar = (SnmpVarBind)elementData[i] ; s.append(avar.getOid().toString() + "\n") ; } return s.toString() ; } /** * Constructs a <CODE>String</CODE> containing details of each <CODE>SnmpVarBindList</CODE> (oid+value). * This is typically used in debugging. * @return A detailed <CODE>String</CODE> of all in the <CODE>SnmpVarBindList</CODE>. */ public synchronized String varBindListToString() { StringBuffer s = new StringBuffer(300) ; for (int i = 0; i < elementCount ; i++) { s.append(elementData[i].toString() + "\n") ; } return s.toString() ; } /** * Finalizer of the <CODE>SnmpVarBindList</CODE> objects. * This method is called by the garbage collector on an object * when garbage collection determines that there are no more references to the object. * <P>Removes all the elements from this <CODE>SnmpVarBindList</CODE> object. */ public void finalize() { removeAllElements() ; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -