1 28 29 package org.jibx.binding.util; 30 31 import java.util.ArrayList ; 32 import java.util.HashMap ; 33 34 35 43 44 public class ArrayMap 45 { 46 47 private ArrayList m_array; 48 49 50 private HashMap m_map; 51 52 55 56 public ArrayMap() { 57 m_array = new ArrayList (); 58 m_map = new HashMap (); 59 } 60 61 66 67 public ArrayMap(int size) { 68 m_array = new ArrayList (size); 69 m_map = new HashMap (size); 70 } 71 72 79 80 public Object get(int index) { 81 return m_array.get(index); 82 } 83 84 91 92 public int find(Object obj) { 93 Integer index = (Integer )m_map.get(obj); 94 if (index == null) { 95 return -1; 96 } else { 97 return index.intValue(); 98 } 99 } 100 101 108 109 public int findOrAdd(Object obj) { 110 Integer index = (Integer )m_map.get(obj); 111 if (index == null) { 112 index = IntegerCache.getInteger(m_array.size()); 113 m_map.put(obj, index); 114 m_array.add(obj); 115 } 116 return index.intValue(); 117 } 118 119 124 125 public int size() { 126 return m_array.size(); 127 } 128 } 129 | Popular Tags |