当前位置: 首页>>代码示例>>Java>>正文


Java TDecorators.wrap方法代码示例

本文整理汇总了Java中gnu.trove.TDecorators.wrap方法的典型用法代码示例。如果您正苦于以下问题:Java TDecorators.wrap方法的具体用法?Java TDecorators.wrap怎么用?Java TDecorators.wrap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在gnu.trove.TDecorators的用法示例。


在下文中一共展示了TDecorators.wrap方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testPutAllMap

import gnu.trove.TDecorators; //导入方法依赖的package包/类
public void testPutAllMap() {
    int element_count = 20;
    String[] keys = new String[element_count];
    int[] vals = new int[element_count];

    TObjectIntMap<String> control = new TObjectIntHashMap<String>();
    for ( int i = 0; i < element_count; i++ ) {
        keys[i] = Integer.toString( i + 1 );
        vals[i] = i + 1;
        control.put( keys[i], vals[i] );
    }

    TObjectIntMap<String> raw_map = new TObjectIntHashMap<String>();
    Map<String,Integer> map = TDecorators.wrap( raw_map );

    Map<String, Integer> source = new HashMap<String, Integer>();
    for ( int i = 0; i < element_count; i++ ) {
        source.put( keys[i], vals[i] );
    }

    map.putAll( source );
    assertEquals( source, map );
    assertEquals( control, raw_map );
}
 
开发者ID:palantir,项目名称:trove-3.0.3,代码行数:25,代码来源:TObjectPrimitiveMapDecoratorTest.java

示例2: testValues

import gnu.trove.TDecorators; //导入方法依赖的package包/类
public void testValues() {
    int element_count = 20;
    String[] keys = new String[element_count];
    Integer[] vals = new Integer[element_count];

    TObjectIntMap<String> raw_map =
            new TObjectIntHashMap<String>( element_count, 0.5f, Integer.MIN_VALUE );
    Map<String,Integer> map = TDecorators.wrap( raw_map );

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

    // No argument
    Collection<Integer> values_collection = map.values();
    assertEquals( element_count, values_collection.size() );
    List<Integer> values_list = new ArrayList<Integer>( values_collection );
    for ( int i = 0; i < element_count; i++ ) {
        assertTrue( values_list.contains( vals[i] ) );
    }
}
 
开发者ID:palantir,项目名称:trove-3.0.3,代码行数:25,代码来源:TObjectPrimitiveMapDecoratorTest.java

示例3: testToArrayMatchesIteratorOrder

