1 18 package org.apache.geronimo.interop.util; 19 20 public abstract class IntegerCache { 21 private static final int MIN_VALUE = -999; 22 private static final int MAX_VALUE = 9999; 23 24 private static final Integer [] CACHE = getCache(); 25 26 public static Integer get(int i) { 27 if (i >= MIN_VALUE && i <= MAX_VALUE) { 28 return CACHE[i - MIN_VALUE]; 29 } else { 30 return new Integer (i); 31 } 32 } 33 34 private static Integer [] getCache() { 35 Integer [] cache = new Integer [1 + MAX_VALUE - MIN_VALUE]; 36 for (int i = MIN_VALUE; i <= MAX_VALUE; i++) { 37 cache[i - MIN_VALUE] = new Integer (i); 38 } 39 return cache; 40 } 41 } 42 | Popular Tags |