001: /**********************************************************************
002: Copyright (c) 2002 Kelly Grizzle (TJDO) and others. All rights reserved.
003: Licensed under the Apache License, Version 2.0 (the "License");
004: you may not use this file except in compliance with the License.
005: You may obtain a copy of the License at
006:
007: http://www.apache.org/licenses/LICENSE-2.0
008:
009: Unless required by applicable law or agreed to in writing, software
010: distributed under the License is distributed on an "AS IS" BASIS,
011: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012: See the License for the specific language governing permissions and
013: limitations under the License.
014:
015: Contributors:
016: 2002 Mike Martin - unknown changes
017: 2003 Andy Jefferson - commented
018: ...
019: **********************************************************************/package org.jpox.store.fieldmanager;
020:
021: /**
022: * A simple field manager that stores/fetches a single field value per type
023: * in memory.
024: * <p>
025: * Calls to the store methods save the value in a local field; calls to the
026: * fetch methods return the previously stored value for that type, or the
027: * "empty" default value if nothing has been stored.
028: * <p>
029: * The field number arguments to each method are ignored.
030: *
031: * @version $Revision: 1.2 $
032: */
033: public class SingleTypeFieldManager implements FieldManager {
034: private boolean booleanValue = false;
035: private char charValue = 0;
036: private byte byteValue = 0;
037: private short shortValue = 0;
038: private int intValue = 0;
039: private long longValue = 0;
040: private float floatValue = 0;
041: private double doubleValue = 0;
042: private String stringValue = null;
043: private Object objectValue = null;
044:
045: /**
046: * Default Constructor.
047: **/
048: public SingleTypeFieldManager() {
049: //default constructor
050: }
051:
052: /**
053: * Constructor.
054: * @param booleanValue Boolean
055: **/
056: public SingleTypeFieldManager(boolean booleanValue) {
057: this .booleanValue = booleanValue;
058: }
059:
060: /**
061: * Constructor.
062: * @param charValue char
063: **/
064: public SingleTypeFieldManager(char charValue) {
065: this .charValue = charValue;
066: }
067:
068: /**
069: * Constructor.
070: * @param byteValue byte
071: **/
072: public SingleTypeFieldManager(byte byteValue) {
073: this .byteValue = byteValue;
074: }
075:
076: /**
077: * Constructor.
078: * @param shortValue short
079: **/
080: public SingleTypeFieldManager(short shortValue) {
081: this .shortValue = shortValue;
082: }
083:
084: /**
085: * Constructor.
086: * @param intValue int
087: **/
088: public SingleTypeFieldManager(int intValue) {
089: this .intValue = intValue;
090: }
091:
092: /**
093: * Constructor.
094: * @param longValue Long
095: **/
096: public SingleTypeFieldManager(long longValue) {
097: this .longValue = longValue;
098: }
099:
100: /**
101: * Constructor.
102: * @param floatValue Float
103: **/
104: public SingleTypeFieldManager(float floatValue) {
105: this .floatValue = floatValue;
106: }
107:
108: /**
109: * Constructor.
110: * @param doubleValue Double
111: **/
112: public SingleTypeFieldManager(double doubleValue) {
113: this .doubleValue = doubleValue;
114: }
115:
116: /**
117: * Constructor.
118: * @param stringValue String
119: **/
120: public SingleTypeFieldManager(String stringValue) {
121: this .stringValue = stringValue;
122: }
123:
124: /**
125: * Constructor.
126: * @param objectValue Object
127: **/
128: public SingleTypeFieldManager(Object objectValue) {
129: this .objectValue = objectValue;
130: }
131:
132: /**
133: * Mutator for boolean field.
134: * @param fieldNum Number of field
135: * @param value Value
136: **/
137: public void storeBooleanField(int fieldNum, boolean value) {
138: booleanValue = value;
139: }
140:
141: /**
142: * Accessor for boolean field.
143: * @param fieldNum Number of field
144: * @return Boolean value
145: **/
146: public boolean fetchBooleanField(int fieldNum) {
147: return booleanValue;
148: }
149:
150: /**
151: * Mutator for char field.
152: * @param fieldNum Number of field
153: * @param value Value
154: **/
155: public void storeCharField(int fieldNum, char value) {
156: charValue = value;
157: }
158:
159: /**
160: * Accessor for char field.
161: * @param fieldNum Number of field
162: * @return Char value
163: **/
164: public char fetchCharField(int fieldNum) {
165: return charValue;
166: }
167:
168: /**
169: * Mutator for byte field.
170: * @param fieldNum Number of field
171: * @param value Value
172: **/
173: public void storeByteField(int fieldNum, byte value) {
174: byteValue = value;
175: }
176:
177: /**
178: * Accessor for byte field.
179: * @param fieldNum Number of field
180: * @return Byte value
181: **/
182: public byte fetchByteField(int fieldNum) {
183: return byteValue;
184: }
185:
186: /**
187: * Mutator for short field.
188: * @param fieldNum Number of field
189: * @param value Value
190: **/
191: public void storeShortField(int fieldNum, short value) {
192: shortValue = value;
193: }
194:
195: /**
196: * Accessor for short field.
197: * @param fieldNum Number of field
198: * @return Short value
199: **/
200: public short fetchShortField(int fieldNum) {
201: return shortValue;
202: }
203:
204: /**
205: * Mutator for int field.
206: * @param fieldNum Number of field
207: * @param value Value
208: **/
209: public void storeIntField(int fieldNum, int value) {
210: intValue = value;
211: }
212:
213: /**
214: * Accessor for int field.
215: * @param fieldNum Number of field
216: * @return Int value
217: **/
218: public int fetchIntField(int fieldNum) {
219: return intValue;
220: }
221:
222: /**
223: * Mutator for long field.
224: * @param fieldNum Number of field
225: * @param value Value
226: **/
227: public void storeLongField(int fieldNum, long value) {
228: longValue = value;
229: }
230:
231: /**
232: * Accessor for long field.
233: * @param fieldNum Number of field
234: * @return Long value
235: **/
236: public long fetchLongField(int fieldNum) {
237: return longValue;
238: }
239:
240: /**
241: * Mutator for float field.
242: * @param fieldNum Number of field
243: * @param value Value
244: **/
245: public void storeFloatField(int fieldNum, float value) {
246: floatValue = value;
247: }
248:
249: /**
250: * Accessor for float field.
251: * @param fieldNum Number of field
252: * @return Float value
253: **/
254: public float fetchFloatField(int fieldNum) {
255: return floatValue;
256: }
257:
258: /**
259: * Mutator for double field.
260: * @param fieldNum Number of field
261: * @param value Value
262: **/
263: public void storeDoubleField(int fieldNum, double value) {
264: doubleValue = value;
265: }
266:
267: /**
268: * Accessor for double field.
269: * @param fieldNum Number of field
270: * @return Double value
271: **/
272: public double fetchDoubleField(int fieldNum) {
273: return doubleValue;
274: }
275:
276: /**
277: * Mutator for String field.
278: * @param fieldNum Number of field
279: * @param value Value
280: **/
281: public void storeStringField(int fieldNum, String value) {
282: stringValue = value;
283: }
284:
285: /**
286: * Accessor for string field.
287: * @param fieldNum Number of field
288: * @return String value
289: **/
290: public String fetchStringField(int fieldNum) {
291: return stringValue;
292: }
293:
294: /**
295: * Mutator for Object field.
296: * @param fieldNum Number of field
297: * @param value Value
298: **/
299: public void storeObjectField(int fieldNum, Object value) {
300: objectValue = value;
301: }
302:
303: /**
304: * Accessor for object field.
305: * @param fieldNum Number of field
306: * @return Object value
307: **/
308: public Object fetchObjectField(int fieldNum) {
309: return objectValue;
310: }
311: }
|