Package gnu.trove

Examples of gnu.trove.TLongCollection


        for ( int i = 0; i < keys.length; i++ ) {
            vals[i] = keys[i] * 2;
            map.put( keys[i], vals[i] );
        }

        TLongCollection values = map.valueCollection();
        long[] sorted_keys = new long[ vals.length ];
        System.arraycopy( vals, 0, sorted_keys, 0, vals.length );
        Arrays.sort( sorted_keys );
        long[] setarray = values.toArray();
        Arrays.sort( setarray );
        assertTrue( "expected: " + Arrays.toString( sorted_keys ) +
                    ", was: " + Arrays.toString( setarray ),
                Arrays.equals( sorted_keys, setarray ) );

        setarray = values.toArray( new long[0] );
        Arrays.sort( setarray );
        assertTrue( "expected: " + Arrays.toString( sorted_keys ) +
                    ", was: " + Arrays.toString( setarray ),
                Arrays.equals( sorted_keys, setarray ) );

        assertFalse( "remove of element not in collection succeded: " + values,
                values.remove( 1 ) );
        assertEquals( keys.length, values.size() );
        assertEquals( keys.length, map.size() );

        assertTrue( "remove of element in collection failed: " + values,
                values.remove( 42 * 2 ) );
        assertEquals( keys.length - 1, values.size() );
        assertEquals( keys.length - 1, map.size() );

        try {
            values.add( 42 );
            fail( "Expected UnsupportedOperationException" );
        }
        catch ( UnsupportedOperationException ex ) {
            // Expected
        }
View Full Code Here


        for ( int i = 0; i < keys.length; i++ ) {
            vals[i] = keys[i] * 2;
            map.put( keys[i], vals[i] );
        }

        TLongCollection values = map.valueCollection();
        assertEquals( map.size(), values.size() );
        assertFalse( values.isEmpty() );

        // test with a java.util.Map
        Set<Number> java_set = new HashSet<Number>();
        for ( int i = 0; i < vals.length; i++ ) {
            java_set.add( Long.valueOf( vals[i] ) );
        }
        assertTrue( values.containsAll( java_set ) );
        java_set.add( Integer.valueOf( 12 ) );
        assertFalse( values.containsAll( java_set ) );
        java_set.remove( Integer.valueOf( 12 ) );
        assertTrue( values.containsAll( java_set ) );
        java_set.add( Long.valueOf( 12 ) );
        assertFalse( values.containsAll( java_set ) );

        // test with a TCollection
        TLongSet tintset = new TLongHashSet( vals );
        assertTrue( values.containsAll( tintset ) );
        tintset.add( 12 );
        assertFalse( values.containsAll( tintset ) );

        // test raw array
        assertTrue( values.containsAll( vals ) );
        vals[3] = vals[3] + 1;
        assertFalse( values.containsAll( vals ) );
    }
View Full Code Here

        for ( int i = 0; i < keys.length; i++ ) {
            vals[i] = keys[i] * 2;
            map.put( keys[i], vals[i] );
        }

        TLongCollection values = map.valueCollection();
        assertEquals( map.size(), values.size() );
        assertFalse( values.isEmpty() );

        // test with a java.util.Map
        Set<Long> java_set = new HashSet<Long>();
        for ( int i = 0; i < vals.length; i++ ) {
            java_set.add( Long.valueOf( vals[i] ) );
        }

        try {
            values.addAll( java_set );
            fail( "Expected UnsupportedOperationException" );
        }
        catch ( UnsupportedOperationException ex ) {
            // Expected
        }

        try {
            values.addAll( values );
            fail( "Expected UnsupportedOperationException" );
        }
        catch ( UnsupportedOperationException ex ) {
            // Expected
        }

        try {
            values.addAll( vals );
            fail( "Expected UnsupportedOperationException" );
        }
        catch ( UnsupportedOperationException ex ) {
            // Expected
        }
