Search in sources :

Example 6 with RandomAccess

use of java.util.RandomAccess in project gradle by gradle.

the class DefaultTaskDependency method visitDependencies.

@Override
public void visitDependencies(TaskDependencyResolveContext context) {
    if (values.isEmpty()) {
        return;
    }
    Deque<Object> queue = new ArrayDeque<Object>(values);
    while (!queue.isEmpty()) {
        Object dependency = queue.removeFirst();
        if (dependency instanceof Buildable) {
            context.add(dependency);
        } else if (dependency instanceof Task) {
            context.add(dependency);
        } else if (dependency instanceof TaskDependency) {
            context.add(dependency);
        } else if (dependency instanceof Closure) {
            Closure closure = (Closure) dependency;
            Object closureResult = closure.call(context.getTask());
            if (closureResult != null) {
                queue.addFirst(closureResult);
            }
        } else if (dependency instanceof RealizableTaskCollection) {
            RealizableTaskCollection realizableTaskCollection = (RealizableTaskCollection) dependency;
            realizableTaskCollection.realizeRuleTaskTypes();
            addAllFirst(queue, realizableTaskCollection.toArray());
        } else if (dependency instanceof List) {
            List<?> list = (List) dependency;
            if (list instanceof RandomAccess) {
                for (int i = list.size() - 1; i >= 0; i--) {
                    queue.addFirst(list.get(i));
                }
            } else {
                ListIterator<?> iterator = list.listIterator(list.size());
                while (iterator.hasPrevious()) {
                    Object item = iterator.previous();
                    queue.addFirst(item);
                }
            }
        } else if (dependency instanceof Iterable) {
            Iterable<?> iterable = (Iterable) dependency;
            addAllFirst(queue, toArray(iterable, Object.class));
        } else if (dependency instanceof Map) {
            Map<?, ?> map = (Map) dependency;
            addAllFirst(queue, map.values().toArray());
        } else if (dependency instanceof Object[]) {
            Object[] array = (Object[]) dependency;
            addAllFirst(queue, array);
        } else if (dependency instanceof Callable) {
            Callable callable = (Callable) dependency;
            Object callableResult = uncheckedCall(callable);
            if (callableResult != null) {
                queue.addFirst(callableResult);
            }
        } else if (resolver != null && dependency instanceof TaskReference) {
            context.add(resolver.resolveTask((TaskReference) dependency));
        } else if (resolver != null && dependency instanceof CharSequence) {
            context.add(resolver.resolveTask(dependency.toString()));
        } else {
            List<String> formats = new ArrayList<String>();
            if (resolver != null) {
                formats.add("A String or CharSequence task name or path");
                formats.add("A TaskReference instance");
            }
            formats.add("A Task instance");
            formats.add("A Buildable instance");
            formats.add("A TaskDependency instance");
            formats.add("A Closure instance that returns any of the above types");
            formats.add("A Callable instance that returns any of the above types");
            formats.add("An Iterable, Collection, Map or array instance that contains any of the above types");
            throw new UnsupportedNotationException(dependency, String.format("Cannot convert %s to a task.", dependency), null, formats);
        }
    }
}
Also used : TaskDependency(org.gradle.api.tasks.TaskDependency) Task(org.gradle.api.Task) Closure(groovy.lang.Closure) RandomAccess(java.util.RandomAccess) ListIterator(java.util.ListIterator) ArrayDeque(java.util.ArrayDeque) Callable(java.util.concurrent.Callable) TaskReference(org.gradle.api.tasks.TaskReference) UnsupportedNotationException(org.gradle.internal.typeconversion.UnsupportedNotationException) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) Buildable(org.gradle.api.Buildable)

Example 7 with RandomAccess

use of java.util.RandomAccess in project kotlin by JetBrains.

the class ResourceVisitor method visitElement.

private void visitElement(@NonNull XmlContext context, @NonNull Element element) {
    List<Detector.XmlScanner> elementChecks = mElementToCheck.get(element.getTagName());
    if (elementChecks != null) {
        assert elementChecks instanceof RandomAccess;
        for (XmlScanner check : elementChecks) {
            check.visitElement(context, element);
        }
    }
    if (!mAllElementDetectors.isEmpty()) {
        for (XmlScanner check : mAllElementDetectors) {
            check.visitElement(context, element);
        }
    }
    if (!mAttributeToCheck.isEmpty() || !mAllAttributeDetectors.isEmpty()) {
        NamedNodeMap attributes = element.getAttributes();
        for (int i = 0, n = attributes.getLength(); i < n; i++) {
            Attr attribute = (Attr) attributes.item(i);
            String name = attribute.getLocalName();
            if (name == null) {
                name = attribute.getName();
            }
            List<Detector.XmlScanner> list = mAttributeToCheck.get(name);
            if (list != null) {
                for (XmlScanner check : list) {
                    check.visitAttribute(context, attribute);
                }
            }
            if (!mAllAttributeDetectors.isEmpty()) {
                for (XmlScanner check : mAllAttributeDetectors) {
                    check.visitAttribute(context, attribute);
                }
            }
        }
    }
    // Visit children
    NodeList childNodes = element.getChildNodes();
    for (int i = 0, n = childNodes.getLength(); i < n; i++) {
        Node child = childNodes.item(i);
        if (child.getNodeType() == Node.ELEMENT_NODE) {
            visitElement(context, (Element) child);
        }
    }
    // Post hooks
    if (elementChecks != null) {
        for (XmlScanner check : elementChecks) {
            check.visitElementAfter(context, element);
        }
    }
    if (!mAllElementDetectors.isEmpty()) {
        for (XmlScanner check : mAllElementDetectors) {
            check.visitElementAfter(context, element);
        }
    }
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) XmlScanner(com.android.tools.klint.detector.api.Detector.XmlScanner) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) RandomAccess(java.util.RandomAccess) Attr(org.w3c.dom.Attr)

