Skip to content

Merging collapsible if statements increases the code's readability #110

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions src/main/java/org/ggp/base/apps/kiosk/GameGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,10 @@ public void actionPerformed(ActionEvent e) {

if(e.getSource() == clearSelectionButton) {
theCanvas.clearMoveSelection();
} else if(e.getSource() == submitMoveButton) {
if(workingMove != null) {
moveBeingSubmitted = true;
updateControls();
notifyObservers(new MoveSelectedEvent(workingMove));
}
} else if(e.getSource() == submitMoveButton && workingMove != null) {
moveBeingSubmitted = true;
updateControls();
notifyObservers(new MoveSelectedEvent(workingMove));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,9 @@ private synchronized void doSchedule(PendingMatch spec) {
File matchFile = new File(matchesDir, match.getMatchId() + ".json");
gameServer.startSavingToFilename(matchFile.getAbsolutePath());
}
if (spec.shouldPublish) {
if (!match.getGame().getRepositoryURL().contains("127.0.0.1")) {
gameServer.startPublishingToSpectatorServer("http://matches.ggp.org/");
gameServer.setForceUsingEntireClock();
}
if (spec.shouldPublish && !match.getGame().getRepositoryURL().contains("127.0.0.1")) {
gameServer.startPublishingToSpectatorServer("http://matches.ggp.org/");
gameServer.setForceUsingEntireClock();
}

gameServers.put(spec.matchID, new WeakReference<GameServer>(gameServer));
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/org/ggp/base/util/gdl/GdlUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,8 @@ private static boolean containsTerm(List<GdlTerm> body, GdlTerm term) {
for(GdlTerm curTerm : body) {
if(curTerm.equals(term))
return true;
if(curTerm instanceof GdlFunction) {
if(containsTerm(((GdlFunction) curTerm).getBody(), term))
return true;
if(curTerm instanceof GdlFunction && containsTerm(((GdlFunction) curTerm).getBody(), term)) {
return true;
}
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@ public static Assignments getAssignmentsWithRecursiveInput(GdlRule rule,
//literals.
List<GdlSentence> matchingLiterals = new ArrayList<GdlSentence>();
for(GdlLiteral literal : rule.getBody())
if(literal instanceof GdlSentence)
if(form.matches((GdlSentence) literal))
matchingLiterals.add((GdlSentence) literal);
if(literal instanceof GdlSentence && form.matches((GdlSentence) literal))
matchingLiterals.add((GdlSentence) literal);

List<Assignments> assignmentsList = new ArrayList<Assignments>();
for(GdlSentence matchingLiteral : matchingLiterals) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,13 +292,11 @@ private List<IterationOrderCandidate> getFunctionAddedChildren(boolean analyticF
//Non-producible vars get iterated over before we start
//deciding which functions to add
for(GdlVariable var : varsToAssign) {
if(!varOrdering.contains(var)) {
if(!functionsProducingVars.containsKey(var)) {
//Add var to the ordering
varOrdering.add(var);
functionalConjunctIndices.add(-1);
varSources.add(-1);
}
if(!varOrdering.contains(var) && !functionsProducingVars.containsKey(var)) {
//Add var to the ordering
varOrdering.add(var);
functionalConjunctIndices.add(-1);
varSources.add(-1);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,9 +360,8 @@ else if(literal instanceof GdlDistinct || literal instanceof GdlNot)
for(GdlVariable varNeeded : varsNeeded) {
Set<GdlLiteral> suppliers = new HashSet<GdlLiteral>();
for(GdlLiteral literal : rule.getBody())
if(literal instanceof GdlRelation)
if(GdlUtils.getVariables(literal).contains(varNeeded))
suppliers.add(literal);
if(literal instanceof GdlRelation && GdlUtils.getVariables(literal).contains(varNeeded))
suppliers.add(literal);
candidateSuppliersList.add(suppliers);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -474,10 +474,8 @@ private static void optimizeAwayFalse(
if (pn != null) {
pn.removeComponent(or);
}
} else if (or.getInputs().size() == 0) {
if (pn != null) {
pn.removeComponent(or);
}
} else if (or.getInputs().size() == 0 && pn != null) {
pn.removeComponent(or);
}
} else if(output instanceof Not) {
Not not = (Not) output;
Expand Down Expand Up @@ -584,10 +582,8 @@ private static void optimizeAwayTrue(
if (pn != null) {
pn.removeComponent(and);
}
} else if (and.getInputs().size() == 0) {
if (pn != null) {
pn.removeComponent(and);
}
} else if (and.getInputs().size() == 0 && pn != null) {
pn.removeComponent(and);
}
} else if(output instanceof Not) {
Not not = (Not) output;
Expand Down