Search in sources :

Example 31 with AbstractList

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));
}
Also used : ArrayList(java.util.ArrayList) RandomAccess(java.util.RandomAccess) List(java.util.List) AbstractList(java.util.AbstractList) LinkedList(java.util.LinkedList) ArrayList(java.util.ArrayList) ListIterator(java.util.ListIterator) LinkedList(java.util.LinkedList)

Example 32 with AbstractList

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
    }
}
Also used : AbstractList(java.util.AbstractList) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ListIterator(java.util.ListIterator)

Example 33 with AbstractList

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));
}
Also used : AbstractList(java.util.AbstractList) ArrayList(java.util.ArrayList) Random(java.util.Random) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) AbstractMap(java.util.AbstractMap) Map(java.util.Map)

Example 34 with AbstractList

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;
        }
    };
}
Also used : AbstractList(java.util.AbstractList) SchemaReader(mondrian.olap.SchemaReader) AbstractListCalc(mondrian.calc.impl.AbstractListCalc) Calc(mondrian.calc.Calc) IntegerCalc(mondrian.calc.IntegerCalc) AbstractListCalc(mondrian.calc.impl.AbstractListCalc) ListCalc(mondrian.calc.ListCalc) Evaluator(mondrian.olap.Evaluator) NativeEvaluator(mondrian.olap.NativeEvaluator) DelegatingTupleList(mondrian.calc.impl.DelegatingTupleList) UnaryTupleList(mondrian.calc.impl.UnaryTupleList) TupleList(mondrian.calc.TupleList) Hierarchy(mondrian.olap.Hierarchy) UnaryTupleList(mondrian.calc.impl.UnaryTupleList) IntegerCalc(mondrian.calc.IntegerCalc) AbstractListCalc(mondrian.calc.impl.AbstractListCalc) ListCalc(mondrian.calc.ListCalc) DelegatingTupleList(mondrian.calc.impl.DelegatingTupleList) AbstractList(java.util.AbstractList) UnaryTupleList(mondrian.calc.impl.UnaryTupleList) TupleList(mondrian.calc.TupleList) List(java.util.List) Member(mondrian.olap.Member) NativeEvaluator(mondrian.olap.NativeEvaluator) DelegatingTupleList(mondrian.calc.impl.DelegatingTupleList)

Example 35 with AbstractList

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();
                }
            };
        }
    };
}
Also used : AbstractList(java.util.AbstractList) CoordinateIterator(org.olap4j.impl.CoordinateIterator) CellSetAxis(org.olap4j.CellSetAxis) CoordinateIterator(org.olap4j.impl.CoordinateIterator) Iterator(java.util.Iterator) Cell(mondrian.olap.Cell)

Aggregations

AbstractList (java.util.AbstractList)76 ArrayList (java.util.ArrayList)30 List (java.util.List)17 HashMap (java.util.HashMap)10 NodeRef (org.alfresco.service.cmr.repository.NodeRef)10 QName (org.alfresco.service.namespace.QName)9 UserInfo (org.alfresco.rest.api.model.UserInfo)8 FileInfo (org.alfresco.service.cmr.model.FileInfo)8 WebApiDescription (org.alfresco.rest.framework.WebApiDescription)7 RexNode (org.apache.calcite.rex.RexNode)7 Collection (java.util.Collection)6 ConcurrentModificationException (java.util.ConcurrentModificationException)6 Iterator (java.util.Iterator)6 Paging (org.alfresco.rest.framework.resource.parameters.Paging)6 IOException (java.io.IOException)5 Set (java.util.Set)5 FilterProp (org.alfresco.repo.node.getchildren.FilterProp)5 Test (org.junit.Test)5 ListIterator (java.util.ListIterator)4 RandomAccess (java.util.RandomAccess)4