當前位置: 首頁>>代碼示例>>Java>>正文


Java TIntSet.addAll方法代碼示例

本文整理匯總了Java中gnu.trove.set.TIntSet.addAll方法的典型用法代碼示例。如果您正苦於以下問題:Java TIntSet.addAll方法的具體用法?Java TIntSet.addAll怎麽用?Java TIntSet.addAll使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在gnu.trove.set.TIntSet的用法示例。


在下文中一共展示了TIntSet.addAll方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testEquals

import gnu.trove.set.TIntSet; //導入方法依賴的package包/類
public void testEquals() {
    int[] ints = {1138, 42, 86, 99, 101};
    TIntSet set = new TIntHashSet();
    set.addAll(ints);
    TIntSet other = new TIntHashSet();
    other.addAll(ints);

    assertTrue("sets incorrectly not equal: " + set + ", " + other,
            set.equals(other));

    int[] mismatched = {72, 49, 53, 1024, 999};
    TIntSet unequal = new TIntHashSet();
    unequal.addAll(mismatched);

    assertFalse("sets incorrectly equal: " + set + ", " + unequal,
            set.equals(unequal));

    // Change length, different code branch
    unequal.add(1);
    assertFalse("sets incorrectly equal: " + set + ", " + unequal,
            set.equals(unequal));
}
 
開發者ID:leventov,項目名稱:trove-over-koloboke-compile,代碼行數:23,代碼來源:TPrimitiveHashSetTest.java

示例2: testToArrayMatchesIteratorOrder

import gnu.trove.set.TIntSet; //導入方法依賴的package包/類
public void testToArrayMatchesIteratorOrder() {
    TIntSet set = new TIntHashSet();
    int[] ints = {42, 1138, 13, 86, 99};
    set.addAll(ints);
    int[] toarray_ints = set.toArray();

    int[] iter_ints = new int[5];
    TIntIterator iter = set.iterator();

    int index = 0;
    while (iter.hasNext()) {
        iter_ints[index++] = iter.next();
    }

    assertTrue(Arrays.equals(iter_ints, toarray_ints));
}
 
開發者ID:leventov,項目名稱:trove-over-koloboke-compile,代碼行數:17,代碼來源:TPrimitiveHashSetTest.java

示例3: testHashcode

import gnu.trove.set.TIntSet; //導入方法依賴的package包/類
public void testHashcode() {
    int[] ints = {1138, 42, 86, 99, 101};
    TIntSet raw_set = new TIntHashSet();
    raw_set.addAll( ints );
    Set<Integer> set = TDecorators.wrap( raw_set );
    TIntSet raw_other = new TIntHashSet();
    raw_other.addAll( ints );
    Set<Integer> other = TDecorators.wrap( raw_other );

    assertTrue( "hashcodes incorrectly not equal: " + set + ", " + other,
            set.hashCode() == other.hashCode() );

    int[] mismatched = {72, 49, 53, 1024, 999};
    TIntSet unequal = new TIntHashSet();
    unequal.addAll( mismatched );

    assertFalse( "hashcodes unlikely equal: " + set + ", " + unequal,
            set.hashCode() == unequal.hashCode() );
}
 
開發者ID:leventov,項目名稱:trove-over-koloboke-compile,代碼行數:20,代碼來源:TPrimitiveSetDecoratorTest.java

示例4: testSerialize

import gnu.trove.set.TIntSet; //導入方法依賴的package包/類
public void testSerialize() throws Exception {
    int[] ints = {1138, 42, 86, 99, 101};

    TIntSet set = new TIntHashSet();
    set.addAll(ints);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(baos);
    oos.writeObject(set);

    ByteArrayInputStream bias = new ByteArrayInputStream(baos.toByteArray());
    ObjectInputStream ois = new ObjectInputStream(bias);

    TIntSet deserialized = (TIntSet) ois.readObject();

    assertEquals(set, deserialized);
}
 
