use of java.util.RandomAccess in project j2objc by google.
the class AbstractListTest method test_subListII.
/**
* @tests java.util.AbstractList#subList(int, int)
*/
public void test_subListII() {
// Test each of the SubList operations to ensure a
// ConcurrentModificationException does not occur on an AbstractList
// which does not update modCount
SimpleList mList = new SimpleList();
mList.add(new Object());
mList.add(new Object());
List sList = mList.subList(0, 2);
// calls add(int, Object)
sList.add(new Object());
sList.get(0);
sList.add(0, new Object());
sList.get(0);
sList.addAll(Arrays.asList(new String[] { "1", "2" }));
sList.get(0);
sList.addAll(0, Arrays.asList(new String[] { "3", "4" }));
sList.get(0);
sList.remove(0);
sList.get(0);
ListIterator lit = sList.listIterator();
lit.add(new Object());
lit.next();
lit.remove();
lit.next();
// calls removeRange()
sList.clear();
sList.add(new Object());
// test the type of sublist that is returned
List al = new ArrayList();
for (int i = 0; i < 10; i++) {
al.add(new Integer(i));
}
assertTrue("Sublist returned should have implemented Random Access interface", al.subList(3, 7) instanceof RandomAccess);
List ll = new LinkedList();
for (int i = 0; i < 10; i++) {
ll.add(new Integer(i));
}
assertTrue("Sublist returned should not have implemented Random Access interface", !(ll.subList(3, 7) instanceof RandomAccess));
}
use of java.util.RandomAccess in project robovm by robovm.
the class CollectionsTest method testSynchronizedList.
private void testSynchronizedList(List smallList, String type) {
for (int i = 0; i < 50; i++) {
smallList.add(objArray[i]);
}
final int numberOfLoops = 200;
List synchList = Collections.synchronizedList(smallList);
if (type.equals("Random Access"))
assertTrue("Returned synchronized list should implement the Random Access interface", synchList instanceof RandomAccess);
else
assertTrue("Returned synchronized list should not implement the Random Access interface", !(synchList instanceof RandomAccess));
// Replacing the previous line with the line below *should* cause the
// test to fail--the list below isn't synchronized
// List synchList = smallList;
SynchCollectionChecker normalSynchChecker = new SynchCollectionChecker(synchList, false, numberOfLoops);
SynchCollectionChecker offsetSynchChecker = new SynchCollectionChecker(synchList, true, numberOfLoops);
Thread normalThread = new Thread(normalSynchChecker);
Thread offsetThread = new Thread(offsetSynchChecker);
normalThread.start();
offsetThread.start();
while ((normalSynchChecker.getNumberOfChecks() < numberOfLoops) || (offsetSynchChecker.getNumberOfChecks() < numberOfLoops)) {
try {
Thread.sleep(10);
} catch (InterruptedException e) {
}
}
assertTrue(type + " list tests: Returned list corrupted by multiple thread access", normalSynchChecker.getResult() && offsetSynchChecker.getResult());
try {
normalThread.join(5000);
offsetThread.join(5000);
} catch (InterruptedException e) {
fail(type + " list tests: join() interrupted");
}
synchList.set(25, null);
assertNull(type + " list tests: Trying to use nulls in list failed", synchList.get(25));
}
use of java.util.RandomAccess in project robovm by robovm.
the class CollectionsTest method test_unmodifiableListLjava_util_List.
/**
* java.util.Collections#unmodifiableList(java.util.List)
*/
public void test_unmodifiableListLjava_util_List() {
// Test for method java.util.List
// java.util.Collections.unmodifiableList(java.util.List)
// test with a Sequential Access List
boolean exception = false;
List c = Collections.unmodifiableList(ll);
// Ensure a NPE is thrown if the list is NULL
try {
Collections.unmodifiableList(null);
fail("Expected NullPointerException for null list parameter");
} catch (NullPointerException e) {
}
assertTrue("Returned list is of incorrect size", c.size() == ll.size());
assertTrue("Returned List should not implement Random Access interface", !(c instanceof RandomAccess));
Iterator i = ll.iterator();
while (i.hasNext()) assertTrue("Returned list missing elements", c.contains(i.next()));
try {
c.add(new Object());
} catch (UnsupportedOperationException e) {
exception = true;
// Correct
}
if (!exception) {
fail("Allowed modification of list");
}
try {
c.remove(new Object());
fail("Allowed modification of list");
} catch (UnsupportedOperationException e) {
// Correct
}
// test with a Random Access List
List smallList = new ArrayList();
smallList.add(null);
smallList.add("yoink");
c = Collections.unmodifiableList(smallList);
assertNull("First element should be null", c.get(0));
assertTrue("List should contain null", c.contains(null));
assertTrue("T1. Returned List should implement Random Access interface", c instanceof RandomAccess);
smallList = new ArrayList();
for (int counter = 0; counter < 100; counter++) {
smallList.add(objArray[counter]);
}
List myList = Collections.unmodifiableList(smallList);
assertTrue("List should not contain null", !myList.contains(null));
assertTrue("T2. Returned List should implement Random Access interface", myList instanceof RandomAccess);
assertTrue("get failed on unmodifiable list", myList.get(50).equals(new Integer(50)));
ListIterator listIterator = myList.listIterator();
for (int counter = 0; listIterator.hasNext(); counter++) {
assertTrue("List has wrong elements", ((Integer) listIterator.next()).intValue() == counter);
}
new Support_UnmodifiableCollectionTest("", smallList).runTest();
}
use of java.util.RandomAccess in project processdash by dtuma.
the class Filter method matchesFilter.
public static boolean matchesFilter(Collection theFilter, String name) {
if (theFilter == null)
return true;
if (theFilter instanceof List) {
List theFilterList = (List) theFilter;
int size = theFilter.size();
if (size == 1)
// common case)
return pathMatches(name, (String) theFilterList.get(0));
else if (theFilter instanceof RandomAccess) {
// iterator instance below)
for (int i = size; i-- > 0; ) if (pathMatches(name, (String) theFilterList.get(i)))
return true;
return false;
}
}
for (Iterator iter = theFilter.iterator(); iter.hasNext(); ) {
String oneFilter = (String) iter.next();
if (pathMatches(name, oneFilter))
return true;
}
return false;
}
Aggregations