use of java.util.AbstractList in project j2objc by google.
the class AbstractListTest method test_subListII.
/**
* 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.AbstractList in project j2objc by google.
the class AbstractListTest method test_listIteratorI.
public void test_listIteratorI() {
AbstractList al1 = new ArrayList();
AbstractList al2 = new ArrayList();
al1.add(0);
al1.add(1);
al1.add(2);
al1.add(3);
al1.add(4);
al2.add(2);
al2.add(3);
al2.add(4);
Iterator li1 = al1.listIterator(2);
Iterator li2 = al2.listIterator();
while (li1.hasNext() && li2.hasNext()) {
assertEquals(li1.next(), li2.next());
}
assertSame(li1.hasNext(), li2.hasNext());
try {
al1.listIterator(-1);
fail("IndexOutOfBoundsException expected");
} catch (IndexOutOfBoundsException ee) {
// expected
}
try {
al1.listIterator(al1.size() + 1);
fail("IndexOutOfBoundsException expected");
} catch (IndexOutOfBoundsException ee) {
// expected
}
}
use of java.util.AbstractList in project j2objc by google.
the class MapDefaultMethodTester method test_entrySet_spliterator_unordered.
public static void test_entrySet_spliterator_unordered(Map<String, String> m) {
checkEntrySpliterator(m);
m.put("key", "value");
checkEntrySpliterator(m, "key", "value");
m.put("key2", "value2");
checkEntrySpliterator(m, "key", "value", "key2", "value2");
m.put("key", "newValue");
checkEntrySpliterator(m, "key", "newValue", "key2", "value2");
m.remove("key2");
checkEntrySpliterator(m, "key", "newValue");
m.clear();
// Check 100 entries in random order
// arbitrary
Random random = new Random(1000);
final List<Integer> order = new ArrayList<>(new AbstractList<Integer>() {
@Override
public Integer get(int index) {
return index;
}
@Override
public int size() {
return 100;
}
});
List<Map.Entry<String, String>> entries = new AbstractList<Map.Entry<String, String>>() {
@Override
public Map.Entry<String, String> get(int index) {
int i = order.get(index);
return new AbstractMap.SimpleEntry<>("key" + i, "value" + i);
}
@Override
public int size() {
return order.size();
}
};
// Pick a random put() order of the entries
Collections.shuffle(order, random);
for (Map.Entry<String, String> entry : entries) {
m.put(entry.getKey(), entry.getValue());
}
// Pick a different random order for the assertion
Collections.shuffle(order, random);
checkEntrySpliterator(m, new ArrayList<>(entries));
}
use of java.util.AbstractList in project mondrian by pentaho.
the class TopBottomCountFunDef method compileCall.
public Calc compileCall(final ResolvedFunCall call, ExpCompiler compiler) {
// Compile the member list expression. Ask for a mutable list, because
// we're going to sort it later.
final ListCalc listCalc = compiler.compileList(call.getArg(0), true);
final IntegerCalc integerCalc = compiler.compileInteger(call.getArg(1));
final Calc orderCalc = call.getArgCount() > 2 ? compiler.compileScalar(call.getArg(2), true) : null;
final int arity = call.getType().getArity();
return new AbstractListCalc(call, new Calc[] { listCalc, integerCalc, orderCalc }) {
public TupleList evaluateList(Evaluator evaluator) {
// Use a native evaluator, if more efficient.
// TODO: Figure this out at compile time.
SchemaReader schemaReader = evaluator.getSchemaReader();
NativeEvaluator nativeEvaluator = schemaReader.getNativeSetEvaluator(call.getFunDef(), call.getArgs(), evaluator, this);
if (nativeEvaluator != null) {
return (TupleList) nativeEvaluator.execute(ResultStyle.LIST);
}
int n = integerCalc.evaluateInteger(evaluator);
if (n == 0 || n == mondrian.olap.fun.FunUtil.IntegerNull) {
return TupleCollections.emptyList(arity);
}
TupleList list = listCalc.evaluateList(evaluator);
assert list.getArity() == arity;
if (list.isEmpty()) {
return list;
}
if (orderCalc == null) {
// REVIEW: Why require "instanceof AbstractList"?
if (list instanceof AbstractList && list.size() <= n) {
return list;
} else if (top) {
return list.subList(0, n);
} else {
return list.subList(list.size() - n, list.size());
}
}
return partiallySortList(evaluator, list, hasHighCardDimension(list), Math.min(n, list.size()));
}
private TupleList partiallySortList(Evaluator evaluator, TupleList list, boolean highCard, int n) {
assert list.size() > 0;
assert n <= list.size();
if (highCard) {
// sort list in chunks, collect the results
// what is this really?
final int chunkSize = 6400;
TupleList allChunkResults = TupleCollections.createList(arity);
for (int i = 0, next; i < list.size(); i = next) {
next = Math.min(i + chunkSize, list.size());
final TupleList chunk = list.subList(i, next);
TupleList chunkResult = partiallySortList(evaluator, chunk, false, n);
allChunkResults.addAll(chunkResult);
}
// one last sort, to merge and cull
return partiallySortList(evaluator, allChunkResults, false, n);
}
// normal case: no need for chunks
final int savepoint = evaluator.savepoint();
try {
switch(list.getArity()) {
case 1:
final List<Member> members = Sorter.partiallySortMembers(evaluator.push(), list.slice(0), orderCalc, n, top);
return new UnaryTupleList(members);
default:
final List<List<Member>> tuples = partiallySortTuples(evaluator.push(), list, orderCalc, n, top);
return new DelegatingTupleList(list.getArity(), tuples);
}
} finally {
evaluator.restore(savepoint);
}
}
public boolean dependsOn(Hierarchy hierarchy) {
return anyDependsButFirst(getCalcs(), hierarchy);
}
private boolean hasHighCardDimension(TupleList l) {
final List<Member> trial = l.get(0);
for (Member m : trial) {
if (m.getHierarchy().getDimension().isHighCardinality()) {
return true;
}
}
return false;
}
};
}
use of java.util.AbstractList in project mondrian by pentaho.
the class TestContext method cellIter.
/**
* Returns an iterator over cells in an olap4j cell set.
*/
static Iterable<org.olap4j.Cell> cellIter(final CellSet cellSet) {
return new Iterable<org.olap4j.Cell>() {
public Iterator<org.olap4j.Cell> iterator() {
int[] axisDimensions = new int[cellSet.getAxes().size()];
int k = 0;
for (CellSetAxis axis : cellSet.getAxes()) {
axisDimensions[k++] = axis.getPositions().size();
}
final CoordinateIterator coordIter = new CoordinateIterator(axisDimensions);
return new Iterator<org.olap4j.Cell>() {
public boolean hasNext() {
return coordIter.hasNext();
}
public org.olap4j.Cell next() {
final int[] ints = coordIter.next();
final List<Integer> list = new AbstractList<Integer>() {
public Integer get(int index) {
return ints[index];
}
public int size() {
return ints.length;
}
};
return cellSet.getCell(list);
}
public void remove() {
throw new UnsupportedOperationException();
}
};
}
};
}
Aggregations