Code example for Set

Methods: contains, containsAll, isEmpty, iterator, size, toArray

0
 
        DBObject decodedObj = lazyDBDecoder.decode(new ByteArrayInputStream(bios.toByteArray()), (DBCollection) null);
        LazyDBObject lazyDBObj = (LazyDBObject) decodedObj;
 
        Set<Map.Entry<String, Object>> entrySet = lazyDBObj.entrySet();
        assertEquals(5, entrySet.size());
        assertFalse(entrySet.isEmpty());
         
        Object[] entrySetArray = entrySet.toArray();
        assertEquals(5, entrySetArray.length);   // kind of a lame test
 
        Map.Entry<String, Object>[] typedArray = entrySet.toArray(new Map.Entry[0]);
        assertEquals(5, typedArray.length);
 
        typedArray = entrySet.toArray(new Map.Entry[6]);
        assertEquals(6, typedArray.length);
        assertNull(typedArray[5]);
 
        assertTrue(entrySet.contains(new TestMapEntry("first", 1)));
        assertFalse(entrySet.contains(new TestMapEntry("first", 2)));
        assertFalse(entrySet.contains(new TestMapEntry("x", 1)));
         
        assertTrue(entrySet.containsAll(Arrays.asList(new TestMapEntry("first", 1), new TestMapEntry("second", "str1"))));
        assertFalse(entrySet.containsAll(Arrays.asList(new TestMapEntry("first", 1), new TestMapEntry("second", "str2"))));
 
        Iterator<Map.Entry<String, Object>> entryIter = entrySet.iterator();
 
        assertTrue(entryIter.hasNext());
        Map.Entry<String, Object> next = entryIter.next();
        assertEquals("_id", next.getKey());
        assertEquals(obj.get("_id"), next.getValue());