開發者ID:leventov,項目名稱:trove-over-koloboke-compile,代碼行數:17,代碼來源:TPrimitiveHashSetTest.java

示例5: testToArrayMatchesIteratorOrder

import gnu.trove.set.TIntSet; //導入方法依賴的package包/類
public void testToArrayMatchesIteratorOrder() {
    TIntSet set = new TIntOffheapHashSet();
    int[] ints = {42, 1138, 13, 86, 99};
    set.addAll(ints);
    int[] toarray_ints = set.toArray();

    int[] iter_ints = new int[5];
    TIntIterator iter = set.iterator();

    int index = 0;
    while (iter.hasNext()) {
        iter_ints[index++] = iter.next();
    }

    assertTrue(Arrays.equals(iter_ints, toarray_ints));
}
 
開發者ID:palantir,項目名稱:trove-3.0.3,代碼行數:17,代碼來源:TPrimitiveOffheapHashSetTest.java

示例6: testKeySetEquals

import gnu.trove.set.TIntSet; //導入方法依賴的package包/類
public void testKeySetEquals() {
    int[] keys = {1138, 42, 86, 99, 101, 727, 117};
    long[] vals = new long[keys.length];

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

    TIntSet set = map.keySet();
    assertEquals( map.size(), set.size() );
    assertFalse( set.isEmpty() );

    TIntSet other = new TIntHashSet();
    other.addAll( keys );

    assertTrue( "sets incorrectly not equal: " + set + ", " + other,
            set.equals( other ) );

    int[] mismatched = {72, 49, 53, 1024, 999};
    TIntSet unequal = new TIntHashSet();
    unequal.addAll( mismatched );

    assertFalse( "sets incorrectly equal: " + set + ", " + unequal,
            set.equals( unequal ) );

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

    assertFalse( "set incorrectly equals a random object",
            set.equals( new Object() ) );
}
 
開發者ID:palantir,項目名稱:trove-3.0.3,代碼行數:36,代碼來源:TPrimitivePrimitiveHashMapTest.java

示例7: testToArray

import gnu.trove.set.TIntSet; //導入方法依賴的package包/類
public void testToArray() {
    TIntSet set = new TIntHashSet();
    int[] ints = {42, 1138, 13, 86, 99};
    set.addAll(ints);
    int[] res = set.toArray();
    Arrays.sort(ints);
    Arrays.sort(res);
    assertTrue(Arrays.equals(ints, res));
}
 
開發者ID:leventov,項目名稱:trove-over-koloboke-compile,代碼行數:10,代碼來源:TPrimitiveHashSetTest.java

示例8: testKeySetEquals

import gnu.trove.set.TIntSet; //導入方法依賴的package包/類
public void testKeySetEquals() {
    int[] keys = {1138, 42, 86, 99, 101, 727, 117};
    long[] vals = new long[keys.length];

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

    TIntSet set = map.keySet();
    assertEquals( map.size(), set.size() );
    assertFalse( set.isEmpty() );

    TIntSet other = new TIntHashSet();
    other.addAll( keys );

    assertTrue( "sets incorrectly not equal: " + set + ", " + other,
            set.equals( other ) );

    int[] mismatched = {72, 49, 53, 1024, 999};
    TIntSet unequal = new TIntHashSet();
    unequal.addAll( mismatched );

    assertFalse( "sets incorrectly equal: " + set + ", " + unequal,
            set.equals( unequal ) );

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

    assertFalse( "set incorrectly equals a random object",
            set.equals( new Object() ) );
}
 
開發者ID:palantir,項目名稱:trove-3.0.3,代碼行數:36,代碼來源:TPrimitivePrimitiveOffheapHashMapTest.java

示例9: testKeySetEqual

