View Javadoc

    1   package org.codehaus.groovy.runtime.typehandling;
    2
    3   public class IntegerCache {
    4       private IntegerCache(){}
    5
    6       static final Integer cache[] = new Integer[-(-128) + 127 + 1];
    7
    8       static {
    9           for(int i = 0; i < cache.length; i++)
    10              cache[i] = new Integer(i - 128);
    11      }
    12
    13      public static Integer integerValue(int i) {
    14          final int offset = 128;
    15          if (i >= -128 && i <= 127) { // must cache
    16              return cache[i + offset];
    17          }
    18          return new Integer(i);
    19      }
    20  }