summaryrefslogtreecommitdiff
path: root/core/java12/com/vladium/util/IntegerFactory.java
blob: 560867279b0cbe9818e835e1f985511f01e3d279 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/* Copyright (C) 2003 Vladimir Roubtsov. All rights reserved.
 * 
 * This program and the accompanying materials are made available under
 * the terms of the Common Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/cpl-v10.html
 * 
 * $Id: IntegerFactory.java,v 1.1.1.1 2004/05/09 16:57:52 vlad_r Exp $
 */
package com.vladium.util;

// ----------------------------------------------------------------------------
/**
 * @author Vlad Roubtsov, (C) 2003
 */
public
abstract class IntegerFactory
{
    // public: ................................................................
    
    // TODO: use thread-local arena pattern to avoid synchronization ?
    
    public static Integer getInteger (final int value)
    {
        synchronized (s_values)
        {
            final Object _result = s_values.get (value);
            
            if (_result == null)
            {
                final Integer result = new Integer (value);
                s_values.put (value, result);
                
                return result; 
            }
            
            return (Integer) _result;
        }
    }
    
    // protected: .............................................................

    // package: ...............................................................
    
    // private: ...............................................................
    
    
    private IntegerFactory () {} // prevent subclassing
    
    
    private static final IntObjectMap s_values = new IntObjectMap (16661);

} // end of class
// ----------------------------------------------------------------------------