/**
 *
 */
package org.javarosa.core.util;

import java.util.Vector;

/**
 * @author ctsims
 */
public class DataUtil {
    static final int offset = 10;
    static final int low = -10;
    static final int high = 400;
    static Integer[] iarray;

    static UnionLambda unionLambda = new UnionLambda();

    public static Integer integer(int ivalue) {
        if (iarray == null) {
            iarray = new Integer[high - low];
            for (int i = 0; i < iarray.length; ++i) {
                iarray[i] = new Integer(i + low);
            }
        }
        return ivalue < high && ivalue >= low ? iarray[ivalue + offset] : new Integer(ivalue);
    }


    public static <T> Vector<T> union(Vector<T> a, Vector<T> b) {
        return unionLambda.union(a, b);
    }

    public static void setUnionLambda(UnionLambda newUnionLambda) {
        unionLambda = newUnionLambda;
    }

    public static class UnionLambda {
        public <T> Vector<T> union(Vector<T> a, Vector<T> b) {
            Vector<T> u = new Vector<T>();
            //Efficiency?
            for (T i : a) {
                if (b.contains(i)) {
                    u.addElement(i);
                }
            }
            return u;
        }
    }
}

@@ -1,15 +1,4 @@
-/**%0A *%0A */%0A
 pack
@@ -288,16 +288,239 @@
 bda();%0A%0A
+    /**%0A     * Get Integer object that corresponds to int argument from a%0A     * pre-computed table, or build a new instance.%0A     *%0A     * @return Cached or new Integer instance that correpsonds to ivalue argument%0A     */%0A
     publ
@@ -555,24 +555,65 @@
 t ivalue) %7B%0A
+        // lazily populate Integer cache%0A
         if (
@@ -804,24 +804,25 @@
       %7D%0A
+%0A
         
 return i
@@ -813,23 +813,20 @@
         
-return 
+if (
 ivalue %3C
@@ -851,10 +851,30 @@
  low
- ?
+) %7B%0A            return
  iar
@@ -893,18 +893,53 @@
  offset%5D
- :
+;%0A        %7D else %7B%0A            return
  new Int
@@ -956,18 +956,27 @@
 e);%0A    
+    %7D%0A    
 %7D
-%0A
 %0A%0A    pu

Comment Integer cache method