import gnu.trove.set.TIntSet; //導入方法依賴的package包/類
public void testKeySetEqual() {
    int element_count = 20;
    int[] keys = new int[element_count];
    String[] vals = new String[element_count];

    TIntObjectMap<String> map = new TIntObjectHashMap<String>();
    for ( int i = 0; i < element_count; i++ ) {
        keys[i] = i + 1;
        vals[i] = Integer.toString( i + 1 );
        map.put( keys[i], vals[i] );
    }
    assertEquals( element_count, map.size() );

    TIntSet keyset = map.keySet();
    for ( int i = 0; i < keyset.size(); i++ ) {
        assertTrue( keyset.contains( keys[i] ) );
    }
    assertFalse( keyset.isEmpty() );

    TIntSet other = new TIntHashSet();
    other.addAll( keys );

    assertTrue( "sets incorrectly not equal: " + keyset + ", " + other,
            keyset.equals( other ) );

    int[] mismatched = {72, 49, 53, 1024, 999};
    TIntSet unequal = new TIntHashSet();
    unequal.addAll( mismatched );

    assertFalse( "sets incorrectly equal: " + keyset + ", " + unequal,
            keyset.equals( unequal ) );

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

    //noinspection ObjectEqualsNull
    assertFalse( keyset.equals( null ) );
}
 
開發者ID:leventov,項目名稱:trove-over-koloboke-compile,代碼行數:41,代碼來源:TPrimitiveObjectHashMapTest.java

示例10: testKeySetHashCode

import gnu.trove.set.TIntSet; //導入方法依賴的package包/類
public void testKeySetHashCode() {
    int[] keys = {1138, 42, 86, 99, 101, 727, 117};
    long[] vals = new long[keys.length];

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

    TIntSet set = map.keySet();
    assertEquals( map.size(), set.size() );
    assertFalse( set.isEmpty() );
    

    TIntSet other = new TIntHashSet();
    other.addAll( keys );

    assertTrue( "hashcodes incorrectly not equal: " + set + ", " + other,
            set.hashCode() == other.hashCode() );

    int[] mismatched = {72, 49, 53, 1024, 999};
    TIntSet unequal = new TIntHashSet();
    unequal.addAll( mismatched );

    assertFalse( "hashcodes unlikely equal: " + set + ", " + unequal,
            set.hashCode() == unequal.hashCode() );
}
 
開發者ID:leventov,項目名稱:trove-over-koloboke-compile,代碼行數:29,代碼來源:TPrimitivePrimitiveHashMapTest.java

示例11: testClear

import gnu.trove.set.TIntSet; //導入方法依賴的package包/類
public void testClear() throws Exception {
    TIntSet set = new TIntHashSet();
    set.addAll(new int[]{1, 2, 3});
    assertEquals("size was not 3", 3, set.size());
    set.clear();
    assertEquals("initial size was not 0", 0, set.size());
}
 
開發者ID:palantir,項目名稱:trove-3.0.3,代碼行數:8,代碼來源:TPrimitiveHashSetTest.java

示例12: testRemoveAll

