Search in sources :

Example 36 with AbstractMap

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;
}
Also used : HashMap(java.util.HashMap) SequenceInputStream(java.io.SequenceInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) StreamSegmentAppendOperation(io.pravega.segmentstore.server.logs.operations.StreamSegmentAppendOperation) MergeSegmentOperation(io.pravega.segmentstore.server.logs.operations.MergeSegmentOperation) SequenceInputStream(java.io.SequenceInputStream) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) AbstractMap(java.util.AbstractMap)

Example 37 with AbstractMap

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());
}
Also used : AbstractMap(java.util.AbstractMap) IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) WeakHashMap(java.util.WeakHashMap) IdentityHashMap(java.util.IdentityHashMap) TreeMap(java.util.TreeMap) IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) AbstractMap(java.util.AbstractMap) TreeMap(java.util.TreeMap) Map(java.util.Map) WeakHashMap(java.util.WeakHashMap) LinkedHashMap(java.util.LinkedHashMap) WeakHashMap(java.util.WeakHashMap)

Example 38 with AbstractMap

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());
}
Also used : AbstractMap(java.util.AbstractMap) IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) WeakHashMap(java.util.WeakHashMap) IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) AbstractMap(java.util.AbstractMap) TreeMap(java.util.TreeMap) Map(java.util.Map) WeakHashMap(java.util.WeakHashMap)

Example 39 with AbstractMap

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);
}
Also used : AbstractMap(java.util.AbstractMap) IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) WeakHashMap(java.util.WeakHashMap) IdentityHashMap(java.util.IdentityHashMap) TreeMap(java.util.TreeMap) LinkedHashMap(java.util.LinkedHashMap) Comparator(java.util.Comparator) WeakHashMap(java.util.WeakHashMap)

Example 40 with AbstractMap

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));
}
Also used : AbstractMap(java.util.AbstractMap)

Aggregations

AbstractMap (java.util.AbstractMap)46 HashMap (java.util.HashMap)27 Map (java.util.Map)20 IdentityHashMap (java.util.IdentityHashMap)19 LinkedHashMap (java.util.LinkedHashMap)19 TreeMap (java.util.TreeMap)17 WeakHashMap (java.util.WeakHashMap)13 Collection (java.util.Collection)8 Set (java.util.Set)7 InputStream (java.io.InputStream)4 SequenceInputStream (java.io.SequenceInputStream)3 Comparator (java.util.Comparator)3 HashSet (java.util.HashSet)3 Iterator (java.util.Iterator)3 AtomicLong (java.util.concurrent.atomic.AtomicLong)3 ReadResult (io.pravega.segmentstore.contracts.ReadResult)2 IOException (java.io.IOException)2 Cleanup (lombok.Cleanup)2 Analyzer (org.apache.lucene.analysis.Analyzer)2 IndexSettings (org.elasticsearch.index.IndexSettings)2