Package gnu.trove.list

Examples of gnu.trove.list.TLongList


        sort(0, size);
    }

    /** {@inheritDoc} */
    public void sort(int fromIndex, int toIndex) {
        TLongList tmp = subList(fromIndex, toIndex);
        long[] vals = tmp.toArray();
        Arrays.sort(vals);
        set(fromIndex, vals);
    }
View Full Code Here


        };
    }

    /** {@inheritDoc} */
    public TLongList grep(TLongProcedure condition) {
        TLongList ret = new TLongLinkedList();
        for (TLongLink l = head; got(l); l = l.getNext()) {
            if (condition.execute(l.getValue()))
                ret.add(l.getValue());
        }
        return ret;
    }
View Full Code Here

        return ret;
    }

    /** {@inheritDoc} */
    public TLongList inverseGrep(TLongProcedure condition) {
        TLongList ret = new TLongLinkedList();
        for (TLongLink l = head; got(l); l = l.getNext()) {
            if (!condition.execute(l.getValue()))
                ret.add(l.getValue());
        }
        return ret;
    }
View Full Code Here

    assertEquals( TCollections.unmodifiableList( list1 ),
      TCollections.unmodifiableList( list2 ) );
  }

  public void testLongUnmodifiableEquality() {
    TLongList list1 = new TLongArrayList();
    TLongList list2 = new TLongArrayList();

    assertEquals( list1, list2 );
    assertEquals( list1, TCollections.unmodifiableList( list2 ) );
    assertEquals( TCollections.unmodifiableList( list1 ), list2 );
    assertEquals( TCollections.unmodifiableList( list1 ),
      TCollections.unmodifiableList( list2 ) );

    list1.add( 1 );
    list1.add( 2 );
    list1.add( 3 );

    list2.add( 1 );
    list2.add( 2 );
    list2.add( 3 );

    assertEquals( list1, list2 );
    assertEquals( list1, TCollections.unmodifiableList( list2 ) );
    assertEquals( TCollections.unmodifiableList( list1 ), list2 );
    assertEquals( TCollections.unmodifiableList( list1 ),
View Full Code Here

    assertEquals( TCollections.unmodifiableList( list1 ),
      TCollections.unmodifiableList( list2 ) );
  }

  public void testLongUnmodifiableEquality() {
    TLongList list1 = new TLongLinkedList();
    TLongList list2 = new TLongLinkedList();

    assertEquals( list1, list2 );
    assertEquals( list1, TCollections.unmodifiableList( list2 ) );
    assertEquals( TCollections.unmodifiableList( list1 ), list2 );
    assertEquals( TCollections.unmodifiableList( list1 ),
      TCollections.unmodifiableList( list2 ) );

    list1.add( 1 );
    list1.add( 2 );
    list1.add( 3 );

    list2.add( 1 );
    list2.add( 2 );
    list2.add( 3 );

    assertEquals( list1, list2 );
    assertEquals( list1, TCollections.unmodifiableList( list2 ) );
    assertEquals( TCollections.unmodifiableList( list1 ), list2 );
    assertEquals( TCollections.unmodifiableList( list1 ),
View Full Code Here

            }
        }

        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

        TLongCollection values = map.valueCollection();
        assertEquals( map.size(), values.size() );
        assertFalse( values.isEmpty() );
        assertEquals( values, values );
        TLongList values_list = new TLongArrayList( values );
        assertFalse( "collections should not be equal: " + values + ", " + values_list,
                values.equals( values_list ) );

        TLongList list = new TLongArrayList( vals );
        values_list.sort();
        list.sort();
        assertTrue( "collections incorrectly not equal: " + values_list + ", " + list,
                values_list.equals( list ) );
        assertTrue( "collections incorrectly not equal: " + values_list + ", " + list,
                values_list.equals( list ) );


        long[] mismatched = {72, 49, 53, 1024, 999};
        TLongCollection unequal = new TLongArrayList();
        unequal.addAll( mismatched );

        assertFalse( "collections incorrectly equal: " + values_list + ", " + unequal,
                values_list.equals( unequal ) );

        // Change length, different code branch
        unequal.add( 1 );
        assertFalse( "collections incorrectly equal: " + values_list + ", " + unequal,
                values_list.equals( unequal ) );

        assertFalse( "values incorrectly equals a random object",
                values_list.equals( new Object() ) );

        // value in map twice, in list twice.
        list = new TLongArrayList( vals );
        map.put( 1, vals[0] );
        values_list = new TLongArrayList( map.valueCollection() );
        list.add( vals[0] );
        values_list.sort();
        list.sort();
        assertTrue( "collections incorrectly not equal: " + values_list + ", " + list,
                values_list.equals( list ) );

        // value in the map twice, same length list, but value only in list once.
        list = new TLongArrayList( vals );
        list.add( -1 );
        list.sort();       
        assertFalse( "collections incorrectly equal: " + values_list + ", " + list,
                values_list.equals( list ) );
    }
View Full Code Here

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

        TLongList list = new TLongArrayList( vals );
        TLongCollection set = map.valueCollection();
        assertEquals( map.getNoEntryValue(), set.getNoEntryValue() );

        // test basic iterator function.
        TLongIterator iter = set.iterator();
        while ( iter.hasNext() ) {
            long val = iter.next();
            assertTrue( "value collection should only contain values: " + val + ", set; " + set,
                    list.contains( val ) );
        }

        assertFalse( iter.hasNext() );
        try {
            iter.next();
            fail( "Expect NoSuchElementException" );
        }
        catch ( NoSuchElementException ex ) {
            // Expected.
        }

        // Start over with new iterator -- test iter.remove()
        iter = set.iterator();
        while ( iter.hasNext() ) {
            long val = iter.next();
            assertTrue( "value collection should only contain values: " + val + ", set; " + set,
                    list.contains( val ) );
            if ( val == vals[3] ) {
                iter.remove();
                assertFalse( "set contains removed element: " + val + ", set: " + set,
                        set.contains( val ) );
            }
View Full Code Here

        assertEquals( 2, map.size() );

        long[] values = map.values( new long[map.size()] );
        assertEquals( 2, values.length );
        TLongList values_list = new TLongArrayList( values );

        assertTrue( values_list.contains( 1 ) );
        assertTrue( values_list.contains( 2 ) );

        long[] values2 = map.values();
        assertEquals( 2, values2.length );
        TLongList keys_list2 = new TLongArrayList( values2 );

        assertTrue( keys_list2.contains( 1 ) );
        assertTrue( keys_list2.contains( 2 ) );

        int element_count = 20;
        map = new TIntLongHashMap();
        for ( int i = 0; i < element_count; i++ ) {
            map.put( i, i * i );
View Full Code Here

            }
        }

        ForEach foreach = new ForEach();
        map.forEachValue( foreach );
        TLongList built = foreach.getBuilt();
        TLongList vals = new TLongArrayList( map.values() );
        assertEquals( vals, built );

        built.sort();
        vals.sort();
        assertEquals( vals, built );


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


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

            TLongList getBuilt() {
                return built;
            }
        }

        ForEachFalse foreach_false = new ForEachFalse();
        map.forEachValue( foreach_false );
        built = foreach_false.getBuilt();
        vals = new TLongArrayList( map.values() );
        assertEquals( 1, built.size() );
        assertEquals( vals.get( 0 ), built.get( 0 ) );
    }
View Full Code Here

TOP

Related Classes of gnu.trove.list.TLongList

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.