import gnu.trove.set.TIntSet; //導入方法依賴的package包/類
public void testRemoveAll() throws Exception {

        int[] ints = {1138, 42, 13, 86, 99, 101};

        TIntSet set = new TIntOffheapHashSet();
        set.addAll(ints);

        TIntSet other = new TIntOffheapHashSet();
        other.addAll(ints);

        int[] to_remove = {13, 86, 99, 1138};

        TIntSet remove_set = new TIntOffheapHashSet();
        remove_set.addAll(to_remove);

        List<Integer> remove_list = new ArrayList<Integer>();
        for (int element : to_remove) {
            remove_list.add(element);
        }

        int[] remainder = {42, 101};

        try {
            assertFalse("removeAll(TIntSet) failed (same set): " + set,
                    set.removeAll(set));
            fail("should have thrown ConcurrentModificationException");
        } catch (ConcurrentModificationException cme) {
            // expected exception thrown.
        }

        // reset the set.
        set = new TIntOffheapHashSet();
        set.addAll(ints);
        assertTrue("removeAll(Collection<?>) failed: " + set,
                set.removeAll(remove_list));
        // Contains just the expected elements
        assertTrue(set.toString(), set.containsAll(remainder));
        assertFalse(set.toString(), set.containsAll(to_remove));
        assertTrue(remove_set.toString(), remove_set.containsAll(to_remove));

        // reset the set.
        set = new TIntOffheapHashSet();
        set.addAll(ints);
        assertTrue("removeAll(TIntSet) failed: " + set,
                set.removeAll(remove_set));
        // Contains just the expected elements
        assertTrue(set.toString(), set.containsAll(remainder));
        assertFalse(set.toString(), set.containsAll(to_remove));
        assertTrue(remove_set.toString(), remove_set.containsAll(to_remove));

        // reset the set.
        set = new TIntOffheapHashSet();
        set.addAll(ints);
        assertTrue("removeAll(int[]) failed: " + set,
                set.removeAll(to_remove));
        // Contains just the expected elements
        assertTrue(set.toString(), set.containsAll(remainder));
        assertFalse(set.toString(), set.containsAll(to_remove));
        assertTrue(remove_set.toString(), remove_set.containsAll(to_remove));
    }
 
開發者ID:palantir,項目名稱:trove-3.0.3,代碼行數:61,代碼來源:TPrimitiveOffheapHashSetTest.java

示例13: testRetainAll

import gnu.trove.set.TIntSet; //導入方法依賴的package包/類
public void testRetainAll() throws Exception {

        int[] ints = {1138, 42, 13, 86, 99, 101};

        TIntSet set = new TIntHashSet();
        set.addAll(ints);

        TIntSet other = new TIntHashSet();
        other.addAll(ints);

        int[] to_retain = {13, 86, 99, 1138};

        TIntSet retain_set = new TIntHashSet();
        retain_set.addAll(to_retain);

        List<Integer> retain_list = new ArrayList<Integer>();
        for (int element : to_retain) {
            retain_list.add(element);
        }

        assertFalse("retainAll(TIntSet) failed (same set): " + set,
                set.retainAll(set));
        // Contains all the original elements
        assertTrue(set.toString(), set.containsAll(ints));
        assertTrue(retain_set.toString(), retain_set.containsAll(to_retain));

        assertTrue("retainAll(Collection<?>) failed: " + set,
                set.retainAll(retain_list));
        // Contains just the expected elements
        assertFalse(set.toString(), set.containsAll(ints));
        assertTrue(set.toString(), set.containsAll(to_retain));
        assertTrue(retain_set.toString(), retain_set.containsAll(to_retain));

        // reset the set.
        set = new TIntHashSet();
        set.addAll(ints);
        assertTrue("retainAll(TIntSet) failed: " + set,
                set.retainAll(retain_set));
        // Contains just the expected elements
        assertFalse(set.toString(), set.containsAll(ints));
        assertTrue(set.toString(), set.containsAll(to_retain));
        assertTrue(retain_set.toString(), retain_set.containsAll(to_retain));

        // reset the set.
        set = new TIntHashSet();
        set.addAll(ints);
        assertTrue("retainAll(int[]) failed: " + set,
                set.retainAll(to_retain));
        // Contains just the expected elements
        assertFalse(set.toString(), set.containsAll(ints));
        assertTrue(set.toString(), set.containsAll(to_retain));
        assertTrue(retain_set.toString(), retain_set.containsAll(to_retain));
    }
 
開發者ID:leventov,項目名稱:trove-over-koloboke-compile,代碼行數:54,代碼來源:TPrimitiveHashSetTest.java

示例14: testEquals

