comparison src/org/tmatesoft/hg/internal/Pool.java @ 431:12f668401613

FIXMEs: awkward API refactored, what need to be internal got hidden; public aspects got captured in slim interfaces
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Thu, 29 Mar 2012 20:54:04 +0200
parents 6bb5e7ed051a
children
comparison
equal deleted inserted replaced
430:d280759c2a3f 431:12f668401613
1 /* 1 /*
2 * Copyright (c) 2011 TMate Software Ltd 2 * Copyright (c) 2011-2012 TMate Software Ltd
3 * 3 *
4 * This program is free software; you can redistribute it and/or modify 4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by 5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License. 6 * the Free Software Foundation; version 2 of the License.
7 * 7 *
16 */ 16 */
17 package org.tmatesoft.hg.internal; 17 package org.tmatesoft.hg.internal;
18 18
19 import java.util.HashMap; 19 import java.util.HashMap;
20 20
21 import org.tmatesoft.hg.util.Convertor;
22
21 /** 23 /**
22 * Instance pooling. 24 * Instance pooling.
23 * 25 *
24 * @author Artem Tikhomirov 26 * @author Artem Tikhomirov
25 * @author TMate Software Ltd. 27 * @author TMate Software Ltd.
26 */ 28 */
27 public class Pool<T> { 29 public class Pool<T> implements Convertor<T> {
28 private final HashMap<T,T> unify; 30 private final HashMap<T,T> unify;
29 31
30 public Pool() { 32 public Pool() {
31 unify = new HashMap<T, T>(); 33 unify = new HashMap<T, T>();
32 } 34 }
36 unify = new HashMap<T, T>(); 38 unify = new HashMap<T, T>();
37 } else { 39 } else {
38 unify = new HashMap<T, T>(sizeHint * 4 / 3, 0.75f); 40 unify = new HashMap<T, T>(sizeHint * 4 / 3, 0.75f);
39 } 41 }
40 } 42 }
41 43
44 public T mangle(T t) {
45 return unify(t);
46 }
47
42 public T unify(T t) { 48 public T unify(T t) {
43 T rv = unify.get(t); 49 T rv = unify.get(t);
44 if (rv == null) { 50 if (rv == null) {
45 // first time we see a new value 51 // first time we see a new value
46 unify.put(t, t); 52 unify.put(t, t);