org.ggp.base.util.gdl.model.assignments.AssignmentIterationPlan Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of alloy-ggp-base Show documentation
Show all versions of alloy-ggp-base Show documentation
A modified version of the GGP-Base library for Alloy.
The newest version!
package org.ggp.base.util.gdl.model.assignments;
import java.util.List;
import java.util.Map;
import org.ggp.base.util.gdl.grammar.GdlConstant;
import org.ggp.base.util.gdl.grammar.GdlDistinct;
import org.ggp.base.util.gdl.grammar.GdlVariable;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
public class AssignmentIterationPlan {
//TODO: Come up with better representations
private final ImmutableList varsToAssign;
private final ImmutableList>> tuplesBySource;
private final ImmutableMap headAssignment;
private final ImmutableList indicesToChangeWhenNull;
private final ImmutableList distincts;
private final ImmutableMap varsToChangePerDistinct;
private final ImmutableMap valuesToCompute;
private final ImmutableList sourceDefiningSlot;
private final ImmutableList> valuesToIterate;
private final ImmutableList> varsChosenBySource;
private final ImmutableList> putDontCheckBySource;
private final boolean empty;
private final boolean allDone;
public AssignmentIterationPlan(
ImmutableList varsToAssign,
ImmutableList>> tuplesBySource,
ImmutableMap headAssignment,
ImmutableList indicesToChangeWhenNull,
ImmutableList distincts,
ImmutableMap varsToChangePerDistinct,
ImmutableMap valuesToCompute,
ImmutableList sourceDefiningSlot,
ImmutableList> valuesToIterate,
ImmutableList> varsChosenBySource,
ImmutableList> putDontCheckBySource,
boolean empty,
boolean allDone) {
this.varsToAssign = varsToAssign;
this.tuplesBySource = tuplesBySource;
this.headAssignment = headAssignment;
this.indicesToChangeWhenNull = indicesToChangeWhenNull;
this.distincts = distincts;
this.varsToChangePerDistinct = varsToChangePerDistinct;
this.valuesToCompute = valuesToCompute;
this.sourceDefiningSlot = sourceDefiningSlot;
this.valuesToIterate = valuesToIterate;
this.varsChosenBySource = varsChosenBySource;
this.putDontCheckBySource = putDontCheckBySource;
this.empty = empty;
this.allDone = allDone;
}
public ImmutableList getVarsToAssign() {
return varsToAssign;
}
public ImmutableList>> getTuplesBySource() {
return tuplesBySource;
}
public ImmutableMap getHeadAssignment() {
return headAssignment;
}
public ImmutableList getIndicesToChangeWhenNull() {
return indicesToChangeWhenNull;
}
public ImmutableList getDistincts() {
return distincts;
}
public ImmutableMap getVarsToChangePerDistinct() {
return varsToChangePerDistinct;
}
public ImmutableMap getValuesToCompute() {
return valuesToCompute;
}
public ImmutableList getSourceDefiningSlot() {
return sourceDefiningSlot;
}
public ImmutableList> getValuesToIterate() {
return valuesToIterate;
}
public ImmutableList> getVarsChosenBySource() {
return varsChosenBySource;
}
public ImmutableList> getPutDontCheckBySource() {
return putDontCheckBySource;
}
public boolean getEmpty() {
return empty;
}
public boolean getAllDone() {
return allDone;
}
private static final AssignmentIterationPlan EMPTY_ITERATION_PLAN =
new AssignmentIterationPlan(
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
true,
false
);
public static AssignmentIterationPlan create(List varsToAssign,
List>> tuplesBySource,
Map headAssignment,
List indicesToChangeWhenNull,
List distincts,
List varsToChangePerDistinct,
List valuesToCompute,
List sourceDefiningSlot,
List> valuesToIterate,
List> varsChosenBySource,
List> putDontCheckBySource,
boolean empty,
boolean allDone) {
if (empty) {
return EMPTY_ITERATION_PLAN;
}
return new AssignmentIterationPlan(ImmutableList.copyOf(varsToAssign),
ImmutableList.copyOf(tuplesBySource),
ImmutableMap.copyOf(headAssignment),
ImmutableList.copyOf(indicesToChangeWhenNull),
ImmutableList.copyOf(distincts),
fromNullableList(varsToChangePerDistinct),
fromNullableList(valuesToCompute),
ImmutableList.copyOf(sourceDefiningSlot),
ImmutableList.copyOf(valuesToIterate),
ImmutableList.copyOf(varsChosenBySource),
ImmutableList.copyOf(putDontCheckBySource),
empty,
allDone);
}
private static ImmutableMap fromNullableList(
List nullableList) {
ImmutableMap.Builder builder = ImmutableMap.builder();
for (int i = 0; i < nullableList.size(); i++) {
if (nullableList.get(i) != null) {
builder.put(i, nullableList.get(i));
}
}
return builder.build();
}
}