107: * @throws IllegalArgumentException if the maximum size is less than one
108: * @throws IllegalArgumentException if the load factor is less than zero
109: */
110: public LRUMap(int maxSize, float loadFactor) {
111: this(maxSize, loadFactor, false);
112: }
113:
114: /**
115: * Constructs a new, empty map with the specified initial capacity and
116: * load factor.
117: *
118: * @param maxSize the maximum size of the map, -1 for no limit,
119: * @param loadFactor the load factor
120: * @param scanUntilRemovable scan until a removeable entry is found, default false
121: * @throws IllegalArgumentException if the maximum size is less than one
122: * @throws IllegalArgumentException if the load factor is less than zero
123: * @since Commons Collections 3.1
124: */
125: public LRUMap(int maxSize, float loadFactor, boolean scanUntilRemovable) {
126: super((maxSize < 1 DEFAULT_CAPACITY : maxSize), loadFactor);
127: if (maxSize < 1) {
128: throw new IllegalArgumentException("LRUMap max size must be greater than 0");
129: }
130: this.maxSize = maxSize;
131: this.scanUntilRemovable = scanUntilRemovable;
132: }
133:
134: /**
135: * Constructor copying elements from another map.
136: *
137: * The maximum size is set from the map's size.
138: *
139: * @param map the map to copy
140: * @throws NullPointerException if the map is null
141: * @throws IllegalArgumentException if the map is empty
142: */
143: public LRUMap(Map map) {
144: this(map, false);
145: }
146:
147: /**
148: * Constructor copying elements from another map.
150: * The maximum size is set from the map's size.
151: *
152: * @param map the map to copy
153: * @param scanUntilRemovable scan until a removeable entry is found, default false
154: * @throws NullPointerException if the map is null
155: * @throws IllegalArgumentException if the map is empty
156: * @since Commons Collections 3.1
157: */
158: public LRUMap(Map map, boolean scanUntilRemovable) {
159: this(map.size(), DEFAULT_LOAD_FACTOR, scanUntilRemovable);
160: putAll(map);
161: }
162:
163: //-----------------------------------------------------------------------
164: /**
165: * Gets the value mapped to the key specified.
166: *
167: * This operation changes the position of the key in the map to the
168: * most recently used position (first).
169: *
170: * @param key the key
171: * @return the mapped value, null if no match
172: */
173: public Object get(Object key) {
174: LinkEntry entry = (LinkEntry) getEntry(key);
175: if (entry == null) {
176: return null;
177: }
178: moveToMRU(entry);
179: return entry.getValue();
180: }
181:
182: //-----------------------------------------------------------------------
183: /**
184: * Moves an entry to the MRU position at the end of the list.
185: *
186: * This implementation moves the updated entry to the end of the list.
187: *
188: * @param entry the entry to update
189: */
190: protected void moveToMRU(LinkEntry entry) {
191: if (entry.after != h