本文整理汇总了Java中gnu.trove.list.TIntList.add方法的典型用法代码示例。如果您正苦于以下问题:Java TIntList.add方法的具体用法?Java TIntList.add怎么用?Java TIntList.add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gnu.trove.list.TIntList
的用法示例。
在下文中一共展示了TIntList.add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testInsertArrayAtEnd
import gnu.trove.list.TIntList; //导入方法依赖的package包/类
public void testInsertArrayAtEnd() {
int element_count = 10;
int[] ints = {1138, 42, 86, 99, 101};
TIntList a = new TIntArrayList();
assertTrue( a.isEmpty() );
for ( int i = 1; i <= element_count; i++ ) {
a.add( i );
}
a.insert( a.size(), ints );
for ( int i = 0; i < element_count; i++ ) {
assertEquals( i + 1, a.get( i ) );
}
for ( int i = element_count, j = 0;
i < ints.length + element_count;
i++, j++ ) {
assertEquals( ints[j], a.get( i ) );
}
}
示例2: testTransform
import gnu.trove.list.TIntList; //导入方法依赖的package包/类
public void testTransform() {
int element_count = 20;
TIntList a = new TIntLinkedList();
for ( int i = 1; i < element_count; i++ ) {
a.add( i );
}
a.transformValues( new TIntFunction() {
public int execute( int value ) {
return value * value;
}
} );
for ( int i = 0; i < a.size(); i++ ) {
int result = a.get( i );
int expected = ( i + 1 ) * ( i + 1 );
assertEquals( expected, result );
}
}
示例3: testIteratorAbuseRemove
import gnu.trove.list.TIntList; //导入方法依赖的package包/类
public void testIteratorAbuseRemove() {
int element_count = 20;
TIntList list = new TIntArrayList();
for ( int i = 0; i < element_count; i++ ) {
list.add( i );
}
TIntIterator iter = list.iterator();
while ( iter.hasNext() ) {
iter.next();
}
assertFalse( iter.hasNext() );
list.remove( 5, 10 );
assertFalse( iter.hasNext() );
try {
iter.remove();
fail( "Expected ConcurrentModificationException" );
} catch( ConcurrentModificationException ex ) {
// Expected.
}
}
示例4: testIntUnmodifiableEquality
import gnu.trove.list.TIntList; //导入方法依赖的package包/类
public void testIntUnmodifiableEquality() {
TIntList list1 = new TIntArrayList();
TIntList list2 = new TIntArrayList();
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 ),
TCollections.unmodifiableList( list2 ) );
}
示例5: testGrep
import gnu.trove.list.TIntList; //导入方法依赖的package包/类
public void testGrep() {
int element_count = 20;
TIntList a = new TIntArrayList();
for ( int i = 1; i < element_count; i++ ) {
a.add( i );
}
TIntList grepped = a.grep( new TIntProcedure() {
@Override
public boolean execute( int value ) {
return value > 10;
}
} );
for ( int i = 0; i < grepped.size(); i++ ) {
int expected = i + 11;
assertEquals( expected, grepped.get( i ) );
}
}
示例6: testIntListDecoratorSubList
import gnu.trove.list.TIntList; //导入方法依赖的package包/类
public void testIntListDecoratorSubList() {
TIntList list = new TIntArrayList();
list.add( 2 );
list.add( 3 );
list.add( 4 );
list.add( 5 );
list.add( 6 );
List<Integer> wrapped_list = TDecorators.wrap( list );
List<Integer> sublist = wrapped_list.subList( 1, 4 );
assertEquals( 3, sublist.size() );
assertEquals( Integer.valueOf( 3 ), sublist.get( 0 ) );
assertEquals( Integer.valueOf( 4 ), sublist.get( 1 ) );
assertEquals( Integer.valueOf( 5 ), sublist.get( 2 ) );
sublist.clear();
assertEquals( 2, list.size() );
assertEquals( 2, list.get( 0 ) );
assertEquals( 6, list.get( 1 ) );
}
示例7: testTransform
import gnu.trove.list.TIntList; //导入方法依赖的package包/类
public void testTransform() {
int element_count = 20;
TIntList a = new TIntLinkedList();
for ( int i = 1; i < element_count; i++ ) {
a.add( i );
}
a.transformValues( new TIntFunction() {
@Override
public int execute( int value ) {
return value * value;
}
} );
for ( int i = 0; i < a.size(); i++ ) {
int result = a.get( i );
int expected = ( i + 1 ) * ( i + 1 );
assertEquals( expected, result );
}
}
示例8: testInsertArray
import gnu.trove.list.TIntList; //导入方法依赖的package包/类
public void testInsertArray() {
int element_count = 10;
int[] ints = {1138, 42, 86, 99, 101};
TIntList a = new TIntArrayList();
assertTrue( a.isEmpty() );
for ( int i = 1; i <= element_count; i++ ) {
a.add( i );
}
a.insert( 0, ints );
assertEquals( ints.length + element_count, a.size() );
for ( int i = 0; i < ints.length; i++ ) {
assertEquals( ints[i], a.get( i ) );
}
for ( int i = ints.length, j = 1;
i < ints.length + element_count;
i++, j++ ) {
assertEquals( j, a.get( i ) );
}
}
示例9: testInsertArrayAtEnd
import gnu.trove.list.TIntList; //导入方法依赖的package包/类
public void testInsertArrayAtEnd() {
int element_count = 10;
int[] ints = {1138, 42, 86, 99, 101};
TIntList a = new TIntLinkedList();
assertTrue( a.isEmpty() );
for ( int i = 1; i <= element_count; i++ ) {
a.add( i );
}
a.insert(a.size(), ints);
for ( int i = 0; i < element_count; i++ ) {
assertEquals( i + 1, a.get( i ) );
}
for ( int i = element_count, j = 0;
i < ints.length + element_count;
i++, j++ ) {
assertEquals( ints[j], a.get( i ) );
}
}
示例10: indexPath
import gnu.trove.list.TIntList; //导入方法依赖的package包/类
private static TIntList indexPath(Element child, int size) {
final Element parent = child.getParentElement();
if(parent == null) {
return new TIntArrayList(size);
} else {
final TIntList path = indexPath(parent, size + 1);
final int index = ((BoundedElement) child).indexInParent();
if(index < 0) {
throw new IllegalStateException("Parent element " + parent + " does not contain its child element " + child);
}
path.add(index);
return path;
}
}
示例11: grep
import gnu.trove.list.TIntList; //导入方法依赖的package包/类
/** {@inheritDoc} */
public TIntList grep(TIntProcedure condition) {
TIntList ret = new TIntLinkedList();
for (TIntLink l = head; got(l); l = l.getNext()) {
if (condition.execute(l.getValue()))
ret.add(l.getValue());
}
return ret;
}
示例12: inverseGrep
import gnu.trove.list.TIntList; //导入方法依赖的package包/类
/** {@inheritDoc} */
public TIntList inverseGrep(TIntProcedure condition) {
TIntList ret = new TIntLinkedList();
for (TIntLink l = head; got(l); l = l.getNext()) {
if (!condition.execute(l.getValue()))
ret.add(l.getValue());
}
return ret;
}
示例13: addClause
import gnu.trove.list.TIntList; //导入方法依赖的package包/类
/**
* Ensures that the clause defined by POSLITS and NEGLITS is satisfied.
*
* @param POSVARS positive variables
* @param NEGVARS negative variables
* @return true if the clause has been added to the clause store
*/
default boolean addClause(int[] POSVARS, int[] NEGVARS) {
TIntList lits = new TIntArrayList(POSVARS.length + NEGVARS.length);
for(int p : POSVARS){
lits.add(makeLiteral(p, true));
}
for(int n : NEGVARS){
lits.add(makeLiteral(n, false));
}
return _me().addClause(lits);
}
示例14: testFill
import gnu.trove.list.TIntList; //导入方法依赖的package包/类
public void testFill() {
int element_count = 20;
TIntList a = new TIntLinkedList();
for ( int i = 1; i <= element_count; i++ ) {
a.add( i );
}
a.fill( 0xdeadbeef );
for ( int i = 0; i < element_count; i++ ) {
assertEquals( 0xdeadbeef, a.get( i ) );
}
}
示例15: testRetainAllTCollection
import gnu.trove.list.TIntList; //导入方法依赖的package包/类
public void testRetainAllTCollection() {
int element_count = 20;
TIntList other = new TIntLinkedList();
for ( int i = 0; i < element_count; i++ ) {
other.add( i );
}
TIntList list = new TIntLinkedList( 20 );
for ( int i = 0; i < element_count; i++ ) {
list.add( i );
}
assertEquals( element_count, list.size() );
assertEquals( element_count, other.size() );
assertFalse( list.retainAll( list ) );
assertFalse( list.retainAll( other ) );
assertEquals( element_count, list.size() );
for ( int i = 0; i < list.size(); i++ ) {
assertEquals( i , list.get( i ) );
}
other.remove( 0 );
other.remove( 5 );
other.remove( 10 );
other.remove( 15 );
assertTrue( list.retainAll( other ) );
int expected = element_count - 4;
assertEquals( expected, list.size() );
for ( int i = 0; i < list.size(); i++ ) {
expected = ( int ) Math.floor( i / 4 ) + i + 1;
assertEquals( "expected: " + expected + ", was: " + list.get( i ) + ", list: " + list,
expected , list.get( i ) );
}
}