View Full Code Here

        for ( int i = 0; i < keys.length; i++ ) {
            vals[i] = keys[i] * 2;
            map.put( keys[i], vals[i] );
        }

        TLongCollection values = map.valueCollection();
        assertEquals( map.size(), values.size() );
        assertFalse( values.isEmpty() );

        // test with a java.util.Map
        Set<Number> java_set = new HashSet<Number>();
        for ( int i = 0; i < vals.length; i++ ) {
            java_set.add( Long.valueOf( vals[i] ) );
        }
        assertFalse( values.retainAll( java_set ) );
        assertEquals( keys.length, values.size() );
        assertEquals( keys.length, map.size() );
        for ( int i = 0; i < keys.length; i++ ) {
            assertTrue( values.contains( vals[i] ) );
            assertTrue( map.containsValue( vals[i] ) );
        }
        java_set.remove( Long.valueOf( 42 * 2 ) );
        assertTrue( "collection should have been modified: " + values +
                    "\njava: " + java_set,
                values.retainAll( java_set ) );
        assertEquals( keys.length - 1, values.size() );
        assertEquals( keys.length - 1, map.size() );
        for ( int i = 0; i < keys.length; i++ ) {
            if ( keys[i] != 42 ) {
                assertTrue( values.contains( vals[i] ) );
                assertTrue( map.containsValue( vals[i] ) );
            } else {
                assertFalse( values.contains( vals[i] ) );
                assertFalse( map.containsValue( vals[i] ) );
            }
        }
    }
View Full Code Here

        for ( int i = 0; i < keys.length; i++ ) {
            vals[i] = keys[i] * 2;
            map.put( keys[i], vals[i] );
        }

        TLongCollection values = map.valueCollection();
        assertEquals( map.size(), values.size() );
        assertFalse( values.isEmpty() );

        assertFalse( values.retainAll( values ) );

        // test with a TCollection
        TLongSet tintset = new TLongHashSet( vals );
        assertFalse( "values: " + values + ", collection: " + tintset,
                values.retainAll( tintset ) );
        TLongCollection collection = new TLongArrayList( vals );
        assertFalse( "values: " + values + ", collection: " + collection,
                values.retainAll( collection ) );

        collection.remove( 42 * 2 );
        assertTrue( "values: " + values + ", collection: " + collection,
                values.retainAll( collection ) );
        assertEquals( keys.length - 1, values.size() );
        assertEquals( keys.length - 1, map.size() );
    }
View Full Code Here

        for ( int i = 0; i < keys.length; i++ ) {
            vals[i] = keys[i] * 2;
            map.put( keys[i], vals[i] );
        }

        TLongCollection values = map.valueCollection();
        assertEquals( map.size(), values.size() );
        assertFalse( values.isEmpty() );

        // test raw array
        map = new TIntLongHashMap();
        for ( int i = 0; i < keys.length; i++ ) {
            vals[i] = keys[i] * 2;
            map.put( keys[i], vals[i] );
        }
        values = map.valueCollection();

        assertFalse( values.retainAll( vals ) );
        assertTrue( values.containsAll( vals ) );

        vals[3] = vals[3] + 1;
        assertTrue( values.retainAll( vals ) );
        vals[3] = vals[3] - 1;

        assertEquals( "removed: " + keys[3] + ", values: " + values,
                keys.length - 1, values.size() );
        assertEquals( "removed: " + keys[3] + ", set: " + values
                      + "\nmap: " + map, values.size(), map.size() );
    }
View Full Code Here

        for ( int i = 0; i < keys.length; i++ ) {
            vals[i] = keys[i] * 2;
            map.put( keys[i], vals[i] );
        }

        TLongCollection values = map.valueCollection();
        assertEquals( map.size(), values.size() );
        assertFalse( values.isEmpty() );

        // test with a java.util.Map
        Set<Number> java_set = new HashSet<Number>();
        assertFalse( values.removeAll( java_set ) );
        assertEquals( vals.length, values.size() );
        assertEquals( vals.length, map.size() );
        for ( int i = 0; i < keys.length; i++ ) {
            assertTrue( values.contains( vals[i] ) );
            assertTrue( map.containsValue( vals[i] ) );
        }

        for ( int i = 0; i < vals.length; i++ ) {
            java_set.add( Long.valueOf( vals[i] ) );
        }
        java_set.remove( Long.valueOf( 42 * 2 ) );
        assertTrue( "values should have been modified: " + values + ", java: " + java_set,
                values.removeAll( java_set ) );
        assertEquals( "set: " + values, 1, values.size() );
        assertEquals( "set: " + values, 1, map.size() );
        for ( int i = 0; i < vals.length; i++ ) {
            if ( vals[i] == 42 * 2 ) {
                assertTrue( values.contains( vals[i] ) );
                assertTrue( map.containsValue( vals[i] ) );
            } else {
                assertFalse( values.contains( vals[i] ) );
                assertFalse( map.containsValue( vals[i] ) );
            }
        }
    }
