1 21 22 package org.apache.derby.iapi.util; 23 24 30 public class ReuseFactory { 31 32 33 private ReuseFactory() { 34 } 35 36 private static final Integer [] staticInts = 37 {new Integer (0), new Integer (1), new Integer (2), new Integer (3), 38 new Integer (4), new Integer (5), new Integer (6), new Integer (7), 39 new Integer (8), new Integer (9), new Integer (10), new Integer (11), 40 new Integer (12), new Integer (13), new Integer (14), new Integer (15), 41 new Integer (16), new Integer (17), new Integer (18)}; 42 private static final Integer FIFTY_TWO = new Integer (52); 43 private static final Integer TWENTY_THREE = new Integer (23); 44 private static final Integer MAXINT = new Integer (Integer.MAX_VALUE); 45 private static final Integer MINUS_ONE = new Integer (-1); 46 47 public static Integer getInteger(int i) 48 { 49 if (i >= 0 && i < staticInts.length) 50 { 51 return staticInts[i]; 52 } 53 else 54 { 55 switch (i) 57 { 58 case 23: 59 return TWENTY_THREE; 61 case 52: 62 return FIFTY_TWO; 64 case Integer.MAX_VALUE: 65 return MAXINT; 66 67 case -1: 68 return MINUS_ONE; 69 70 default: 71 return new Integer (i); 72 } 73 } 74 } 75 76 private static final Short [] staticShorts = 77 {new Short ((short) 0), new Short ((short) 1), new Short ((short) 2), 78 new Short ((short) 3), new Short ((short) 4), new Short ((short) 5), 79 new Short ((short) 6), new Short ((short) 7), new Short ((short) 8), 80 new Short ((short) 9), new Short ((short) 10)}; 81 82 public static Short getShort(short i) 83 { 84 if (i >= 0 && i < staticShorts.length) 85 return staticShorts[i]; 86 else 87 return new Short (i); 88 } 89 90 private static final Byte [] staticBytes = 91 {new Byte ((byte) 0), new Byte ((byte) 1), new Byte ((byte) 2), 92 new Byte ((byte) 3), new Byte ((byte) 4), new Byte ((byte) 5), 93 new Byte ((byte) 6), new Byte ((byte) 7), new Byte ((byte) 8), 94 new Byte ((byte) 9), new Byte ((byte) 10)}; 95 96 public static Byte getByte(byte i) 97 { 98 if (i >= 0 && i < staticBytes.length) 99 return staticBytes[i]; 100 else 101 return new Byte (i); 102 } 103 104 private static final Long [] staticLongs = 105 {new Long (0), new Long (1), new Long (2), 106 new Long (3), new Long (4), new Long (5), 107 new Long (6), new Long (7), new Long (8), 108 new Long (9), new Long (10)}; 109 110 public static Long getLong(long i) 111 { 112 if (i >= 0 && i < staticLongs.length) 113 return staticLongs[(int) i]; 114 else 115 return new Long (i); 116 } 117 118 private static final Boolean staticFalse = new Boolean ( false); 119 private static final Boolean staticTrue = new Boolean ( true); 120 121 public static Boolean getBoolean( boolean b) 122 { 123 return b ? staticTrue : staticFalse; 124 } 125 } 126 | Popular Tags |