KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > barracuda > core > comp > DefaultItemMap


1 /*
2  * Copyright (C) 2003 Christian Cryder [christianc@granitepeaks.com]
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * $Id: DefaultItemMap.java,v 1.8 2004/02/01 05:16:27 christianc Exp $
19  */

20 package org.enhydra.barracuda.core.comp;
21
22 import java.util.*;
23
24
25 /**
26  * An ItemMap can be returned by the getItem() methods within any of
27  * the model implementations. It is used to associate a key with a
28  * particular value. It is primarily used by the BSelect component
29  * (which can use both key and value information when rendering).
30  * The other components just use the value information.
31  */

32 public class DefaultItemMap implements ItemMap {
33
34     protected Object JavaDoc key = null;
35     protected Object JavaDoc value = null;
36
37     /**
38      * Create a new DefaultItemMap with the given key
39      * and value
40      *
41      * @param ikey an int key
42      * @param ivalue the object value
43      */

44     public DefaultItemMap(int ikey, Object JavaDoc ivalue) {
45         key = new Integer JavaDoc(ikey);
46         value = ivalue;
47     }
48
49     /**
50      * Create a new DefaultItemMap with the given key
51      * and value
52      *
53      * @param ikey an Integer key
54      * @param ivalue the object value
55      */

56     public DefaultItemMap(Object JavaDoc ikey, Object JavaDoc ivalue) {
57         key = ikey;
58         value = ivalue;
59     }
60
61     /**
62      * Returns the key corresponding to this entry.
63      */

64     public Object JavaDoc getKey() {
65         return key;
66     }
67
68     /**
69      * Returns the value corresponding to this entry.
70      */

71     public Object JavaDoc getValue() {
72         return value;
73     }
74
75     /**
76      * Replaces the value corresponding to this entry with the specified
77      * value (optional operation).
78      */

79     public Object JavaDoc setValue(Object JavaDoc ivalue) {
80         value = ivalue;
81         return value;
82     }
83
84     /**
85      * Return a String representation of the ItemMap
86      */

87     public String JavaDoc toString() {
88 //csc_071602.1 - modify so that if there is a null value in the item map we don't get a null pointer exception here
89
//csc_071602.1 return value.toString();
90
return (value!=null ? value.toString() : "null"); //csc_071602.1
91
}
92
93 }
Popular Tags