View Full Code Here

        for ( int i = 0; i < keys.length; i++ ) {
            vals[i] = keys[i] * 2;
            map.put( keys[i], vals[i] );
        }

        TLongCollection values = map.valueCollection();
        assertEquals( map.size(), values.size() );
        assertFalse( values.isEmpty() );

        assertTrue( values.removeAll( values ) );
        assertTrue( values.isEmpty() );

        // repopulate the set.
        map = new TIntLongHashMap();
        for ( int i = 0; i < keys.length; i++ ) {
            vals[i] = keys[i] * 2;
            map.put( keys[i], vals[i] );
        }
        values = map.valueCollection();

        // With empty set
        TLongSet tlongset = new TLongHashSet();
        assertFalse( "values: " + values + ", collection: " + tlongset,
                values.removeAll( tlongset ) );

        // With partial set
        tlongset = new TLongHashSet( vals );
        tlongset.remove( 42 * 2 );
        assertTrue( "values: " + values + ", collection: " + tlongset,
                values.removeAll( tlongset ) );
        assertEquals( "set: " + values, 1, values.size() );
        assertEquals( "set: " + values, 1, map.size() );
        for ( int i = 0; i < keys.length; i++ ) {
            if ( keys[i] == 42 ) {
                assertTrue( values.contains( vals[i] ) );
                assertTrue( map.containsValue( vals[i] ) );
            } else {
                assertFalse( values.contains( vals[i] ) );
                assertFalse( map.containsValue( vals[i] ) );
            }
        }

        // repopulate the set.
        map = new TIntLongHashMap();
        for ( int i = 0; i < keys.length; i++ ) {
            vals[i] = keys[i] * 2;
            map.put( keys[i], vals[i] );
        }
        values = map.valueCollection();

        // Empty list
        TLongCollection collection = new TLongArrayList();
        assertFalse( "values: " + values + ", collection: " + collection,
                values.removeAll( collection ) );

        // partial list
        collection = new TLongArrayList( vals );
        collection.remove( 42 * 2 );
        assertTrue( "values: " + values + ", collection: " + collection,
                values.removeAll( collection ) );
        assertEquals( "values: " + values, 1, values.size() );
        assertEquals( "values: " + values, 1, map.size() );
        for ( int i = 0; i < keys.length; i++ ) {
View Full Code Here

        for ( int i = 0; i < keys.length; i++ ) {
            vals[i] = keys[i] * 2;
            map.put( keys[i], vals[i] );
        }

        TLongCollection values = map.valueCollection();
        assertEquals( map.size(), values.size() );
        assertFalse( values.isEmpty() );

        // test raw array
        map = new TIntLongHashMap();
        for ( int i = 0; i < keys.length; i++ ) {
            vals[i] = keys[i] * 2;
            map.put( keys[i], vals[i] );
        }
        values = map.valueCollection();

        vals[3] = vals[3] + 1;
        assertTrue( values.removeAll( vals ) );
        vals[3] = vals[3] - 1;

        assertEquals( "removed: " + keys[3] + ", values: " + values,
                1, values.size() );
        assertEquals( "removed: " + keys[3] + ", values: " + values
                      + "\nmap: " + map, values.size(), map.size() );
    }
View Full Code Here

        for ( int i = 0; i < keys.length; i++ ) {
            vals[i] = keys[i] * 2;
            map.put( keys[i], vals[i] );
        }

        TLongCollection values = map.valueCollection();
        assertEquals( map.size(), values.size() );
        assertFalse( values.isEmpty() );

        class ForEach implements TLongProcedure {
            TLongList built = new TLongArrayList();


            public boolean execute( long value ) {
                built.add( value );
                return true;
            }

            TLongList getBuilt() {
                return built;
            }
        }

        ForEach foreach = new ForEach();
        values.forEach( foreach );
        TLongList built = foreach.getBuilt();
        for ( int i = 0; i < values.size(); i++ ) {
            assertTrue( values.contains( built.get( i ) ) );
        }
    }
View Full Code Here

TOP

Related Classes of gnu.trove.TLongCollection

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.