KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > icl > saxon > ParameterSet


1 package com.icl.saxon;
2 import com.icl.saxon.expr.Value;
3
4
5 /**
6 * A ParameterSet is a set of parameters supplied when calling a template.
7 * It is a collection of name-value pairs
8 */

9
10 public class ParameterSet
11 {
12     private int[] keys = new int[10];
13     private Value[] values = new Value[10];
14     private int used = 0;
15
16
17     /**
18     * Add a parameter to the ParameterSet
19     * @param fingerprint The fingerprint of the parameter name.
20     * @param value The value of the parameter
21     */

22     
23     public void put (int fingerprint, Value value) {
24         for (int i=0; i<used; i++) {
25             if (keys[i]==fingerprint) {
26                 values[i]=value;
27                 return;
28             }
29         }
30         if (used+1 > keys.length) {
31             int[] newkeys = new int[used*2];
32             Value[] newvalues = new Value[used*2];
33             System.arraycopy(values, 0, newvalues, 0, used);
34             System.arraycopy(keys, 0, newkeys, 0, used);
35             values = newvalues;
36             keys = newkeys;
37         }
38         keys[used] = fingerprint;
39         values[used++] = value;
40     }
41
42     /**
43     * Get a parameter
44     * @param fingerprint The fingerprint of the name.
45     * @return The value of the parameter, or null if not defined
46     */

47
48     public Value get (int fingerprint) {
49         for (int i=0; i<used; i++) {
50             if (keys[i]==fingerprint) {
51                 return values[i];
52             }
53         }
54         return null;
55     }
56
57     /**
58     * Clear all values
59     */

60
61     public void clear() {
62         used = 0;
63     }
64
65 }
66
Popular Tags