Package org.apache.commons.collections4.keyvalue

Examples of org.apache.commons.collections4.keyvalue.MultiKey


        for (int i = 0; i < keys.length; i++) {
            resetFull();
            MultiKeyMap multimap = (MultiKeyMap) map;
            int size = multimap.size();

            MultiKey key = keys[i];
            Object value = values[i];

            switch (key.size()) {
                case 2:
                    assertEquals(true, multimap.containsKey(key.getKey(0), key.getKey(1)));
                    assertEquals(value, multimap.remove(key.getKey(0), key.getKey(1)));
                    assertEquals(false, multimap.containsKey(key.getKey(0), key.getKey(1)));
                    assertEquals(size - 1, multimap.size());
                    assertEquals(null, multimap.remove(key.getKey(0), key.getKey(1)));
                    assertEquals(false, multimap.containsKey(key.getKey(0), key.getKey(1)));
                    break;
                case 3:
                    assertEquals(true, multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2)));
                    assertEquals(value, multimap.remove(key.getKey(0), key.getKey(1), key.getKey(2)));
                    assertEquals(false, multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2)));
                    assertEquals(size - 1, multimap.size());
                    assertEquals(null, multimap.remove(key.getKey(0), key.getKey(1), key.getKey(2)));
                    assertEquals(false, multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2)));
                    break;
                case 4:
                    assertEquals(true, multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3)));
                    assertEquals(value, multimap.remove(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3)));
                    assertEquals(false, multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3)));
                    assertEquals(size - 1, multimap.size());
                    assertEquals(null, multimap.remove(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3)));
                    assertEquals(false, multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3)));
                    break;
                case 5:
                    assertEquals(true, multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3), key.getKey(4)));
                    assertEquals(value, multimap.remove(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3), key.getKey(4)));
                    assertEquals(false, multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3), key.getKey(4)));
                    assertEquals(size - 1, multimap.size());
                    assertEquals(null, multimap.remove(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3), key.getKey(4)));
                    assertEquals(false, multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3), key.getKey(4)));
                    break;
                default:
                    fail("Invalid key size");
            }
        }
View Full Code Here


        assertEquals(12, multimap.size());

        multimap.removeAll(I1);
        assertEquals(8, multimap.size());
        for (MapIterator it = multimap.mapIterator(); it.hasNext();) {
            MultiKey key = (MultiKey) it.next();
            assertEquals(false, I1.equals(key.getKey(0)));
        }
    }
View Full Code Here

        assertEquals(12, multimap.size());

        multimap.removeAll(I2, I3);
        assertEquals(9, multimap.size());
        for (MapIterator it = multimap.mapIterator(); it.hasNext();) {
            MultiKey key = (MultiKey) it.next();
            assertEquals(false, I2.equals(key.getKey(0)) && I3.equals(key.getKey(1)));
        }
    }
View Full Code Here

        assertEquals(12, multimap.size());

        multimap.removeAll(I1, I1, I2);
        assertEquals(9, multimap.size());
        for (MapIterator it = multimap.mapIterator(); it.hasNext();) {
            MultiKey key = (MultiKey) it.next();
            assertEquals(false, I1.equals(key.getKey(0)) && I1.equals(key.getKey(1)) && I2.equals(key.getKey(2)));
        }
    }
View Full Code Here

        assertEquals(12, multimap.size());

        multimap.removeAll(I1, I1, I2, I3);
        assertEquals(10, multimap.size());
        for (MapIterator it = multimap.mapIterator(); it.hasNext();) {
            MultiKey key = (MultiKey) it.next();
            assertEquals(false, I1.equals(key.getKey(0)) && I1.equals(key.getKey(1)) && I2.equals(key.getKey(2)) && key.size() >= 4 && I3.equals(key.getKey(3)));
        }
    }
View Full Code Here

    }

    //-----------------------------------------------------------------------
    public void testClone() {
        MultiKeyMap map = new MultiKeyMap();
        map.put(new MultiKey(I1, I2), "1-2");
        Map cloned = (Map) map.clone();
        assertEquals(map.size(), cloned.size());
        assertSame(map.get(new MultiKey(I1, I2)), cloned.get(new MultiKey(I1, I2)));
    }
View Full Code Here

        MultiKeyMap multimap = (MultiKeyMap) map;
        MultiKey[] keys = getMultiKeyKeys();
        Object[] values = getSampleValues();

        for (int i = 0; i < keys.length; i++) {
            MultiKey key = keys[i];
            Object value = values[i];

            switch (key.size()) {
                case 2:
                    assertEquals(true, multimap.containsKey(key.getKey(0), key.getKey(1)));
                    assertEquals(false, multimap.containsKey(null, key.getKey(1)));
                    assertEquals(false, multimap.containsKey(key.getKey(0), null));
                    assertEquals(false, multimap.containsKey(null, null));
                    assertEquals(false, multimap.containsKey(key.getKey(0), key.getKey(1), null));
                    assertEquals(false, multimap.containsKey(key.getKey(0), key.getKey(1), null, null));
                    assertEquals(false, multimap.containsKey(key.getKey(0), key.getKey(1), null, null, null));
                    break;
                case 3:
                    assertEquals(true, multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2)));
                    assertEquals(false, multimap.containsKey(null, key.getKey(1), key.getKey(2)));
                    assertEquals(false, multimap.containsKey(key.getKey(0), null, key.getKey(2)));
                    assertEquals(false, multimap.containsKey(key.getKey(0), key.getKey(1), null));
                    assertEquals(false, multimap.containsKey(null, null, null));
                    assertEquals(false, multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2), null));
                    assertEquals(false, multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2), null, null));
                    break;
                case 4:
                    assertEquals(true, multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3)));
                    assertEquals(false, multimap.containsKey(null, key.getKey(1), key.getKey(2), key.getKey(3)));
                    assertEquals(false, multimap.containsKey(key.getKey(0), null, key.getKey(2), key.getKey(3)));
                    assertEquals(false, multimap.containsKey(key.getKey(0), key.getKey(1), null, key.getKey(3)));
                    assertEquals(false, multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2), null));
                    assertEquals(false, multimap.containsKey(null, null, null, null));
                    assertEquals(false, multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3), null));
                    break;
                case 5:
                    assertEquals(true, multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3), key.getKey(4)));
                    assertEquals(false, multimap.containsKey(null, key.getKey(1), key.getKey(2), key.getKey(3), key.getKey(4)));
                    assertEquals(false, multimap.containsKey(key.getKey(0), null, key.getKey(2), key.getKey(3), key.getKey(4)));
                    assertEquals(false, multimap.containsKey(key.getKey(0), key.getKey(1), null, key.getKey(3), key.getKey(4)));
                    assertEquals(false, multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2), null, key.getKey(4)));
                    assertEquals(false, multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3), null));
                    assertEquals(false, multimap.containsKey(null, null, null, null, null));
                    break;
                default:
                    fail("Invalid key size");
            }