Example 8 with RandomAccess

use of java.util.RandomAccess in project hbase by apache.

the class HRegion method rewriteCellTags.

/**
   * Possibly rewrite incoming cell tags.
   */
void rewriteCellTags(Map<byte[], List<Cell>> familyMap, final Mutation m) {
    // Update these checks as more logic is added here
    if (m.getTTL() == Long.MAX_VALUE) {
        return;
    }
    // From this point we know we have some work to do
    for (Map.Entry<byte[], List<Cell>> e : familyMap.entrySet()) {
        List<Cell> cells = e.getValue();
        assert cells instanceof RandomAccess;
        int listSize = cells.size();
        for (int i = 0; i < listSize; i++) {
            Cell cell = cells.get(i);
            List<Tag> newTags = TagUtil.carryForwardTags(null, cell);
            newTags = TagUtil.carryForwardTTLTag(newTags, m.getTTL());
            // Rewrite the cell with the updated set of tags
            cells.set(i, CellUtil.createCell(cell, newTags));
        }
    }
}
Also used : RandomAccess(java.util.RandomAccess) ArrayList(java.util.ArrayList) AbstractList(java.util.AbstractList) List(java.util.List) Tag(org.apache.hadoop.hbase.Tag) Map(java.util.Map) TreeMap(java.util.TreeMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) NavigableMap(java.util.NavigableMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) Cell(org.apache.hadoop.hbase.Cell)

Example 9 with RandomAccess

use of java.util.RandomAccess in project hbase by apache.

the class HRegion method checkTimestamps.

@Override
public void checkTimestamps(final Map<byte[], List<Cell>> familyMap, long now) throws FailedSanityCheckException {
    if (timestampSlop == HConstants.LATEST_TIMESTAMP) {
        return;
    }
    long maxTs = now + timestampSlop;
    for (List<Cell> kvs : familyMap.values()) {
        assert kvs instanceof RandomAccess;
        int listSize = kvs.size();
        for (int i = 0; i < listSize; i++) {
            Cell cell = kvs.get(i);
            // see if the user-side TS is out of range. latest = server-side
            long ts = cell.getTimestamp();
            if (ts != HConstants.LATEST_TIMESTAMP && ts > maxTs) {
                throw new FailedSanityCheckException("Timestamp for KV out of range " + cell + " (too.new=" + timestampSlop + ")");
            }
        }
    }
}
Also used : RandomAccess(java.util.RandomAccess) Cell(org.apache.hadoop.hbase.Cell) FailedSanityCheckException(org.apache.hadoop.hbase.exceptions.FailedSanityCheckException)

Example 10 with RandomAccess

use of java.util.RandomAccess in project j2objc by google.

the class CollectionsTest method test_unmodifiableListLjava_util_List.

/**
	 * @tests 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();
}
Also used : Support_UnmodifiableCollectionTest(tests.support.Support_UnmodifiableCollectionTest) ListIterator(java.util.ListIterator) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) RandomAccess(java.util.RandomAccess) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) ListIterator(java.util.ListIterator)

Aggregations

RandomAccess (java.util.RandomAccess)14 List (java.util.List)9 ArrayList (java.util.ArrayList)8 LinkedList (java.util.LinkedList)5 ListIterator (java.util.ListIterator)5 Cell (org.apache.hadoop.hbase.Cell)5 AbstractList (java.util.AbstractList)4 Iterator (java.util.Iterator)3 Map (java.util.Map)3 HashMap (java.util.HashMap)2 NavigableMap (java.util.NavigableMap)2 TreeMap (java.util.TreeMap)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ConcurrentMap (java.util.concurrent.ConcurrentMap)2 ConcurrentSkipListMap (java.util.concurrent.ConcurrentSkipListMap)2 Support_UnmodifiableCollectionTest (tests.support.Support_UnmodifiableCollectionTest)2 XmlScanner (com.android.tools.klint.detector.api.Detector.XmlScanner)1 TestingLoader (dagger.internal.TestingLoader)1 Closure (groovy.lang.Closure)1 ArrayDeque (java.util.ArrayDeque)1