1 package net.sf.saxon.instruct; 2 import net.sf.saxon.om.ValueRepresentation; 3 4 9 10 public class ParameterSet 11 { 12 private int[] keys; 13 private ValueRepresentation[] values; 14 private int used = 0; 15 16 public static ParameterSet EMPTY_PARAMETER_SET = new ParameterSet(0); 17 18 21 22 public ParameterSet() { 23 this(10); 24 } 25 26 29 30 public ParameterSet(int capacity) { 31 keys = new int[capacity]; 32 values = new ValueRepresentation[capacity]; 33 } 34 35 38 39 public ParameterSet(ParameterSet existing, int extra) { 40 this(existing.used + extra); 41 for (int i=0; i<existing.used; i++) { 42 put(existing.keys[i], existing.values[i]); 43 } 44 } 45 46 52 53 public void put (int fingerprint, ValueRepresentation value) { 54 for (int i=0; i<used; i++) { 55 if (keys[i]==fingerprint) { 56 values[i]=value; 57 return; 58 } 59 } 60 if (used+1 > keys.length) { 61 int newlength = (used<=5 ? 10 : used*2); 62 int[] newkeys = new int[newlength]; 63 ValueRepresentation[] newvalues = new ValueRepresentation[newlength]; 64 System.arraycopy(values, 0, newvalues, 0, used); 65 System.arraycopy(keys, 0, newkeys, 0, used); 66 values = newvalues; 67 keys = newkeys; 68 } 69 keys[used] = fingerprint; 70 values[used++] = value; 71 } 72 73 79 80 public ValueRepresentation get (int fingerprint) { 81 for (int i=0; i<used; i++) { 82 if (keys[i]==fingerprint) { 83 return values[i]; 84 } 85 } 86 return null; 87 } 88 89 92 93 public void clear() { 94 used = 0; 95 } 96 97 } 98 | Popular Tags |