use of java.util.AbstractMap in project pravega by pravega.
the class OperationLogTestBase method getExpectedContents.
/**
* Given a list of Log Operations, generates an InputStream for each encountered StreamSegment that contains the final
* contents of that StreamSegment. Only considers operations of type StreamSegmentAppendOperation and MergeSegmentOperation.
*/
private AbstractMap<Long, InputStream> getExpectedContents(Collection<OperationWithCompletion> operations) {
HashMap<Long, List<InputStream>> partialContents = new HashMap<>();
for (OperationWithCompletion o : operations) {
Assert.assertTrue("Operation is not completed.", o.completion.isDone());
if (o.completion.isCompletedExceptionally()) {
// This is failed operation; ignore it.
continue;
}
if (o.operation instanceof StreamSegmentAppendOperation) {
StreamSegmentAppendOperation appendOperation = (StreamSegmentAppendOperation) o.operation;
List<InputStream> segmentContents = partialContents.get(appendOperation.getStreamSegmentId());
if (segmentContents == null) {
segmentContents = new ArrayList<>();
partialContents.put(appendOperation.getStreamSegmentId(), segmentContents);
}
segmentContents.add(appendOperation.getData().getReader());
} else if (o.operation instanceof MergeSegmentOperation) {
MergeSegmentOperation mergeOperation = (MergeSegmentOperation) o.operation;
List<InputStream> targetSegmentContents = partialContents.get(mergeOperation.getStreamSegmentId());
if (targetSegmentContents == null) {
targetSegmentContents = new ArrayList<>();
partialContents.put(mergeOperation.getStreamSegmentId(), targetSegmentContents);
}
List<InputStream> sourceSegmentContents = partialContents.get(mergeOperation.getSourceSegmentId());
targetSegmentContents.addAll(sourceSegmentContents);
partialContents.remove(mergeOperation.getSourceSegmentId());
}
}
// Construct final result.
HashMap<Long, InputStream> result = new HashMap<>();
for (Map.Entry<Long, List<InputStream>> e : partialContents.entrySet()) {
result.put(e.getKey(), new SequenceInputStream(Iterators.asEnumeration(e.getValue().iterator())));
}
return result;
}
use of java.util.AbstractMap in project j2objc by google.
the class AbstractMapTest method test_values.
/**
* java.util.AbstractMap#values()
*/
public void test_values() {
AbstractMap map1 = new HashMap(0);
assertSame("HashMap(0)", map1.values(), map1.values());
AbstractMap map2 = new HashMap(10);
assertSame("HashMap(10)", map2.values(), map2.values());
Map map3 = Collections.EMPTY_MAP;
assertSame("EMPTY_MAP", map3.values(), map3.values());
AbstractMap map4 = new IdentityHashMap(1);
assertSame("IdentityHashMap", map4.values(), map4.values());
AbstractMap map5 = new LinkedHashMap(122);
assertSame("IdentityHashMap", map5.values(), map5.values());
AbstractMap map6 = new TreeMap();
assertSame("TreeMap", map6.values(), map6.values());
AbstractMap map7 = new WeakHashMap();
assertSame("WeakHashMap", map7.values(), map7.values());
}
use of java.util.AbstractMap in project j2objc by google.
the class AbstractMapTest method test_clone.
/**
* java.util.AbstractMap#clone()
*/
public void test_clone() {
class MyMap extends AbstractMap implements Cloneable {
private Map map = new HashMap();
public Set entrySet() {
return map.entrySet();
}
public Object put(Object key, Object value) {
return map.put(key, value);
}
public Map getMap() {
return map;
}
public Object clone() {
try {
return super.clone();
} catch (CloneNotSupportedException e) {
fail("Clone must be supported");
return null;
}
}
}
MyMap map = new MyMap();
map.put("one", "1");
Map.Entry entry = (Map.Entry) map.entrySet().iterator().next();
assertTrue("entry not added", entry.getKey() == "one" && entry.getValue() == "1");
MyMap mapClone = (MyMap) map.clone();
assertTrue("clone not shallow", map.getMap() == mapClone.getMap());
}
use of java.util.AbstractMap in project j2objc by google.
the class AbstractMapTest method test_removeLjava_lang_Object.
/**
* java.util.AbstractMap#remove(java.lang.Object)
*/
public void test_removeLjava_lang_Object() {
Object key = new Object();
Object value = new Object();
AbstractMap map1 = new HashMap(0);
map1.put("key", value);
assertSame("HashMap(0)", map1.remove("key"), value);
AbstractMap map4 = new IdentityHashMap(1);
map4.put(key, value);
assertSame("IdentityHashMap", map4.remove(key), value);
AbstractMap map5 = new LinkedHashMap(122);
map5.put(key, value);
assertSame("LinkedHashMap", map5.remove(key), value);
AbstractMap map6 = new TreeMap(new Comparator() {
// Bogus comparator
public int compare(Object object1, Object object2) {
return 0;
}
});
map6.put(key, value);
assertSame("TreeMap", map6.remove(key), value);
AbstractMap map7 = new WeakHashMap();
map7.put(key, value);
assertSame("WeakHashMap", map7.remove(key), value);
AbstractMap aSpecialMap = new MyMap();
aSpecialMap.put(specialKey, specialValue);
Object valueOut = aSpecialMap.remove(specialKey);
assertSame("MyMap", valueOut, specialValue);
}
use of java.util.AbstractMap in project j2objc by google.
the class AbstractMapTest method test_get.
/**
* java.util.AbstractMap#get(Object)
*/
public void test_get() {
AbstractMap map = new AMT();
assertNull(map.get("key"));
assertNull(map.get(null));
map.put("k", "v");
map.put("key", null);
map.put(null, "value");
assertEquals("v", map.get("k"));
assertNull(map.get("key"));
assertEquals("value", map.get(null));
}
Aggregations