Skip to content

Make *(one|zero) weights singletons #153

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

Merged
merged 10 commits into from
May 6, 2025
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
public class SetDomainOne implements SetDomain {
@NonNull private static final SetDomainOne one = new SetDomainOne();

private SetDomainOne() {}

public static Weight one() {
return one;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public class SetDomainZero implements SetDomain {

@NonNull private static final SetDomainZero zero = new SetDomainZero();

private SetDomainZero() {}

@NonNull
@Override
public Weight extendWith(@NonNull Weight other) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class DataFlowPathWeightOne implements DataFlowPathWeight {

@NonNull private static final DataFlowPathWeightOne one = new DataFlowPathWeightOne();

public DataFlowPathWeightOne() {}
private DataFlowPathWeightOne() {}

public static DataFlowPathWeightOne one() {
return one;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ public boolean equals(Object obj) {

@Override
public String toString() {
final Weight one = new MinDistanceWeightOne();
return (this == one) ? "ONE " : " Distance: " + minDistance;
return "Distance: " + minDistance;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public static MinDistanceWeightOne one() {
return one;
}

private MinDistanceWeightOne() {}

@NonNull
@Override
public Weight extendWith(@NonNull Weight o) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class PathConditionWeightOne implements PathConditionWeight {

@NonNull private static final PathConditionWeightOne one = new PathConditionWeightOne();

public PathConditionWeightOne(
private PathConditionWeightOne(
Map<Statement, ConditionDomain> newIfs,
Map<Val, ConditionDomain> newVals,
Set<Val> newReturnVals,
Expand All @@ -52,17 +52,17 @@ public Map<Method, Statement> getCalleeToCallSite() {
throw new IllegalStateException("PathConditionWeightOne.getCalleeToCallSite() - don't");
}

public PathConditionWeightOne() {}
private PathConditionWeightOne() {}

public static PathConditionWeightOne one() {
return one;
}

public PathConditionWeightOne(Statement callSite, Method callee) {
private PathConditionWeightOne(Statement callSite, Method callee) {
this.getCalleeToCallSite().put(callee, callSite);
}

public PathConditionWeightOne(Val returnVal) {
private PathConditionWeightOne(Val returnVal) {
this.getReturnVals().add(returnVal);
}

Expand Down
5 changes: 3 additions & 2 deletions idealPDS/src/main/java/typestate/TransitionFunctionOne.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class TransitionFunctionOne implements TransitionFunction {

@NonNull private static final TransitionFunctionOne one = new TransitionFunctionOne();

public TransitionFunctionOne() {}
private TransitionFunctionOne() {}

public static TransitionFunctionOne one() {
return one;
Expand All @@ -50,8 +50,9 @@ public Set<ControlFlowGraph.Edge> getStateChangeStatements() {
"TransitionFunctionOne.getStateChangeStatements() - This should not happen!");
}

@NonNull
@Override
public Weight extendWith(Weight other) {
public Weight extendWith(@NonNull Weight other) {
if (other.equals(one())) return this;
if (this.equals(one())) return other;
if (other.equals(zero()) || this.equals(zero())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class TransitionFunctionZero implements TransitionFunction {

@NonNull private static final TransitionFunctionZero zero = new TransitionFunctionZero();

public TransitionFunctionZero() {}
private TransitionFunctionZero() {}

@NonNull
public static TransitionFunctionZero zero() {
Expand Down
Loading