|
StatsValueList |
|
1 package com.mccrory.scott.spumoni; 2 3 //////////////////////////////////////////////////////////////////////////////// 4 // Copyright (C) 2002 Scott McCrory 5 // 6 // This program is free software; you can redistribute it and/or 7 // modify it under the terms of the GNU General Public License 8 // as published by the Free Software Foundation; either version 2 9 // of the License, or (at your option) any later version. 10 // 11 // This program is distributed in the hope that it will be useful, 12 // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 // GNU General Public License for more details. 15 // 16 // You should have received a copy of the GNU General Public License 17 // along with this program; if not, write to the Free Software 18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 //////////////////////////////////////////////////////////////////////////////// 20 21 import java.io.IOException; 22 import java.io.ObjectInputStream; 23 import java.io.ObjectOutputStream; 24 import java.util.Vector; 25 26 /** 27 * <P><code>StatsValueList</code> is a collection of StatsValue objects. 28 * Includes methods used for operating on that group of objects.</P> 29 * 30 * @author <a href="mailto:smccrory@users.sourceforge.net">Scott McCrory</a>. 31 * @version CVS $Id: StatsValueList.java,v 1.8 2002/08/04 22:04:53 smccrory Exp $ 32 */ 33 public class StatsValueList extends java.util.Vector { 34 35 /** 36 * Basic StatsValueList constructor. 37 */ 38 public StatsValueList() { 39 super(); 40 } 41 42 /** 43 * StatsValueList constructor with preset minimum size. 44 * @param initialCapacity Initial capacity 45 */ 46 public StatsValueList(int initialCapacity) { 47 super(initialCapacity); 48 } 49 50 /** 51 * StatsValueList constructor with preset minimum size and capacity increment. 52 * @param initialCapacity Initial capacity 53 * @param capacityIncrement Capacity increment 54 */ 55 public StatsValueList(int initialCapacity, int capacityIncrement) { 56 super(initialCapacity, capacityIncrement); 57 } 58 59 /** 60 * Convenience constructor for creating a new StatsValueList and populating 61 * it with a single StatsValue. 62 * @param sVal The StatsValue which will be immediately added 63 */ 64 public StatsValueList(StatsValue sVal) { 65 this(); 66 this.add(sVal); 67 } 68 69 /** 70 * Returns a vector of all of the OIDs in the contained StatsValues 71 * @return A vector of all of the OIDs in the contained StatsValues 72 */ 73 public Vector getOids() { 74 75 Vector oids = new Vector(); 76 77 for (int i = 0; i < this.size(); i++) { 78 79 StatsValue sv = (StatsValue) get(i); 80 oids.add(sv.getSnmpOid()); 81 82 } 83 84 return oids; 85 86 } 87 88 /** 89 * Returns a value String corresponding to the specified OID. 90 * @return java.lang.String 91 * @param oid java.lang.String 92 * @exception java.util.NoSuchElementException if the OID isn't found. 93 */ 94 public String getValueByOid(String oid) 95 throws java.util.NoSuchElementException { 96 97 for (int i = 0; i < this.size(); i++) { 98 99 StatsValue sValue = (StatsValue) get(i); 100 if (sValue.getSnmpOid().equals(oid)) { 101 return sValue.getValue(); 102 } 103 104 } 105 106 throw new java.util.NoSuchElementException("OID " + oid + " not found"); 107 108 } 109 110 /** 111 * We override the <code>readObject</code> method here to prevent 112 * deserialization of our class for security reasons. 113 * 114 * @param in java.io.ObjectInputStream 115 * @throws IOException thrown if a problem occurs 116 **/ 117 private final void readObject(ObjectInputStream in) throws IOException { 118 119 throw new IOException("Object cannot be deserialized"); 120 121 } 122 123 /** 124 * Unsets all of the values. 125 * Typically done just before another round of stats collection. 126 */ 127 public void unsetValues() { 128 129 for (int j = 0; j < this.size(); j++) { 130 StatsValue sValue = (StatsValue) get(j); 131 sValue.unset(); 132 } 133 134 } 135 136 /** 137 * We override the <code>writeObject</code> method here to prevent 138 * serialization of our class for security reasons. 139 * 140 * @param out java.io.ObjectOutputStream 141 * @throws IOException thrown if a problem occurs 142 **/ 143 private final void writeObject(ObjectOutputStream out) throws IOException { 144 145 throw new IOException("Object cannot be serialized"); 146 147 } 148 149 }
|
StatsValueList |
|