View Full Code Here

        Object[] values = getSampleValues();

        for (int i = 0; i < keys.length; i++) {
            MultiKeyMap multimap = new MultiKeyMap();

            MultiKey key = keys[i];
            Object value = values[i];

            int oldkey = hash(key.getKey(0), key.getKey(1));

            switch (key.size()) {
                case 2:
                    assertEquals(null, multimap.put(key.getKey(0), key.getKey(1), value));
                    assertEquals(1, multimap.size());
                    assertEquals(value, multimap.get(key.getKey(0), key.getKey(1)));
                    assertEquals(true, multimap.containsKey(key.getKey(0), key.getKey(1)));
                    assertEquals(true, multimap.containsKey(new MultiKey(key.getKey(0), key.getKey(1))));
                    assertEquals(value, multimap.put(key.getKey(0), key.getKey(1), null));
                    assertEquals(1, multimap.size());
                    assertEquals(null, multimap.get(key.getKey(0), key.getKey(1)));
                    assertEquals(true, multimap.containsKey(key.getKey(0), key.getKey(1)));
                    break;
                case 3:
                    assertEquals(null, multimap.put(key.getKey(0), key.getKey(1), key.getKey(2), value));
                    assertEquals(1, multimap.size());
                    assertEquals(value, multimap.get(key.getKey(0), key.getKey(1), key.getKey(2)));
                    assertEquals(true, multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2)));
                    assertEquals(true, multimap.containsKey(new MultiKey(key.getKey(0), key.getKey(1), key.getKey(2))));
                    assertEquals(value, multimap.put(key.getKey(0), key.getKey(1), key.getKey(2), null));
                    assertEquals(1, multimap.size());
                    assertEquals(null, multimap.get(key.getKey(0), key.getKey(1), key.getKey(2)));
                    assertEquals(true, multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2)));
                    break;
                case 4:
                    assertEquals(null, multimap.put(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3), value));
                    assertEquals(1, multimap.size());
                    assertEquals(value, multimap.get(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3)));
                    assertEquals(true, multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3)));
                    assertEquals(true, multimap.containsKey(new MultiKey(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3))));
                    assertEquals(value, multimap.put(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3), null));
                    assertEquals(1, multimap.size());
                    assertEquals(null, multimap.get(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3)));
                    assertEquals(true, multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3)));
                    break;
                case 5:
                    assertEquals(null, multimap.put(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3), key.getKey(4), value));
                    assertEquals(1, multimap.size());
                    assertEquals(value, multimap.get(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3), key.getKey(4)));
                    assertEquals(true, multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3), key.getKey(4)));
                    assertEquals(true, multimap.containsKey(new MultiKey(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3), key.getKey(4))));
                    assertEquals(value, multimap.put(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3), key.getKey(4), null));
                    assertEquals(1, multimap.size());
                    assertEquals(null, multimap.get(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3), key.getKey(4)));
                    assertEquals(true, multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3), key.getKey(4)));
                    break;
                default:
                    fail("Invalid key size");
            }
        }
View Full Code Here

    public Object[] getSampleKeys() {
        return getMultiKeyKeys();
    }

    private MultiKey[] getMultiKeyKeys() {
        return new MultiKey[]{new MultiKey(I1, I2), new MultiKey(I2, I3), new MultiKey(I3, I4), new MultiKey(I1, I1, I2), new MultiKey(I2, I3, I4), new MultiKey(I3, I7, I6), new MultiKey(I1, I1, I2, I3), new MultiKey(I2, I4, I5, I6), new MultiKey(I3, I6, I7, I8), new MultiKey(I1, I1, I2, I3, I4), new MultiKey(I2, I3, I4, I5, I6), new MultiKey(I3, I5, I6, I7, I8), };
    }
View Full Code Here

    public Object[] getNewSampleValues() {
        return new Object[]{"1a", "1b", "1c", "2d", "2e", "2f", "3g", "3h", "3i", "4j", "4k", "4l", };
    }

    public Object[] getOtherKeys() {
        return new Object[]{new MultiKey(I1, I7), new MultiKey(I1, I8), new MultiKey(I2, I4), new MultiKey(I2, I5), };
    }
View Full Code Here

TOP

Related Classes of org.apache.commons.collections4.keyvalue.MultiKey

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.