Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public final class Pool<E>
- {
- private Map<Integer, E> indexToData;
- private Map<E, Integer> dataToIndex;
- private int index;
- public Pool()
- {
- this.indexToData = new HashMap<>();
- this.dataToIndex = new HashMap<>();
- }
- public int get(final E e)
- {
- if (this.dataToIndex.containsKey(e))
- {
- return this.dataToIndex.get(e);
- }
- else
- {
- final int index = this.index;
- this.index++;
- this.dataToIndex.put(e, index);
- this.indexToData.put(index, e);
- return index;
- }
- }
- public E getByIndex(final int index)
- {
- return this.indexToData.get(index);
- }
- public int size()
- {
- return this.index;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement