private TaskInfo getNextReadyAndMatching(Spec<TaskInfo> criteria) { for (TaskInfo taskInfo : executionPlan.values()) { if (taskInfo.isReady() && criteria.isSatisfiedBy(taskInfo)) { return taskInfo; } } return null; }
public static <T, C extends Collection<T>> C filter( Iterable<? extends T> source, C destination, Spec<? super T> filter) { for (T item : source) { if (filter.isSatisfiedBy(item)) { destination.add(item); } } return destination; }
public static <T> T findFirst(T[] source, Spec<? super T> filter) { for (T thing : source) { if (filter.isSatisfiedBy(thing)) { return thing; } } return null; }
public static <T> T findFirst(Iterable<? extends T> source, Spec<? super T> filter) { for (T item : source) { if (filter.isSatisfiedBy(item)) { return item; } } return null; }
public static <T> boolean every(Iterable<? extends T> things, Spec<? super T> predicate) { for (T thing : things) { if (!predicate.isSatisfiedBy(thing)) { return false; } } return true; }
private List<DaemonInfo> daemonInfosOfEntriesMatching(Spec<DaemonInfo> spec) { List<DaemonInfo> matches = new ArrayList<DaemonInfo>(); for (DaemonInfo daemonInfo : daemonInfos.values()) { if (spec.isSatisfiedBy(daemonInfo)) { matches.add(daemonInfo); } } return matches; }
@Override public List<FileTreeElement> filter(PatternSet patternSet) { ImmutableList.Builder<FileTreeElement> filtered = ImmutableList.builder(); final Spec<FileTreeElement> spec = patternSet.getAsSpec(); for (FileTreeElement element : entries) { if (spec.isSatisfiedBy(element)) { filtered.add(element); } } return filtered.build(); }
public static <E> boolean replace( List<E> list, Spec<? super E> filter, Transformer<? extends E, ? super E> transformer) { boolean replaced = false; int i = 0; for (E it : list) { if (filter.isSatisfiedBy(it)) { list.set(i, transformer.transform(it)); replaced = true; } ++i; } return replaced; }
public void determineExecutionPlan() { List<TaskInfo> nodeQueue = CollectionUtils.collect( new ArrayList<Task>(entryTasks), new Transformer<TaskInfo, Task>() { public TaskInfo transform(Task original) { return graph.getNode(original); } }); Set<TaskInfo> visitingNodes = new HashSet<TaskInfo>(); while (!nodeQueue.isEmpty()) { TaskInfo taskNode = nodeQueue.get(0); boolean filtered = !filter.isSatisfiedBy(taskNode.getTask()); if (filtered) { taskNode.setRequired(false); } if (!taskNode.getRequired() || executionPlan.containsKey(taskNode.getTask())) { nodeQueue.remove(0); continue; } if (visitingNodes.add(taskNode)) { // Have not seen this task before - add its dependencies to the head of the queue and leave // this // task in the queue ArrayList<TaskInfo> dependsOnTasks = new ArrayList<TaskInfo>(); addAllReversed(dependsOnTasks, taskNode.getHardSuccessors()); addAllReversed(dependsOnTasks, taskNode.getSoftSuccessors()); for (TaskInfo dependsOnTask : dependsOnTasks) { if (visitingNodes.contains(dependsOnTask)) { throw new CircularReferenceException( String.format( "Circular dependency between tasks. Cycle includes [%s, %s].", taskNode.getTask(), dependsOnTask.getTask())); } nodeQueue.add(0, dependsOnTask); } } else { // Have visited this task's dependencies - add it to the end of the plan nodeQueue.remove(0); visitingNodes.remove(taskNode); executionPlan.put(taskNode.getTask(), taskNode); } } }
public OutputEventRenderer addStandardOutputAndError() { boolean stdOutIsTerminal = terminalDetector.isSatisfiedBy(FileDescriptor.out); boolean stdErrIsTerminal = terminalDetector.isSatisfiedBy(FileDescriptor.err); if (stdOutIsTerminal) { PrintStream outStr = org.fusesource.jansi.AnsiConsole.out(); Console console = new AnsiConsole(outStr, outStr, colourMap); addConsole(console, true, stdErrIsTerminal); } else if (stdErrIsTerminal) { // Only stderr is connected to a terminal PrintStream errStr = org.fusesource.jansi.AnsiConsole.err(); Console console = new AnsiConsole(errStr, errStr, colourMap); addConsole(console, false, true); } if (!stdOutIsTerminal) { addStandardOutput(System.out); } if (!stdErrIsTerminal) { addStandardError(System.err); } return this; }
private static List<Method> findAllMethodsInternal( Class<?> target, Spec<Method> predicate, MultiMap<String, Method> seen, List<Method> collector, boolean stopAtFirst) { for (final Method method : target.getDeclaredMethods()) { List<Method> seenWithName = seen.get(method.getName()); Method override = CollectionUtils.findFirst( seenWithName, new Spec<Method>() { public boolean isSatisfiedBy(Method potentionOverride) { return potentionOverride.getName().equals(method.getName()) && Arrays.equals( potentionOverride.getParameterTypes(), method.getParameterTypes()); } }); if (override == null) { seenWithName.add(method); if (predicate.isSatisfiedBy(method)) { collector.add(method); if (stopAtFirst) { return collector; } } } } Class<?> parent = target.getSuperclass(); if (parent != null) { return findAllMethodsInternal(parent, predicate, seen, collector, stopAtFirst); } return collector; }
@Override public boolean isSatisfiedBy(StackTraceElement element) { return truncationPointReached |= truncationPointDetector.isSatisfiedBy(element); }