~pbms-core/pbms/async_read

« back to all changes in this revision

Viewing changes to mybs/java/src/org/blobstreaming/www/PropertyList.java

  • Committer: paul-mccullagh
  • Date: 2008-03-26 11:35:17 UTC
  • Revision ID: paul-mccullagh-afb1610c21464a577ae428d72fc725eb986c05a5
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (c) 2007 SNAP Innovation GmbH
 
2
 *
 
3
 * BLOB Streaming for MySQL
 
4
 *
 
5
 * This program is free software; you can redistribute it and/or modify
 
6
 * it under the terms of the GNU General Public License as published by
 
7
 * the Free Software Foundation; either version 2 of the License, or
 
8
 * (at your option) any later version.
 
9
 *
 
10
 * This program is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program; if not, write to the Free Software
 
17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 
18
 *
 
19
 * Paul McCullagh
 
20
 *
 
21
 * 2007-07-30
 
22
 *
 
23
 * H&G2JCtL
 
24
 *
 
25
 * Property List
 
26
 *
 
27
 */
 
28
 
 
29
package org.blobstreaming.www;
 
30
 
 
31
import java.util.Vector;
 
32
 
 
33
class PropertyList {
 
34
        class Property {
 
35
                public String   key;
 
36
                public String   value;
 
37
                
 
38
                public Property(String k, String v)
 
39
                {
 
40
                        this.key = k;
 
41
                        this.value = v;
 
42
                }
 
43
        }
 
44
 
 
45
        Vector properties;
 
46
 
 
47
        public PropertyList()
 
48
        {
 
49
                super();
 
50
                properties = new Vector();
 
51
        }
 
52
 
 
53
        /**
 
54
         * Removes all the properties from the list.
 
55
         */
 
56
        public void removeAll()
 
57
        {
 
58
                properties.clear();
 
59
        }
 
60
 
 
61
        /**
 
62
         * Returns the number of properties in the list.
 
63
         */
 
64
        public int length()
 
65
        {
 
66
                return(properties.size());
 
67
        }
 
68
 
 
69
        /**
 
70
         * Find a property with the given key. If the key
 
71
         * is an int then it is used as an index.
 
72
         * null will be returned if the property is not
 
73
         * found.
 
74
         */
 
75
        protected Property findProperty(String key)
 
76
        {
 
77
                Property        p = null;
 
78
                int                     i;
 
79
 
 
80
                for (i=0; i<properties.size(); i++) {
 
81
                        p = (Property) properties.get(i);
 
82
                        if (p.key.equalsIgnoreCase(key))
 
83
                                break;
 
84
                        p = null;
 
85
                }
 
86
                return p;
 
87
        }
 
88
 
 
89
        protected Property findProperty(int i)
 
90
        {
 
91
                Property        p = null;
 
92
 
 
93
                if (i < properties.size())
 
94
                        p = (Property) properties.get(i);
 
95
                return p;
 
96
        }
 
97
 
 
98
        /**
 
99
         * Set a property with the given key to a specified
 
100
         * value. If the key
 
101
         * is an int then it is used as an index.
 
102
         */
 
103
        public void setProperty(String key, String value)
 
104
        {
 
105
                Property p;
 
106
 
 
107
                if ((p = findProperty(key)) != null)
 
108
                        p.value = value;
 
109
                else
 
110
                        properties.add(new Property(key, value));
 
111
        }
 
112
 
 
113
        public void setProperty(String key, int value)
 
114
        {
 
115
                setProperty(key, Integer.toString(value));
 
116
        }
 
117
 
 
118
        public void setProperty(String key, long value)
 
119
        {
 
120
                setProperty(key, Long.toString(value));
 
121
        }
 
122
 
 
123
        /**
 
124
         * Get a property with the given key. If the key
 
125
         * is an int then it is used as an index.
 
126
         */
 
127
        public String getProperty(String key)
 
128
        {
 
129
                Property p;
 
130
 
 
131
                if ((p = findProperty(key)) != null)
 
132
                        return(p.value);
 
133
                return(null);
 
134
        }
 
135
 
 
136
        public String getProperty(int i)
 
137
        {
 
138
                Property p;
 
139
 
 
140
                if ((p = findProperty(i)) != null)
 
141
                        return(p.value);
 
142
                return(null);
 
143
        }
 
144
 
 
145
        public String getPropertyKey(int i)
 
146
        {
 
147
                Property p;
 
148
 
 
149
                if ((p = findProperty(i)) != null)
 
150
                        return(p.key);
 
151
                return(null);
 
152
        }
 
153
}
 
154