Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change of range in product - fix 2037066 #115

Merged
merged 12 commits into from
Nov 11, 2023
17 changes: 12 additions & 5 deletions src/main/java/dk/aau/cs/model/CPN/ColorType.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,17 @@ public Integer size() {
return colors.iterator();
}

public Vector<Color> getColors(){
public Vector<Color> getColors() {
return colors;
}

public boolean isIdentical(ColorType newColorType) {
boolean firstColorIdentical = getFirstColor().getColorName().equals(newColorType.getFirstColor().getColorName());
boolean lastColorIdentical = getColors().lastElement().getColorName().equals(newColorType.getColors().lastElement().getColorName());

return firstColorIdentical && lastColorIdentical && !equals(newColorType);
}

@Override
public boolean equals(Object o) {
if (!(o instanceof ColorType) || o instanceof ProductType)
Expand All @@ -52,11 +59,11 @@ public boolean equals(Object o) {

if (!object.name.equals(this.name))
return false;

if(!object.size().equals(size())){
if (!object.size().equals(size())){
return false;
}
for(int i = 0; i < colors.size(); i++){
for (int i = 0; i < colors.size(); i++){
if(!colors.get(i).equals(object.colors.get(i))){
return false;
}
Expand Down Expand Up @@ -139,4 +146,4 @@ public boolean isIntegerRange(){
}
return true;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public abstract class GuardExpression extends Expression {

public ColorType getColorType() { return colorType; }

public void setColorType(ColorType colorType) { this.colorType = colorType; }

@Override
public abstract GuardExpression replace(Expression object1, Expression object2, boolean replaceAllInstances);

Expand Down
10 changes: 10 additions & 0 deletions src/main/java/dk/aau/cs/model/tapn/TimedArcPetriNetNetwork.java
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,16 @@ public Integer getVariableIndex(String name) {
}
return null;
}

public boolean isIndeticalToExisting(ColorType newColorType) {
for (ColorType ct : colorTypes) {
if (ct.isIdentical(newColorType)) {
return true;
}
}

return false;
}

public boolean isNameUsedForColorType(String name) {
for (ColorType element : colorTypes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,7 @@ private void onOK() {
"Error", JOptionPane.ERROR_MESSAGE);
return;
}

try {
if (rangeOfIntegersPanelEnabled && (Integer.parseInt(lowerBoundTextField.getText()) > Integer.parseInt(upperBoundTextField.getText()))) {
JOptionPane.showMessageDialog(
Expand Down Expand Up @@ -1078,6 +1079,14 @@ private void onOK() {
newColorType.addColor(String.valueOf(i));
}

if (network.isIndeticalToExisting(newColorType)) {
JOptionPane.showMessageDialog(
TAPAALGUI.getApp(),
"Color type with identical range already exists!",
"Error", JOptionPane.ERROR_MESSAGE);
return;
}

if (oldColorType != null) {
if (oldColorType.equals(newColorType)) {
exit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,19 @@ public void undo() {
}
}
for (TimedInputArc arc : tapn.inputArcs()) {
if (arc.getArcExpression() != null && arc.source().getColorType() == oldColorType)
if (arc.getArcExpression() != null) {
arc.setExpression(arc.getArcExpression().getExprWithNewColorType(oldColorType));
}
}
for (TimedOutputArc arc : tapn.outputArcs()) {
if (arc.getExpression() != null && arc.destination().getColorType() == oldColorType)
if (arc.getExpression() != null) {
arc.setExpression(arc.getExpression().getExprWithNewColorType(oldColorType));
}
}
for (TimedTransition transition : tapn.transitions()) {
if (transition.getGuard() != null) {
transition.getGuard().setColorType(oldColorType);
}
}
}

Expand Down Expand Up @@ -75,12 +82,19 @@ public void redo() {
}
}
for (TimedInputArc arc : tapn.inputArcs()) {
if (arc.getArcExpression() != null && arc.source().getColorType() == newColorType)
if (arc.getArcExpression() != null) {
arc.setExpression(arc.getArcExpression().getExprWithNewColorType(newColorType));
}
}
for (TimedOutputArc arc : tapn.outputArcs()) {
if (arc.getExpression() != null && arc.destination().getColorType() == newColorType)
if (arc.getExpression() != null) {
arc.setExpression(arc.getExpression().getExprWithNewColorType(newColorType));
}
}
for (TimedTransition transition : tapn.transitions()) {
if (transition.getGuard() != null) {
transition.getGuard().setColorType(newColorType);
}
}
}

Expand Down
Loading