blob: db77525d904f66329de665bcfa6f2aaa54a578e9 [file] [log] [blame]
/**
*
* Copyright (c) 2010-2015, Andras Szabolcs Nagy, Abel Hegedus, Akos Horvath, Zoltan Ujhelyi 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:
* Andras Szabolcs Nagy - initial API and implementation
*
*/
package org.eclipse.viatra.dse.examples.bpmn.patterns;
import java.util.Arrays;
import java.util.List;
import org.eclipse.viatra.dse.examples.bpmn.patterns.util.UnassignedTaskQuerySpecification;
import org.eclipse.viatra.dse.examples.simplifiedbpmn.Task;
import org.eclipse.viatra.query.runtime.api.IPatternMatch;
import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch;
import org.eclipse.viatra.query.runtime.exception.ViatraQueryException;
/**
* Pattern-specific match representation of the org.eclipse.viatra.dse.examples.bpmn.patterns.unassignedTask pattern,
* to be used in conjunction with {@link UnassignedTaskMatcher}.
*
* <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned.
* Each instance is a (possibly partial) substitution of pattern parameters,
* usable to represent a match of the pattern in the result of a query,
* or to specify the bound (fixed) input parameters when issuing a query.
*
* @see UnassignedTaskMatcher
* @see UnassignedTaskProcessor
*
*/
@SuppressWarnings("all")
public abstract class UnassignedTaskMatch extends BasePatternMatch {
private Task fT;
private static List<String> parameterNames = makeImmutableList("T");
private UnassignedTaskMatch(final Task pT) {
this.fT = pT;
}
@Override
public Object get(final String parameterName) {
if ("T".equals(parameterName)) return this.fT;
return null;
}
public Task getT() {
return this.fT;
}
@Override
public boolean set(final String parameterName, final Object newValue) {
if (!isMutable()) throw new java.lang.UnsupportedOperationException();
if ("T".equals(parameterName) ) {
this.fT = (Task) newValue;
return true;
}
return false;
}
public void setT(final Task pT) {
if (!isMutable()) throw new java.lang.UnsupportedOperationException();
this.fT = pT;
}
@Override
public String patternName() {
return "org.eclipse.viatra.dse.examples.bpmn.patterns.unassignedTask";
}
@Override
public List<String> parameterNames() {
return UnassignedTaskMatch.parameterNames;
}
@Override
public Object[] toArray() {
return new Object[]{fT};
}
@Override
public UnassignedTaskMatch toImmutable() {
return isMutable() ? newMatch(fT) : this;
}
@Override
public String prettyPrint() {
StringBuilder result = new StringBuilder();
result.append("\"T\"=" + prettyPrintValue(fT)
);
return result.toString();
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((fT == null) ? 0 : fT.hashCode());
return result;
}
@Override
public boolean equals(final Object obj) {
if (this == obj)
return true;
if (!(obj instanceof UnassignedTaskMatch)) { // this should be infrequent
if (obj == null) {
return false;
}
if (!(obj instanceof IPatternMatch)) {
return false;
}
IPatternMatch otherSig = (IPatternMatch) obj;
if (!specification().equals(otherSig.specification()))
return false;
return Arrays.deepEquals(toArray(), otherSig.toArray());
}
UnassignedTaskMatch other = (UnassignedTaskMatch) obj;
if (fT == null) {if (other.fT != null) return false;}
else if (!fT.equals(other.fT)) return false;
return true;
}
@Override
public UnassignedTaskQuerySpecification specification() {
try {
return UnassignedTaskQuerySpecification.instance();
} catch (ViatraQueryException ex) {
// This cannot happen, as the match object can only be instantiated if the query specification exists
throw new IllegalStateException (ex);
}
}
/**
* Returns an empty, mutable match.
* Fields of the mutable match can be filled to create a partial match, usable as matcher input.
*
* @return the empty match.
*
*/
public static UnassignedTaskMatch newEmptyMatch() {
return new Mutable(null);
}
/**
* Returns a mutable (partial) match.
* Fields of the mutable match can be filled to create a partial match, usable as matcher input.
*
* @param pT the fixed value of pattern parameter T, or null if not bound.
* @return the new, mutable (partial) match object.
*
*/
public static UnassignedTaskMatch newMutableMatch(final Task pT) {
return new Mutable(pT);
}
/**
* Returns a new (partial) match.
* This can be used e.g. to call the matcher with a partial match.
* <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
* @param pT the fixed value of pattern parameter T, or null if not bound.
* @return the (partial) match object.
*
*/
public static UnassignedTaskMatch newMatch(final Task pT) {
return new Immutable(pT);
}
private static final class Mutable extends UnassignedTaskMatch {
Mutable(final Task pT) {
super(pT);
}
@Override
public boolean isMutable() {
return true;
}
}
private static final class Immutable extends UnassignedTaskMatch {
Immutable(final Task pT) {
super(pT);
}
@Override
public boolean isMutable() {
return false;
}
}
}