Java Code Examples for com.google.common.collect.HashMultimap#containsEntry()

The following examples show how to use com.google.common.collect.HashMultimap#containsEntry() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultTaskExecutionPlan.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void removeShouldRunAfterSuccessorsIfTheyImposeACycle(HashMultimap<TaskInfo, Integer> visitingNodes, TaskInfoInVisitingSegment taskNodeWithVisitingSegment) {
    TaskInfo taskNode = taskNodeWithVisitingSegment.taskInfo;
    for (TaskInfo shouldRunAfterSuccessor : taskNode.getShouldSuccessors()) {
        if (visitingNodes.containsEntry(shouldRunAfterSuccessor, taskNodeWithVisitingSegment.visitingSegment)) {
            taskNode.removeShouldRunAfterSuccessor(shouldRunAfterSuccessor);
        }
    }
}
 
Example 2
Source File: DefaultTaskExecutionPlan.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void removeShouldRunAfterSuccessorsIfTheyImposeACycle(HashMultimap<TaskInfo, Integer> visitingNodes, TaskInfoInVisitingSegment taskNodeWithVisitingSegment) {
    TaskInfo taskNode = taskNodeWithVisitingSegment.taskInfo;
    for (TaskInfo shouldRunAfterSuccessor : taskNode.getShouldSuccessors()) {
        if (visitingNodes.containsEntry(shouldRunAfterSuccessor, taskNodeWithVisitingSegment.visitingSegment)) {
            taskNode.removeShouldRunAfterSuccessor(shouldRunAfterSuccessor);
        }
    }
}
 
Example 3
Source File: DefaultTaskExecutionPlan.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void determineExecutionPlan() {
    List<TaskInfoInVisitingSegment> nodeQueue = Lists.newArrayList(Iterables.transform(entryTasks, new Function<TaskInfo, TaskInfoInVisitingSegment>() {
        int index;

        public TaskInfoInVisitingSegment apply(TaskInfo taskInfo) {
            return new TaskInfoInVisitingSegment(taskInfo, index++);
        }
    }));
    int visitingSegmentCounter = nodeQueue.size();

    HashMultimap<TaskInfo, Integer> visitingNodes = HashMultimap.create();
    Stack<GraphEdge> walkedShouldRunAfterEdges = new Stack<GraphEdge>();
    Stack<TaskInfo> path = new Stack<TaskInfo>();
    HashMap<TaskInfo, Integer> planBeforeVisiting = new HashMap<TaskInfo, Integer>();

    while (!nodeQueue.isEmpty()) {
        TaskInfoInVisitingSegment taskInfoInVisitingSegment = nodeQueue.get(0);
        int currentSegment = taskInfoInVisitingSegment.visitingSegment;
        TaskInfo taskNode = taskInfoInVisitingSegment.taskInfo;

        if (taskNode.isIncludeInGraph() || executionPlan.containsKey(taskNode.getTask())) {
            nodeQueue.remove(0);
            maybeRemoveProcessedShouldRunAfterEdge(walkedShouldRunAfterEdges, taskNode);
            continue;
        }

        boolean alreadyVisited = visitingNodes.containsKey(taskNode);
        visitingNodes.put(taskNode, currentSegment);

        if (!alreadyVisited) {
            // Have not seen this task before - add its dependencies to the head of the queue and leave this
            // task in the queue
            recordEdgeIfArrivedViaShouldRunAfter(walkedShouldRunAfterEdges, path, taskNode);
            removeShouldRunAfterSuccessorsIfTheyImposeACycle(visitingNodes, taskInfoInVisitingSegment);
            takePlanSnapshotIfCanBeRestoredToCurrentTask(planBeforeVisiting, taskNode);
            ArrayList<TaskInfo> successors = new ArrayList<TaskInfo>();
            addAllSuccessorsInReverseOrder(taskNode, successors);
            for (TaskInfo successor : successors) {
                if (visitingNodes.containsEntry(successor, currentSegment)) {
                    if (!walkedShouldRunAfterEdges.empty()) {
                        //remove the last walked should run after edge and restore state from before walking it
                        GraphEdge toBeRemoved = walkedShouldRunAfterEdges.pop();
                        toBeRemoved.from.removeShouldRunAfterSuccessor(toBeRemoved.to);
                        restorePath(path, toBeRemoved);
                        restoreQueue(nodeQueue, visitingNodes, toBeRemoved);
                        restoreExecutionPlan(planBeforeVisiting, toBeRemoved);
                        break;
                    } else {
                        onOrderingCycle();
                    }
                }
                nodeQueue.add(0, new TaskInfoInVisitingSegment(successor, currentSegment));
            }
            path.push(taskNode);
        } else {
            // Have visited this task's dependencies - add it to the end of the plan
            nodeQueue.remove(0);
            visitingNodes.remove(taskNode, currentSegment);
            path.pop();
            executionPlan.put(taskNode.getTask(), taskNode);
            // Add any finalizers to the queue
            ArrayList<TaskInfo> finalizerTasks = new ArrayList<TaskInfo>();
            addAllReversed(finalizerTasks, taskNode.getFinalizers());
            for (TaskInfo finalizer : finalizerTasks) {
                if (!visitingNodes.containsKey(finalizer)) {
                    nodeQueue.add(finalizerTaskPosition(finalizer, nodeQueue), new TaskInfoInVisitingSegment(finalizer, visitingSegmentCounter++));
                }
            }
        }
    }
}
 