import gnu.trove.set.TIntSet; //導入方法依賴的package包/類
public void testEquals() {
    Integer[] ints = {1138, 42, 86, 99, 101};
    TIntSet raw_set = new TIntHashSet();
    Set<Integer> set = TDecorators.wrap( raw_set );
    set.addAll( Arrays.asList( ints ) );
    TIntSet raw_other = new TIntHashSet();
    Set<Integer> other = TDecorators.wrap( raw_other );
    other.addAll( Arrays.asList( ints ) );

    assertTrue( "sets incorrectly not equal: " + set + ", " + other,
            set.equals( other ) );

    int[] mismatched = {72, 49, 53, 1024, 999};
    TIntSet raw_unequal = new TIntHashSet();
    raw_unequal.addAll( mismatched );
    Set<Integer> unequal = TDecorators.wrap( raw_unequal );

    assertFalse( "sets incorrectly equal: " + set + ", " + unequal,
            set.equals( unequal ) );

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

    Set<Number> different_classes = new HashSet<Number>();
    different_classes.addAll( Arrays.asList( ints ) );
    different_classes.remove( Integer.valueOf( 86 ) );
    different_classes.add( Long.valueOf( 86 ) );
    assertFalse( "sets incorrectly equal: " + set + ", " + different_classes,
            set.equals( different_classes ) );

    //noinspection ObjectEqualsNull
    assertFalse( set.equals( null ) );

    // test against TIntSet
    assertTrue( set.equals( raw_other ) );

    //noinspection MismatchedQueryAndUpdateOfCollection 
    TIntSetDecorator decorated = new TIntSetDecorator( raw_other );
    assertTrue( set.equals( decorated.getSet() ) );
}
 
開發者ID:leventov,項目名稱:trove-over-koloboke-compile,代碼行數:43,代碼來源:TPrimitiveSetDecoratorTest.java

示例15: testRemoveAll

import gnu.trove.set.TIntSet; //導入方法依賴的package包/類
public void testRemoveAll() throws Exception {

        int[] ints = {1138, 42, 13, 86, 99, 101};

        TIntSet set = new TIntHashSet();
        set.addAll(ints);

        TIntSet other = new TIntHashSet();
        other.addAll(ints);

        int[] to_remove = {13, 86, 99, 1138};

        TIntSet remove_set = new TIntHashSet();
        remove_set.addAll(to_remove);

        List<Integer> remove_list = new ArrayList<Integer>();
        for (int element : to_remove) {
            remove_list.add(element);
        }

        int[] remainder = {42, 101};

        try {
            assertFalse("removeAll(TIntSet) failed (same set): " + set,
                    set.removeAll(set));
            fail("should have thrown ConcurrentModificationException");
        } catch (ConcurrentModificationException cme) {
            // expected exception thrown.
        }

        // reset the set.
        set = new TIntHashSet();
        set.addAll(ints);
        assertTrue("removeAll(Collection<?>) failed: " + set,
                set.removeAll(remove_list));
        // Contains just the expected elements
        assertTrue(set.toString(), set.containsAll(remainder));
        assertFalse(set.toString(), set.containsAll(to_remove));
        assertTrue(remove_set.toString(), remove_set.containsAll(to_remove));

        // reset the set.
        set = new TIntHashSet();
        set.addAll(ints);
        assertTrue("removeAll(TIntSet) failed: " + set,
                set.removeAll(remove_set));
        // Contains just the expected elements
        assertTrue(set.toString(), set.containsAll(remainder));
        assertFalse(set.toString(), set.containsAll(to_remove));
        assertTrue(remove_set.toString(), remove_set.containsAll(to_remove));

        // reset the set.
        set = new TIntHashSet();
        set.addAll(ints);
        assertTrue("removeAll(int[]) failed: " + set,
                set.removeAll(to_remove));
        // Contains just the expected elements
        assertTrue(set.toString(), set.containsAll(remainder));
        assertFalse(set.toString(), set.containsAll(to_remove));
        assertTrue(remove_set.toString(), remove_set.containsAll(to_remove));
    }
 
開發者ID:palantir,項目名稱:trove-3.0.3,代碼行數:61,代碼來源:TPrimitiveHashSetTest.java


注:本文中的gnu.trove.set.TIntSet.addAll方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。