KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > triactive > jdo > state > StateFieldManager


1 /*
2  * Copyright 2004 (C) TJDO.
3  * All rights reserved.
4  *
5  * This software is distributed under the terms of the TJDO License version 1.0.
6  * See the terms of the TJDO License in the documentation provided with this software.
7  *
8  * $Id: StateFieldManager.java,v 1.2 2004/01/18 03:01:06 jackknifebarber Exp $
9  */

10
11 package com.triactive.jdo.state;
12
13 import com.triactive.jdo.GenericFieldManager;
14 import java.util.ArrayList JavaDoc;
15
16
17 /**
18  * A simple field manager that stores/fetches field values in memory.
19  * <p>
20  * Calls to the store methods save the value in a local array; calls to the
21  * fetch methods return the previously stored value for that field, or the
22  * "empty" default value if nothing has been stored.
23  *
24  * @author <a HREF="mailto:mmartin5@austin.rr.com">Mike Martin</a>
25  * @version $Revision: 1.2 $
26  */

27
28 class StateFieldManager extends GenericFieldManager
29 {
30     private final ArrayList JavaDoc values = new ArrayList JavaDoc();
31
32
33     public void storeObjectField(int fieldNum, Object JavaDoc value)
34     {
35         while (values.size() <= fieldNum)
36             values.add(null);
37
38         values.set(fieldNum, value);
39     }
40
41     public Object JavaDoc fetchObjectField(int fieldNum)
42     {
43         if (fieldNum < values.size())
44             return values.get(fieldNum);
45         else
46             return null;
47     }
48 }
49
Popular Tags