KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis > transport > jms > MapUtils


1 /*
2  * Copyright 2001, 2002,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.axis.transport.jms;
18
19 import java.util.Map JavaDoc;
20
21 /**
22  * MapUtils provides convenience methods for accessing a java.util.Map
23  *
24  * @author Jaime Meritt (jmeritt@sonicsoftware.com)
25  * @author Richard Chung (rchung@sonicsoftware.com)
26  * @author Dave Chappell (chappell@sonicsoftware.com)
27  */

28 public class MapUtils
29 {
30     /**
31      * Returns an int property from a Map and removes it.
32      *
33      * @param properties
34      * @param key
35      * @param defaultValue
36      * @return
37      */

38     public static int removeIntProperty(Map JavaDoc properties, String JavaDoc key, int defaultValue)
39     {
40         int value = defaultValue;
41         if(properties != null && properties.containsKey(key))
42         {
43             try{value = ((Integer JavaDoc)properties.remove(key)).intValue();}catch(Exception JavaDoc ignore){}
44         }
45         return value;
46     }
47
48     /**
49      * Returns a long property from a Map and removes it.
50      *
51      * @param properties
52      * @param key
53      * @param defaultValue
54      * @return
55      */

56     public static long removeLongProperty(Map JavaDoc properties, String JavaDoc key, long defaultValue)
57     {
58         long value = defaultValue;
59         if(properties != null && properties.containsKey(key))
60         {
61             try{value = ((Long JavaDoc)properties.remove(key)).longValue();}catch(Exception JavaDoc ignore){}
62         }
63         return value;
64     }
65
66     /**
67      * Returns a String property from a Map and removes it.
68      *
69      * @param properties
70      * @param key
71      * @param defaultValue
72      * @return
73      */

74     public static String JavaDoc removeStringProperty(Map JavaDoc properties, String JavaDoc key, String JavaDoc defaultValue)
75     {
76         String JavaDoc value = defaultValue;
77         if(properties != null && properties.containsKey(key))
78         {
79             try{value = (String JavaDoc)properties.remove(key);}catch(Exception JavaDoc ignore){}
80         }
81         return value;
82     }
83
84     /**
85      * Returns a boolean property from a Map and removes it.
86      *
87      * @param properties
88      * @param key
89      * @param defaultValue
90      * @return
91      */

92     public static boolean removeBooleanProperty(Map JavaDoc properties, String JavaDoc key, boolean defaultValue)
93     {
94         boolean value = defaultValue;
95         if(properties != null && properties.containsKey(key))
96         {
97             try{value = ((Boolean JavaDoc)properties.remove(key)).booleanValue();}catch(Exception JavaDoc ignore){}
98         }
99         return value;
100     }
101
102     /**
103      * Returns an Object property from a Map and removes it.
104      *
105      * @param properties
106      * @param key
107      * @param defaultValue
108      * @return
109      */

110     public static Object JavaDoc removeObjectProperty(Map JavaDoc properties, String JavaDoc key, Object JavaDoc defaultValue)
111     {
112         Object JavaDoc value = defaultValue;
113         if(properties != null && properties.containsKey(key))
114         {
115             value = properties.remove(key);
116         }
117         return value;
118     }
119 }
120
Popular Tags