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);
}
}
}
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);
}
}
}
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));
}
}
}
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 + ")");
}
}
}
}
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();
}
Aggregations