Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

unnecessary comments removed, licensing information added.

  • Loading branch information...
commit 5769334c51b88da66927bfd3695b36657fd43dac 1 parent 0bb336e
Sarah Jundt authored
View
12 src/main/java/com/liveramp/commons/collections/MemoryBoundLruHashMap.java
@@ -57,14 +57,14 @@ public MemoryBoundLruHashMap(int numItemsCapacity, long numBytesCapacity, Memory
// First, unmanage memory usage of existing value since it is about to be replaced
// We get() instead of remove() in order to keep the same instance of 'key' in the map
if (map.containsKey(key)) {
- V oldValue = map.get(key); //TODO map.remove(key)
+ V oldValue = map.get(key);
unmanage(key, oldValue);
}
// Add to map
map.put(key, value);
manage(key, value);
- return evictIfNecessary(); //TODO: returned void
+ return evictIfNecessary();
}
public List<Map.Entry<K, V>> evictIfNecessary() {
@@ -74,12 +74,12 @@ public MemoryBoundLruHashMap(int numItemsCapacity, long numBytesCapacity, Memory
Map.Entry<K, V> eldestRemoved = map.getAndClearEldestRemoved();
if (eldestRemoved != null) {
unmanage(eldestRemoved);
- evicted = new LinkedList<Map.Entry<K, V>>(); //TODO: didn't do this evicted business.
+ evicted = new LinkedList<Map.Entry<K, V>>();
evicted.add(eldestRemoved);
}
// Now remove elements until byte count is under the threshold
- if (isMemoryBound()) { //TODO: was maxNumberManagedBytes >=0
+ if (isMemoryBound()) {
Iterator<Map.Entry<K, V>> iterator = map.entrySet().iterator();
while (numManagedBytes > numBytesCapacity && map.size() > 0) {
Map.Entry<K, V> eldest = iterator.next();
@@ -91,11 +91,9 @@ public MemoryBoundLruHashMap(int numItemsCapacity, long numBytesCapacity, Memory
iterator.remove();
}
}
-
if (evicted == null) {
evicted = Collections.emptyList();
}
-
return evicted;
}
@@ -193,7 +191,5 @@ public void remove() {
}
iterator.remove();
}
-
}
-
}
View
15 src/main/java/com/liveramp/commons/util/ByteBufferMemoryUsageEstimator.java
@@ -1,3 +1,18 @@
+/**
+ * Copyright 2011 LiveRamp
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package com.liveramp.commons.util;
import java.io.Serializable;
View
18 src/test/java/com/liveramp/commons/collections/TestMemoryBoundLruHashMap.java
@@ -16,14 +16,15 @@
package com.liveramp.commons.collections;
-import com.liveramp.commons.util.IntegerMemoryUsageEstimator;
-import com.liveramp.commons.util.LongMemoryUsageEstimator;
-import com.liveramp.commons.util.StringMemoryUsageEstimator;
+import java.util.Iterator;
+import java.util.Map;
+
import junit.framework.TestCase;
import org.junit.Test;
-import java.util.Iterator;
-import java.util.Map;
+import com.liveramp.commons.util.IntegerMemoryUsageEstimator;
+import com.liveramp.commons.util.LongMemoryUsageEstimator;
+import com.liveramp.commons.util.StringMemoryUsageEstimator;
public class TestMemoryBoundLruHashMap extends TestCase {
@@ -149,15 +150,16 @@ public void testIterator() {
map.putAndEvict(3L, 3L);
Iterator<Map.Entry<Long, Long>> itr = map.iterator();
- assertEquals(1L, (long) itr.next().getKey());
- assertEquals(2L, (long) itr.next().getKey());
+ assertEquals(1L, (long)itr.next().getKey());
+ assertEquals(2L, (long)itr.next().getKey());
assertEquals(3, map.size());
assertEquals(96, map.getNumManagedBytes());
itr.remove();
assertEquals(2, map.size());
assertEquals(64, map.getNumManagedBytes());
- assertEquals(3L, (long) itr.next().getKey());
+ assertEquals(3L, (long)itr.next().getKey());
assertFalse(itr.hasNext());
}
+
}
Please sign in to comment.
Something went wrong with that request. Please try again.