1 /* Copyright (C) 2003 Vladimir Roubtsov. All rights reserved. 2 * 3 * This program and the accompanying materials are made available under 4 * the terms of the Common Public License v1.0 which accompanies this distribution, 5 * and is available at http://www.eclipse.org/legal/cpl-v10.html 6 * 7 * $Id: IntegerFactory.java,v 1.1.1.1 2004/05/09 16:57:52 vlad_r Exp $ 8 */ 9 package com.vladium.util; 10 11 // ---------------------------------------------------------------------------- 12 /** 13 * @author Vlad Roubtsov, (C) 2003 14 */ 15 public 16 abstract class IntegerFactory 17 { 18 // public: ................................................................ 19 20 // TODO: use thread-local arena pattern to avoid synchronization ? 21 22 public static Integer getInteger (final int value) 23 { 24 synchronized (s_values) 25 { 26 final Object _result = s_values.get (value); 27 28 if (_result == null) 29 { 30 final Integer result = new Integer (value); 31 s_values.put (value, result); 32 33 return result; 34 } 35 36 return (Integer) _result; 37 } 38 } 39 40 // protected: ............................................................. 41 42 // package: ............................................................... 43 44 // private: ............................................................... 45 46 47 private IntegerFactory () {} // prevent subclassing 48 49 50 private static final IntObjectMap s_values = new IntObjectMap (16661); 51 52 } // end of class 53 // ----------------------------------------------------------------------------