Package org.apache.commons.collections15

Examples of org.apache.commons.collections15.BidiMap


    public BidiMap makeEmptyBidiMap() {
        return UnmodifiableBidiMap.decorate(new DualHashBidiMap());
    }

    public BidiMap makeFullBidiMap() {
        BidiMap bidi = new DualHashBidiMap();
        for (int i = 0; i < entries.length; i++) {
            bidi.put(entries[i][0], entries[i][1]);
        }
        return UnmodifiableBidiMap.decorate(bidi);
    }
View Full Code Here


        }
        return UnmodifiableBidiMap.decorate(bidi);
    }

    public Map makeFullMap() {
        BidiMap bidi = new DualHashBidiMap();
        addSampleMappings(bidi);
        return UnmodifiableBidiMap.decorate(bidi);
    }
View Full Code Here

     * Override to create a full <code>BidiMap</code> other than the default.
     *
     * @return a full <code>BidiMap</code> implementation.
     */
    public BidiMap makeFullBidiMap() {
        final BidiMap map = makeEmptyBidiMap();
        for (int i = 0; i < entries.length; i++) {
            map.put(entries[i][0], entries[i][1]);
        }
        return map;
    }
View Full Code Here

    // BidiPut
    //-----------------------------------------------------------------------
    public void testBidiPut() {
        if (isPutAddSupported() == false || isPutChangeSupported() == false) return;

        BidiMap map = makeEmptyBidiMap();
        BidiMap inverse = map.inverseBidiMap();
        assertEquals(0, map.size());
        assertEquals(map.size(), inverse.size());

        map.put("A", "B");
        assertEquals(1, map.size());
        assertEquals(map.size(), inverse.size());
        assertEquals("B", map.get("A"));
        assertEquals("A", inverse.get("B"));

        map.put("A", "C");
        assertEquals(1, map.size());
        assertEquals(map.size(), inverse.size());
        assertEquals("C", map.get("A"));
        assertEquals("A", inverse.get("C"));

        map.put("B", "C");
        assertEquals(1, map.size());
        assertEquals(map.size(), inverse.size());
        assertEquals("C", map.get("B"));
        assertEquals("B", inverse.get("C"));

        map.put("E", "F");
        assertEquals(2, map.size());
        assertEquals(map.size(), inverse.size());
        assertEquals("F", map.get("E"));
        assertEquals("E", inverse.get("F"));
    }
View Full Code Here

    }

    // testInverse
    //-----------------------------------------------------------------------
    public void testBidiInverse() {
        final BidiMap map = makeFullBidiMap();
        final BidiMap inverseMap = map.inverseBidiMap();

        assertSame("Inverse of inverse is not equal to original.", map, inverseMap.inverseBidiMap());

        assertEquals("Value not found for key.", entries[0][0], inverseMap.get(entries[0][1]));

        assertEquals("Key not found for value.", entries[0][1], inverseMap.getKey(entries[0][0]));
    }
View Full Code Here

    /**
     * Tests {@link BlockingBuffer#get()} in combination with {@link BlockingBuffer#add()}.
     */
    public void testGetWithAdd() {

        Buffer blockingBuffer = BlockingBuffer.decorate(new MyBuffer());
        Object obj = new Object();

        new DelayedAdd(blockingBuffer, obj).start();

        // verify does not throw BufferUnderflowException; should block until other thread has added to the buffer .
        assertSame(obj, blockingBuffer.get());
    }
View Full Code Here

    /**
     * Tests {@link BlockingBuffer#get()} in combination with {@link BlockingBuffer#addAll()}.
     */
    public void testGetWithAddAll() {

        Buffer blockingBuffer = BlockingBuffer.decorate(new MyBuffer());
        Object obj = new Object();

        new DelayedAddAll(blockingBuffer, obj).start();

        // verify does not throw BufferUnderflowException; should block until other thread has added to the buffer .
        assertSame(obj, blockingBuffer.get());
    }
View Full Code Here

    /**
     * Tests {@link BlockingBuffer#remove()} in combination with {@link BlockingBuffer#add()}.
     */
    public void testRemoveWithAdd() {

        Buffer blockingBuffer = BlockingBuffer.decorate(new MyBuffer());
        Object obj = new Object();

        new DelayedAdd(blockingBuffer, obj).start();

        // verify does not throw BufferUnderflowException; should block until other thread has added to the buffer .
        assertSame(obj, blockingBuffer.remove());
    }
View Full Code Here

    /**
     * Tests {@link BlockingBuffer#remove()} in combination with {@link BlockingBuffer#addAll()}.
     */
    public void testRemoveWithAddAll() {

        Buffer blockingBuffer = BlockingBuffer.decorate(new MyBuffer());
        Object obj = new Object();

        new DelayedAddAll(blockingBuffer, obj).start();

        // verify does not throw BufferUnderflowException; should block until other thread has added to the buffer .
        assertSame(obj, blockingBuffer.remove());
    }
View Full Code Here

     * Two read threads should block on an empty buffer until one object
     * is added then both threads should complete.
     */
    public void testBlockedGetWithAdd() {

        Buffer blockingBuffer = BlockingBuffer.decorate(new MyBuffer());
        Object obj = new Object();
       
        // run methods will get and compare -- must wait for add
        Thread thread1 = new ReadThread(blockingBuffer, obj);
        Thread thread2 = new ReadThread(blockingBuffer, obj);
        thread1.start();
        thread2.start();
       
        // give hungry read threads ample time to hang
        delay();
          
        // notifyAll should allow both read threads to complete
        blockingBuffer.add(obj);
       
        // allow notified threads to complete
        delay();
       
        // There should not be any threads waiting.
View Full Code Here

TOP

Related Classes of org.apache.commons.collections15.BidiMap

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.