001: /*
002: /*
003: *
004: *
005: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
006: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
007: *
008: * This program is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU General Public License version
010: * 2 only, as published by the Free Software Foundation.
011: *
012: * This program is distributed in the hope that it will be useful, but
013: * WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * General Public License version 2 for more details (a copy is
016: * included at /legal/license.txt).
017: *
018: * You should have received a copy of the GNU General Public License
019: * version 2 along with this work; if not, write to the Free Software
020: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
021: * 02110-1301 USA
022: *
023: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
024: * Clara, CA 95054 or visit www.sun.com if you need additional
025: * information or have any questions.
026: */
027:
028: package com.sun.kvem.midp.pim;
029:
030: import java.util.Vector;
031:
032: /**
033: * Encapsulation of a multi-value PIM field
034: *
035: */
036: class VectorPIMField implements PIMField {
037: /** Array of values. */
038: private final Vector values = new Vector();
039: /** Array of attributes. */
040: private final Vector attributes = new Vector();
041:
042: /**
043: * Adds a value to a PIM field.
044: * @param attributes properties to update
045: * @param value entry to be updated
046: */
047: public void addValue(int attributes, Object value) {
048: this .values.addElement(value);
049: this .attributes.addElement(new Integer(attributes));
050: }
051:
052: /**
053: * Gets the value of the field.
054: * @param index element index
055: * @return field value
056: */
057: public Object getValue(int index) {
058: return values.elementAt(index);
059: }
060:
061: /**
062: * Sets the value of the field.
063: * @param attributes field attributes requested
064: * @param value new value for field
065: * @param index element identifier
066: */
067: public void setValue(int attributes, Object value, int index) {
068: this .values.setElementAt(value, index);
069: this .attributes.setElementAt(new Integer(attributes), index);
070: }
071:
072: /**
073: * Gets the field attributes.
074: * @param index element identifier
075: * @return encoded attributes
076: */
077: public int getAttributes(int index) {
078: return ((Integer) attributes.elementAt(index)).intValue();
079: }
080:
081: /**
082: * Checks if the field contains data.
083: * @return <code>true</code> if field contains data
084: */
085: public boolean containsData() {
086: return values.size() > 0;
087: }
088:
089: /**
090: * Gets the number of value elements.
091: * @return always returns <code>1</code>
092: */
093: public int getValueCount() {
094: return values.size();
095: }
096:
097: /**
098: * Removes a value element.
099: * @param index identifier for value to remove
100: */
101: public void removeValue(int index) {
102: this .values.removeElementAt(index);
103: this .attributes.removeElementAt(index);
104: }
105:
106: /**
107: * Checks if field has scalar value.
108: * @return always returns <code>true</code>
109: */
110: public boolean isScalar() {
111: return false;
112: }
113:
114: }
|