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


Java TDecorators类代码示例

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


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

示例1: testSerialize

import gnu.trove.TDecorators; //导入依赖的package包/类
public void testSerialize() throws Exception {
    Integer[] ints = {1138, 42, 86, 99, 101};

    TIntSet raw_set = new TIntHashSet();
    Set<Integer> set = TDecorators.wrap( raw_set );
    set.addAll( Arrays.asList( ints ) );
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream( baos );
    oos.writeObject( set );

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

    //noinspection unchecked
    Set<Integer> deserialized = ( Set<Integer> ) ois.readObject();

    assertEquals( set, deserialized );
}
 
开发者ID:palantir,项目名称:trove-3.0.3,代码行数:19,代码来源:TPrimitiveSetDecoratorTest.java

示例2: testToArray

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

    Object[] res = set.toArray();
    Arrays.sort( ints );
    Arrays.sort( res );
    assertTrue( Arrays.equals( ints, res ) );

    res = set.toArray( new Integer[set.size()] );
    Arrays.sort( ints );
    Arrays.sort( res );
    assertTrue( Arrays.equals( ints, res ) );

}
 
开发者ID:palantir,项目名称:trove-3.0.3,代码行数:22,代码来源:TPrimitiveSetDecoratorTest.java

示例3: testSerialize

import gnu.trove.TDecorators; //导入依赖的package包/类
public void testSerialize() throws Exception {
    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 );

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream( baos );
    oos.writeObject( map );

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

    //noinspection unchecked
    Map<Integer,Long> deserialized = (Map<Integer,Long>) ois.readObject();

    assertEquals( map, deserialized );
}
 
开发者ID:leventov,项目名称:trove-over-koloboke-compile,代码行数:24,代码来源:TPrimitivePrimitiveMapDecoratorTest.java

示例4: testToArrayWithParams

import gnu.trove.TDecorators; //导入依赖的package包/类
public void testToArrayWithParams() {
    int no_entry_value = Integer.MIN_VALUE;
    TIntSet raw_set = new TIntHashSet( 10, 0.5f, no_entry_value );
    Set<Integer> set = TDecorators.wrap( raw_set );

    Integer[] ints = {42, 1138, 13, 86, 99};
    set.addAll( Arrays.asList( ints ) );

    Integer[] sink = new Integer[ints.length + 2];
    sink[sink.length - 1] = -1;
    sink[sink.length - 2] = -2;

    Integer[] res = set.toArray( sink );
    assertNull( res[set.size()] );

    Set<Integer> copy = new HashSet<Integer>();
    copy.addAll( Arrays.asList( sink ) );

    Set<Integer> bogey = new HashSet<Integer>();
    bogey.addAll( Arrays.asList( ints ) );
    bogey.add( -1 );
    bogey.add( null );
    assertEquals( bogey, copy );
}
 
开发者ID:palantir,项目名称:trove-3.0.3,代码行数:25,代码来源:TPrimitiveSetDecoratorTest.java

示例5: testHashcode

import gnu.trove.TDecorators; //导入依赖的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:palantir,项目名称:trove-3.0.3,代码行数:20,代码来源:TPrimitiveSetDecoratorTest.java

示例6: testPutAllMap

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

    TIntObjectMap<String> raw_control = new TIntObjectHashMap<String>();
    for (int i = 0; i < element_count; i++) {
        keys[i] = i + 1;
        vals[i] = Integer.toString(i + 1);
        raw_control.put(keys[i], vals[i]);
    }
    Map<Integer, String> control = TDecorators.wrap(raw_control);

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

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

    map.putAll(source);
    assertEquals(control, map);
}
 
开发者ID:leventov,项目名称:trove-over-koloboke-compile,代码行数:25,代码来源:TPrimitiveObjectMapDecoratorTest.java

示例7: testClear

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

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

    map.clear();
    assertEquals( 0, map.size() );
    assertTrue( map.isEmpty() );

    TIntLongMap raw_empty = new TIntLongHashMap();
    Map<Integer,Long> empty = TDecorators.wrap( raw_empty );
    assertEquals( empty, map );
}
 
开发者ID:palantir,项目名称:trove-3.0.3,代码行数:20,代码来源:TPrimitivePrimitiveMapDecoratorTest.java

示例8: testRemove

import gnu.trove.TDecorators; //导入依赖的package包/类
public void testRemove() {
    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] = Long.valueOf( keys[i] * 2 );
        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++ ) {
        assertEquals( vals[i], map.get( keys[i] ) );
    }
    assertEquals( vals[0], map.remove( keys[0] ) );
    assertEquals( vals[3], map.remove( keys[3] ) );
    assertNull( map.remove( keys[0] ) );
    assertEquals( vals[5], map.remove( keys[5] ) );
    assertNull( map.remove( 11010110 ) );

    assertNull( map.get( 1138 ) );
    //noinspection SuspiciousMethodCalls
    assertNull( map.get( Integer.valueOf( 1138 ) ) );
    assertNull( map.get( null ) );
}
 
开发者ID:palantir,项目名称:trove-3.0.3,代码行数:27,代码来源:TPrimitivePrimitiveMapDecoratorTest.java

示例9: 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

示例10: testClear

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

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

    map.clear();
    assertTrue(map.isEmpty());
    assertEquals(0, map.size());

    assertNull(map.get(keys[5]));
}
 
开发者ID:leventov,项目名称:trove-over-koloboke-compile,代码行数:21,代码来源:TPrimitiveObjectMapDecoratorTest.java

示例11: 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

示例12: testGet

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

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

    assertEquals(vals[10], map.get(Integer.valueOf(keys[10])));
    assertNull(map.get(Integer.valueOf(1138)));

    Integer key = Integer.valueOf(1138);
    map.put(key, null);
    assertTrue(map.containsKey(key));
    assertNull(map.get(key));

    Long long_key = Long.valueOf(1138);
    //noinspection SuspiciousMethodCalls
    assertNull(map.get(long_key));
}
 
开发者ID:palantir,项目名称:trove-3.0.3,代码行数:26,代码来源:TPrimitiveObjectMapDecoratorTest.java

示例13: testContainsKey

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

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

    for (int i = 0; i < element_count; i++) {
        assertTrue("Key should be present: " + keys[i] + ", map: " + map,
                map.containsKey(keys[i]));
    }

    int key = 1138;
    assertFalse("Key should not be present: " + key + ", map: " + map,
            map.containsKey(key));
}
 
开发者ID:palantir,项目名称:trove-3.0.3,代码行数:23,代码来源:TPrimitiveObjectMapDecoratorTest.java

示例14: testContainsValue

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

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

    for (int i = 0; i < element_count; i++) {
        assertTrue("Value should be present: " + vals[i] + ", map: " + map,
                map.containsValue(vals[i]));
    }

    String val = "1138";
    assertFalse("Key should not be present: " + val + ", map: " + map,
            map.containsValue(val));

    //noinspection SuspiciousMethodCalls
    assertFalse("Random object should not be present in map: " + map,
            map.containsValue(new Object()));
}
 
开发者ID:palantir,项目名称:trove-3.0.3,代码行数:27,代码来源:TPrimitiveObjectMapDecoratorTest.java

示例15: 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:palantir,项目名称:trove-3.0.3,代码行数:17,代码来源:TPrimitiveObjectMapDecoratorTest.java


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