import gnu.trove.TDecorators; //导入方法依赖的package包/类
public void testToArrayMatchesIteratorOrder() {
    TIntSet raw_set = new TIntHashSet();
    Set<Integer> set = TDecorators.wrap( raw_set );
    Integer[] ints = {42, 1138, 13, 86, 99};
    set.addAll( Arrays.asList( ints ) );
    Integer[] toarray_ints = set.toArray( new Integer[ints.length] );

    Integer[] iter_ints = new Integer[ints.length];
    Iterator<Integer> 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,代码行数:18,代码来源:TPrimitiveSetDecoratorTest.java

示例4: testPutAll

import gnu.trove.TDecorators; //导入方法依赖的package包/类
public void testPutAll() throws Exception {
    TIntObjectMap<String> raw_t = new TIntObjectHashMap<String>();
    Map<Integer, String> t = TDecorators.wrap(raw_t);
    TIntObjectMap<String> raw_m = new TIntObjectHashMap<String>();
    Map<Integer, String> m = TDecorators.wrap(raw_m);
    m.put(2, "one");
    m.put(4, "two");
    m.put(6, "three");

    t.put(5, "four");
    assertEquals(1, t.size());

    t.putAll(m);
    assertEquals(4, t.size());
    assertEquals("two", t.get(4));
}
 
开发者ID:leventov,项目名称:trove-over-koloboke-compile,代码行数:17,代码来源:TPrimitiveObjectMapDecoratorTest.java

示例5: testRehash

import gnu.trove.TDecorators; //导入方法依赖的package包/类
/** Be sure that size is large enough to force a resize or two. */
public void testRehash() {
    int size = 1000;
    int[] keys = new int[size];
    long[] vals = new long[size];
    for ( int i = 0; i < size; i++ ) {
        keys[i] = i + 1;
        vals[i] = keys[i] * 2;
    }

    TIntLongMap raw_map = new TIntLongHashMap();
    for ( int i = 0; i < keys.length; i++ ) {
        raw_map.put( keys[i], vals[i] );
    }
    Map<Integer,Long> map = TDecorators.wrap( raw_map );
    assertEquals( keys.length, map.size() );
    for ( int i = 0; i < keys.length; i++ ) {
        Integer key = keys[i];
        Long val = vals[i];
        assertEquals( "got incorrect value for index " + i + ", map: " + map,
                val, map.get( key ) );
    }
}
 
开发者ID:palantir,项目名称:trove-3.0.3,代码行数:24,代码来源:TPrimitivePrimitiveMapDecoratorTest.java

示例6: testIsEmpty

import gnu.trove.TDecorators; //导入方法依赖的package包/类
public void testIsEmpty() throws Exception {
    TIntSet raw_set = new TIntHashSet();
    Set<Integer> set = TDecorators.wrap( raw_set );
    assertTrue( "new set wasn't empty", set.isEmpty() );

    set.add( 1 );
    assertFalse( "set with element reports empty", set.isEmpty() );
    set.clear();
    assertTrue( "cleared set reports not-empty", set.isEmpty() );
}
 
开发者ID:palantir,项目名称:trove-3.0.3,代码行数:11,代码来源:TPrimitiveSetDecoratorTest.java

示例7: testContains

import gnu.trove.TDecorators; //导入方法依赖的package包/类
public void testContains() throws Exception {
    TIntSet raw_set = new TIntHashSet();
    Set<Integer> set = TDecorators.wrap( raw_set );
    int i = 100;
    set.add( i );
    assertTrue( "contains failed", set.contains( i ) );
    assertFalse( "contains failed", set.contains( 1000 ) );
}
 
开发者ID:palantir,项目名称:trove-3.0.3,代码行数:9,代码来源:TPrimitiveSetDecoratorTest.java

示例8: testValueCollectionHashCode

import gnu.trove.TDecorators; //导入方法依赖的package包/类
public void testValueCollectionHashCode() {
    int element_count = 20;
    String[] keys = new String[element_count];
    int[] vals = new int[element_count];

    TObjectIntMap<String> raw_map = new TObjectIntHashMap<String>();
    Map<String,Integer> map = TDecorators.wrap( raw_map );

    TObjectIntMap<String> raw_map2 = new TObjectIntHashMap<String>();
    Map<String,Integer> map2 = TDecorators.wrap( raw_map2 );

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

    Collection<Integer> values = map.values();
    Collection<Integer> other = map2.values();

    assertTrue( values.hashCode() == values.hashCode() );
    assertTrue( other.hashCode() == other.hashCode() );

    map2.put( String.valueOf( 1138 ), 1138 );
    assertFalse( values.hashCode() == other.hashCode() );
}
 
开发者ID:leventov,项目名称:trove-over-koloboke-compile,代码行数:29,代码来源:TObjectPrimitiveMapDecoratorTest.java

示例9: testRemove

import gnu.trove.TDecorators; //导入方法依赖的package包/类
public void testRemove() throws Exception {
    TIntSet raw_set = new TIntHashSet();
    Set<Integer> set = TDecorators.wrap( raw_set );
    set.add( 1 );
    set.add( 2 );
    assertTrue( "One was not added", set.contains( 1 ) );
    assertTrue( "One was not removed", set.remove( 1 ) );
    assertFalse( "One was not removed", set.contains( 1 ) );
    assertTrue( "Two was also removed", set.contains( 2 ) );
}
 
开发者ID:leventov,项目名称:trove-over-koloboke-compile,代码行数:11,代码来源:TPrimitiveSetDecoratorTest.java

示例10: testEquals

import gnu.trove.TDecorators; //导入方法依赖的package包/类
public void testEquals() {
    int element_count = 20;
    String[] keys = new String[element_count];
    int[] vals = new int[element_count];

    TObjectIntMap<String> raw_map =
            new TObjectIntHashMap<String>( element_count, 0.5f, Integer.MIN_VALUE );
    Map<String,Integer> map = TDecorators.wrap( raw_map );

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

    TObjectIntHashMap<String> raw_fully_specified =
            new TObjectIntHashMap<String>( 20, 0.75f, Integer.MIN_VALUE );
    Map<String,Integer> fully_specified = TDecorators.wrap( raw_fully_specified );

    for ( int i = 0; i < element_count; i++ ) {
        fully_specified.put( keys[i], vals[i] );
    }
    assertEquals( map, fully_specified );

    assertFalse( "shouldn't equal random object", map.equals( new Object() ) );
    //noinspection ObjectEqualsNull
    assertFalse( "shouldn't equal null", map.equals( null ) );
}
 
开发者ID:palantir,项目名称:trove-3.0.3,代码行数:30,代码来源:TObjectPrimitiveMapDecoratorTest.java

示例11: testValueCollectionRemoveAllCollection

import gnu.trove.TDecorators; //导入方法依赖的package包/类
public void testValueCollectionRemoveAllCollection() {
    int element_count = 20;
    String[] keys = new String[element_count];
    int[] vals = new int[element_count];

    TObjectIntMap<String> raw_map = new TObjectIntHashMap<String>();
    Map<String,Integer> map = TDecorators.wrap( raw_map );

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

    Collection<Integer> collection = map.values();
    for ( int i = 0; i < collection.size(); i++ ) {
        assertTrue( collection.contains( vals[i] ) );
    }
    assertFalse( collection.isEmpty() );

    List<Integer> java_list = new ArrayList<Integer>();
    assertFalse( "collection: " + collection + ", should contain all in list: " +
                 java_list, collection.removeAll( java_list ) );

    java_list.add( vals[5] );
    assertTrue( "collection: " + collection + ", should contain all in list: " +
                java_list, collection.removeAll( java_list ) );
    assertFalse( collection.contains( vals[5] ) );
    assertFalse( map.containsKey( keys[5] ) );
    assertFalse( map.containsValue( vals[5] ) );

    java_list = new ArrayList<Integer>();
    for ( int value : vals ) {
        java_list.add( value );
    }
    assertTrue( "collection: " + collection + ", should contain all in list: " +
                java_list, collection.removeAll( java_list ) );
    assertTrue( collection.isEmpty() );
}
 
开发者ID:leventov,项目名称:trove-over-koloboke-compile,代码行数:41,代码来源:TObjectPrimitiveMapDecoratorTest.java

示例12: testSize

import gnu.trove.TDecorators; //导入方法依赖的package包/类
public void testSize() throws Exception {
    TIntSet raw_set = new TIntHashSet();
    Set<Integer> set = TDecorators.wrap( raw_set );
    assertEquals( "initial size was not 0", 0, set.size() );

    for ( int i = 0; i < 99; i++ ) {
        set.add( i );
        assertEquals( "size did not increase after add", i + 1, set.size() );
    }
}
 
开发者ID:leventov,项目名称:trove-over-koloboke-compile,代码行数:11,代码来源:TPrimitiveSetDecoratorTest.java

示例13: testIteratorRemove

import gnu.trove.TDecorators; //导入方法依赖的package包/类
public void testIteratorRemove() {

        TIntSet raw_set = new TIntHashSet();
        Set<Integer> set = TDecorators.wrap( raw_set );
        set.add( 1 );
        set.add( 2 );
        set.add( 3 );
        set.add( 4 );

        Iterator<Integer> iter = set.iterator();
        assertTrue( "iterator should have a next item", iter.hasNext() );

        int last = -1;
        while ( iter.hasNext() ) {
            int next = iter.next();
            assertTrue( next >= 1 && next <= 4 );
            assertTrue( next != last );
            last = next;

            if ( next == 3 ) {
                iter.remove();
            }
        }

        assertFalse( "iterator should not have a next item", iter.hasNext() );

        assertFalse( "set should not contain 3", set.contains( 3 ) );
        assertTrue( "set should contain 1", set.contains( 1 ) );
        assertTrue( "set should contain 2", set.contains( 2 ) );
        assertTrue( "set should contain 4", set.contains( 4 ) );
        assertEquals( 3, set.size() );

    }
 
开发者ID:leventov,项目名称:trove-over-koloboke-compile,代码行数:34,代码来源:TPrimitiveSetDecoratorTest.java

示例14: testKeys

import gnu.trove.TDecorators; //导入方法依赖的package包/类
public void testKeys() {
    int element_count = 20;
    String[] keys = new String[element_count];
    int[] vals = new int[element_count];

    TObjectIntMap<String> raw_map = new TObjectIntHashMap<String>();
    Map<String,Integer> map = TDecorators.wrap( raw_map );

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

    // No argument
    Object[] keys_object_array = map.keySet().toArray();
    assertEquals( element_count, keys_object_array.length );
    List<Object> keys_object_list = Arrays.asList( keys_object_array );
    for ( int i = 0; i < element_count; i++ ) {
        assertTrue( keys_object_list.contains( keys[i] ) );
    }

    // Zero length array
    //noinspection ToArrayCallWithZeroLengthArrayArgument
    String[] keys_string_array = map.keySet().toArray( new String[0] );
    assertEquals( element_count, keys_string_array.length );
    List<String> keys_string_list = Arrays.asList( keys_string_array );
    for ( int i = 0; i < element_count; i++ ) {
        assertTrue( keys_string_list.contains( keys[i] ) );
    }

    // appropriate length array
    keys_string_array = map.keySet().toArray( new String[map.size()] );
    assertEquals( element_count, keys_string_array.length );
    keys_string_list = Arrays.asList( keys_string_array );
    for ( int i = 0; i < element_count; i++ ) {
        assertTrue( keys_string_list.contains( keys[i] ) );
    }

    // longer array
    keys_string_array = map.keySet().toArray( new String[element_count * 2] );
    assertEquals( element_count * 2, keys_string_array.length );
    keys_string_list = Arrays.asList( keys_string_array );
    for ( int i = 0; i < element_count; i++ ) {
        assertTrue( keys_string_list.contains( keys[i] ) );
    }
    assertNull( keys_string_array[element_count] );
}
 
开发者ID:palantir,项目名称:trove-3.0.3,代码行数:50,代码来源:TObjectPrimitiveMapDecoratorTest.java

示例15: testKeySetMisc

import gnu.trove.TDecorators; //导入方法依赖的package包/类
public void testKeySetMisc() {
    int[] keys = {1138, 42, 86, 99, 101, 727, 117};
    long[] vals = new long[keys.length];

    TIntLongMap raw_map = new TIntLongHashMap();
    for ( int i = 0; i < keys.length; i++ ) {
        vals[i] = keys[i] * 2;
        raw_map.put( keys[i], vals[i] );
    }
    Map<Integer,Long> map = TDecorators.wrap( raw_map );

    Set<Integer> set = map.keySet();
    Integer[] sorted_keys = new Integer[keys.length];
    for ( int i = 0; i < keys.length; i++ ) {
        sorted_keys[i] = keys[i];
    }
    Arrays.sort( sorted_keys );
    Integer[] setarray = set.toArray( new Integer[set.size()] );
    Arrays.sort( setarray );
    assertTrue( "expected: " + Arrays.toString( sorted_keys ) +
                ", was: " + Arrays.toString( setarray ),
            Arrays.equals( sorted_keys, setarray ) );

    //noinspection ToArrayCallWithZeroLengthArrayArgument
    setarray = set.toArray( new Integer[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 set succeded: " + set, set.remove( 1 ) );
    assertEquals( keys.length, set.size() );
    assertEquals( keys.length, map.size() );

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

    try {
        set.add( 42 );
        fail( "Expected UnsupportedOperationException" );
    }
    catch ( UnsupportedOperationException ex ) {
        // Expected
    }
}
 
开发者ID:leventov,项目名称:trove-over-koloboke-compile,代码行数:47,代码来源:TPrimitivePrimitiveMapDecoratorTest.java


注:本文中的gnu.trove.TDecorators.wrap方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。