aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIstvan David2013-10-01 05:13:44 (EDT)
committerAbel Hegedus2013-10-01 05:19:06 (EDT)
commitc667ee33b48a7132f580a87882fc34a15249af15 (patch)
treea07cf05fbc2ec78d4705b4980aca6449d6dd5ac9
parentf3f25ff20891d673c58a7122bcebf90373ef9287 (diff)
downloadorg.eclipse.incquery-c667ee33b48a7132f580a87882fc34a15249af15.zip
org.eclipse.incquery-c667ee33b48a7132f580a87882fc34a15249af15.tar.gz
org.eclipse.incquery-c667ee33b48a7132f580a87882fc34a15249af15.tar.bz2
[418274] LIFO conflict resolver initial contribution
Signed-off-by: Istvan David <istvan_david@mentor.com>
-rw-r--r--plugins/org.eclipse.incquery.runtime.evm/src/org/eclipse/incquery/runtime/evm/specific/resolver/LifoConflictResolver.java93
1 files changed, 93 insertions, 0 deletions
diff --git a/plugins/org.eclipse.incquery.runtime.evm/src/org/eclipse/incquery/runtime/evm/specific/resolver/LifoConflictResolver.java b/plugins/org.eclipse.incquery.runtime.evm/src/org/eclipse/incquery/runtime/evm/specific/resolver/LifoConflictResolver.java
new file mode 100644
index 0000000..f17ffa6
--- /dev/null
+++ b/plugins/org.eclipse.incquery.runtime.evm/src/org/eclipse/incquery/runtime/evm/specific/resolver/LifoConflictResolver.java
@@ -0,0 +1,93 @@
+/*******************************************************************************
+ * Copyright (c) 2010-2013, Istvan David, Abel Hegedus and Daniel Varro
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Istvan David - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.incquery.runtime.evm.specific.resolver;
+
+import static com.google.common.base.Preconditions.checkArgument;
+
+import java.util.ArrayDeque;
+import java.util.Collections;
+import java.util.Deque;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.incquery.runtime.evm.api.Activation;
+import org.eclipse.incquery.runtime.evm.api.resolver.ChangeableConflictSet;
+import org.eclipse.incquery.runtime.evm.api.resolver.ConflictResolver;
+
+import com.google.common.collect.Sets;
+
+/**
+ *
+ * @author Istvan David
+ *
+ */
+public class LifoConflictResolver implements ConflictResolver {
+ @Override
+ public LifoConflictSet createConflictSet() {
+ return new LifoConflictSet(this);
+ }
+
+ public static final class LifoConflictSet implements ChangeableConflictSet {
+
+ private LifoConflictResolver resolver;
+ private Deque<Activation<?>> activations = new ArrayDeque<Activation<?>>();
+
+ public LifoConflictSet(LifoConflictResolver resolver) {
+ this.resolver = resolver;
+ }
+
+ @Override
+ public ConflictResolver getConflictResolver() {
+ return resolver;
+ }
+
+ @Override
+ public Activation<?> getNextActivation() {
+ return activations.peek();
+ }
+
+ @Override
+ public Set<Activation<?>> getNextActivations() {
+ if (activations.isEmpty()) {
+ return Collections.emptySet();
+ }
+ HashSet<Activation<?>> activationSet = new HashSet<Activation<?>>();
+ activationSet.add(getNextActivation());
+ return activationSet;
+ }
+
+ @Override
+ public Set<Activation<?>> getConflictingActivations() {
+ return Collections.unmodifiableSet(Sets.newLinkedHashSet(activations));
+ }
+
+ @Override
+ public boolean addActivation(Activation<?> activation) {
+ checkArgument(activation != null, "Activation cannot be null!");
+ if (activation.equals(activations.peek())) {
+ return false; // no change required
+ } else {
+ // activation may already be in the queue, but never more than
+ // once (see JavaDoc of method)
+ activations.remove(activation);
+ activations.push(activation);
+ return true; // if the first activation changes, we consider it
+ // a change in the set
+ }
+ }
+
+ @Override
+ public boolean removeActivation(Activation<?> activation) {
+ checkArgument(activation != null, "Activation cannot be null!");
+ return activations.remove(activation);
+ }
+ }
+} \ No newline at end of file