本文整理匯總了Java中gnu.trove.set.TIntSet類的典型用法代碼示例。如果您正苦於以下問題:Java TIntSet類的具體用法?Java TIntSet怎麽用?Java TIntSet使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
TIntSet類屬於gnu.trove.set包,在下文中一共展示了TIntSet類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: equals
import gnu.trove.set.TIntSet; //導入依賴的package包/類
/** {@inheritDoc) */
public boolean equals( Object other ) {
if (! ( other instanceof TIntSet ) ) {
return false;
}
final TIntSet that = ( TIntSet ) other;
if ( that.size() != this.size() ) {
return false;
}
for ( int i = _states.length; i-- > 0; ) {
if ( _states[i] == FULL ) {
if ( ! that.contains( _set[i] ) ) {
return false;
}
}
}
return true;
}
示例2: equals
import gnu.trove.set.TIntSet; //導入依賴的package包/類
/** {@inheritDoc} */
public boolean equals( Object other ) {
if ( ! ( other instanceof TIntSet ) ) {
return false;
}
TIntSet that = ( TIntSet ) other;
if ( that.size() != this.size() ) {
return false;
}
for ( int i = _states.length; i-- > 0; ) {
if ( _states[i] == FULL ) {
if ( ! that.contains( _set[i] ) ) {
return false;
}
}
}
return true;
}
示例3: equals
import gnu.trove.set.TIntSet; //導入依賴的package包/類
public boolean equals( Object other ) {
if (! ( other instanceof TIntSet ) ) {
return false;
}
final TIntSet that = ( TIntSet ) other;
if ( that.size() != this.size() ) {
return false;
}
for ( int i = _states.length; i-- > 0; ) {
if ( _states[i] == FULL ) {
if ( ! that.contains( _set[i] ) ) {
return false;
}
}
}
return true;
}
示例4: distinct
import gnu.trove.set.TIntSet; //導入依賴的package包/類
@Override
public final Array<Integer> distinct(int limit) {
final int capacity = limit < Integer.MAX_VALUE ? limit : 100;
final TIntSet set = new TIntHashSet(capacity);
final ArrayBuilder<Integer> builder = ArrayBuilder.of(capacity, Integer.class);
for (int i=0; i<length(); ++i) {
final int value = getInt(i);
if (set.add(value)) {
builder.addInt(value);
if (set.size() >= limit) {
break;
}
}
}
return builder.toArray();
}
示例5: distinct
import gnu.trove.set.TIntSet; //導入依賴的package包/類
@Override
public Array<T> distinct(int limit) {
final int capacity = limit < Integer.MAX_VALUE ? limit : 100;
final TIntSet set = new TIntHashSet(capacity);
final ArrayBuilder<T> builder = ArrayBuilder.of(capacity, type());
for (int i=0; i<length(); ++i) {
final int code = getInt(i);
if (set.add(code)) {
final T value = getValue(i);
builder.add(value);
if (set.size() >= limit) {
break;
}
}
}
return builder.toArray();
}
示例6: testHashcode
import gnu.trove.set.TIntSet; //導入依賴的package包/類
public void testHashcode() {
int[] ints = {1138, 42, 86, 99, 101};
TIntSet set = new TIntHashSet();
set.addAll(ints);
TIntSet other = new TIntHashSet();
other.addAll(ints);
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());
}
示例7: testKeySetHashCode
import gnu.trove.set.TIntSet; //導入依賴的package包/類
public void testKeySetHashCode() {
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() );
assertEquals( keyset.hashCode(), keyset.hashCode() );
TIntSet other = new TIntHashSet( keys );
other.add( 1138 );
assertTrue( keyset.hashCode() != other.hashCode() );
}
示例8: testToArray
import gnu.trove.set.TIntSet; //導入依賴的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 ) );
}
示例9: 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));
}
示例10: testEquals
import gnu.trove.set.TIntSet; //導入依賴的package包/類
public void testEquals() {
int[] ints = {1138, 42, 86, 99, 101};
TIntSet set = new TIntOffheapHashSet();
set.addAll(ints);
TIntSet other = new TIntOffheapHashSet();
other.addAll(ints);
assertTrue("sets incorrectly not equal: " + set + ", " + other,
set.equals(other));
int[] mismatched = {72, 49, 53, 1024, 999};
TIntSet unequal = new TIntOffheapHashSet();
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));
}
示例11: getRatings_shouldReturnAllRatingsOfUser
import gnu.trove.set.TIntSet; //導入依賴的package包/類
@Test
public void getRatings_shouldReturnAllRatingsOfUser() {
TIntSet itemTypeIds = new TIntHashSet(new int[]{1});
List<RatingVO<Integer, Integer>> ratings = actionDAO.getRatings(1, itemTypeIds, 1);
assertThat(ratings.size(), is(4));
assertThat(ratings, hasItem(equalTo(createRating(1, 1, 1, "2007-04-15 12:11:00.0"))));
assertThat(ratings, hasItem(equalTo(createRating(2, 1, 2, "2007-04-15 12:12:00.0"))));
assertThat(ratings, hasItem(equalTo(createRating(3, 1, 3, "2007-04-15 12:13:00.0"))));
assertThat(ratings, hasItem(equalTo(createRating(4, 1, 4, "2007-04-15 12:14:00.0"))));
ratings = actionDAO.getRatings(1, itemTypeIds, 2);
assertThat(ratings.size(), is(1));
assertThat(ratings, hasItem(equalTo(createRating(7, 2, 7, "2007-04-15 12:17:00.0"))));
}
示例12: 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));
}
示例13: testSerialize
import gnu.trove.set.TIntSet; //導入依賴的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 );
}
示例14: testToArrayMatchesIteratorOrder
import gnu.trove.set.TIntSet; //導入依賴的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 ) );
}
示例15: testToArrayWithParams
import gnu.trove.set.TIntSet; //導入依賴的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 );
}