001 package org.codehaus.groovy.runtime.typehandling;
002
003 public class IntegerCache {
004 private IntegerCache(){}
005
006 static final Integer cache[] = new Integer[-(-128) + 127 + 1];
007
008 static {
009 for(int i = 0; i < cache.length; i++)
010 cache[i] = new Integer(i - 128);
011 }
012
013 public static Integer integerValue(int i) {
014 final int offset = 128;
015 if (i >= -128 && i <= 127) { // must cache
016 return cache[i + offset];
017 }
018 return new Integer(i);
019 }
020 }