Example 4
Source File: DefaultTaskExecutionPlan.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void determineExecutionPlan() {
    List<TaskInfoInVisitingSegment> nodeQueue = Lists.newArrayList(Iterables.transform(entryTasks, new Function<TaskInfo, TaskInfoInVisitingSegment>() {
        int index;

        public TaskInfoInVisitingSegment apply(TaskInfo taskInfo) {
            return new TaskInfoInVisitingSegment(taskInfo, index++);
        }
    }));
    int visitingSegmentCounter = nodeQueue.size();

    HashMultimap<TaskInfo, Integer> visitingNodes = HashMultimap.create();
    Stack<GraphEdge> walkedShouldRunAfterEdges = new Stack<GraphEdge>();
    Stack<TaskInfo> path = new Stack<TaskInfo>();
    HashMap<TaskInfo, Integer> planBeforeVisiting = new HashMap<TaskInfo, Integer>();

    while (!nodeQueue.isEmpty()) {
        TaskInfoInVisitingSegment taskInfoInVisitingSegment = nodeQueue.get(0);
        int currentSegment = taskInfoInVisitingSegment.visitingSegment;
        TaskInfo taskNode = taskInfoInVisitingSegment.taskInfo;

        if (taskNode.isIncludeInGraph() || executionPlan.containsKey(taskNode.getTask())) {
            nodeQueue.remove(0);
            maybeRemoveProcessedShouldRunAfterEdge(walkedShouldRunAfterEdges, taskNode);
            continue;
        }

        boolean alreadyVisited = visitingNodes.containsKey(taskNode);
        visitingNodes.put(taskNode, currentSegment);

        if (!alreadyVisited) {
            // Have not seen this task before - add its dependencies to the head of the queue and leave this
            // task in the queue
            recordEdgeIfArrivedViaShouldRunAfter(walkedShouldRunAfterEdges, path, taskNode);
            removeShouldRunAfterSuccessorsIfTheyImposeACycle(visitingNodes, taskInfoInVisitingSegment);
            takePlanSnapshotIfCanBeRestoredToCurrentTask(planBeforeVisiting, taskNode);
            ArrayList<TaskInfo> successors = new ArrayList<TaskInfo>();
            addAllSuccessorsInReverseOrder(taskNode, successors);
            for (TaskInfo successor : successors) {
                if (visitingNodes.containsEntry(successor, currentSegment)) {
                    if (!walkedShouldRunAfterEdges.empty()) {
                        //remove the last walked should run after edge and restore state from before walking it
                        GraphEdge toBeRemoved = walkedShouldRunAfterEdges.pop();
                        toBeRemoved.from.removeShouldRunAfterSuccessor(toBeRemoved.to);
                        restorePath(path, toBeRemoved);
                        restoreQueue(nodeQueue, visitingNodes, toBeRemoved);
                        restoreExecutionPlan(planBeforeVisiting, toBeRemoved);
                        break;
                    } else {
                        onOrderingCycle();
                    }
                }
                nodeQueue.add(0, new TaskInfoInVisitingSegment(successor, currentSegment));
            }
            path.push(taskNode);
        } else {
            // Have visited this task's dependencies - add it to the end of the plan
            nodeQueue.remove(0);
            visitingNodes.remove(taskNode, currentSegment);
            path.pop();
            executionPlan.put(taskNode.getTask(), taskNode);
            // Add any finalizers to the queue
            ArrayList<TaskInfo> finalizerTasks = new ArrayList<TaskInfo>();
            addAllReversed(finalizerTasks, taskNode.getFinalizers());
            for (TaskInfo finalizer : finalizerTasks) {
                if (!visitingNodes.containsKey(finalizer)) {
                    nodeQueue.add(finalizerTaskPosition(finalizer, nodeQueue), new TaskInfoInVisitingSegment(finalizer, visitingSegmentCounter++));
                }
            }
        }
    }
}
 
Example 5
Source File: SimpleSearchProviderImplTest.java    From swellrt with Apache License 2.0 4 votes vote down vote up
private void addWaveletToUserView(WaveletName name, ParticipantId user) {
  HashMultimap<WaveId,WaveletId> wavesView = wavesViews.get(user);
  if (!wavesView.containsEntry(name.waveId, name.waveletId)) {
    wavesViews.get(user).put(name.waveId, name.waveletId);
  }
}
 
Example 6
Source File: SimpleSearchProviderImplTest.java    From incubator-retired-wave with Apache License 2.0 4 votes vote down vote up
private void addWaveletToUserView(WaveletName name, ParticipantId user) {
  HashMultimap<WaveId,WaveletId> wavesView = wavesViews.get(user);
  if (!wavesView.containsEntry(name.waveId, name.waveletId)) {
    wavesViews.get(user).put(name.waveId, name.waveletId);
  }
}