Skip to content

Commit 3513b58

Browse files
committed
fix dereference warnings
1 parent 5b3a5fa commit 3513b58

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

src/main/java/bwem/BWMapInitializer.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -432,14 +432,15 @@ private List<Pair<WalkPosition, MiniTile>> getSortedMiniTilesByDescendingAltitud
432432
final List<Pair<WalkPosition, MiniTile>> miniTilesByDescendingAltitude =
433433
new ArrayList<>();
434434

435-
for (int y = 0; y < getData().getMapData().getWalkSize().getY(); ++y)
435+
for (int y = 0; y < getData().getMapData().getWalkSize().getY(); ++y) {
436436
for (int x = 0; x < getData().getMapData().getWalkSize().getX(); ++x) {
437437
final WalkPosition w = new WalkPosition(x, y);
438438
final MiniTile miniTile = getData().getMiniTile(w, CheckMode.NO_CHECK);
439439
if (miniTile.isAreaIdMissing()) {
440440
miniTilesByDescendingAltitude.add(new Pair<>(w, miniTile));
441441
}
442442
}
443+
}
443444

444445
miniTilesByDescendingAltitude.sort(MiniTile.BY_ALTITUDE_ORDER);
445446
Collections.reverse(miniTilesByDescendingAltitude);
@@ -593,7 +594,7 @@ private void createAreas(final List<TempAreaInfo> tempAreaList, final int areaMi
593594
private void setLowestAltitudeInTile(final TilePosition t) {
594595
Altitude lowestAltitude = new Altitude(Integer.MAX_VALUE);
595596

596-
for (int dy = 0; dy < 4; ++dy)
597+
for (int dy = 0; dy < 4; ++dy) {
597598
for (int dx = 0; dx < 4; ++dx) {
598599
final Altitude altitude =
599600
getData()
@@ -605,6 +606,7 @@ private void setLowestAltitudeInTile(final TilePosition t) {
605606
lowestAltitude = altitude;
606607
}
607608
}
609+
}
608610

609611
getData().getTile(t).setLowestAltitude(lowestAltitude);
610612
}
@@ -620,14 +622,18 @@ private void setAreaIdAndLowestAltitudeInTiles() {
620622
}
621623

622624
void onBlockingNeutralDestroyed(Neutral pBlocking) {
623-
if (!(pBlocking != null && pBlocking.isBlocking())) {
625+
if (pBlocking == null) {
626+
throw new IllegalStateException();
627+
}
628+
if (!pBlocking.isBlocking()) {
624629
asserter.throwIllegalStateException("");
625630
}
626631

627-
for (Area pArea : pBlocking.getBlockedAreas())
632+
for (Area pArea : pBlocking.getBlockedAreas()) {
628633
for (ChokePoint cp : pArea.getChokePoints()) {
629634
cp.onBlockingNeutralDestroyed(pBlocking);
630635
}
636+
}
631637

632638
// there remains some blocking Neutrals at the same location
633639
if (getData().getTile(pBlocking.getTopLeft()).getNeutral() != null) {
@@ -637,22 +643,24 @@ void onBlockingNeutralDestroyed(Neutral pBlocking) {
637643
// Unblock the miniTiles of pBlocking:
638644
AreaId newId = pBlocking.getBlockedAreas().iterator().next().getId();
639645
WalkPosition pBlockingW = pBlocking.getSize().toWalkPosition();
640-
for (int dy = 0; dy < pBlockingW.getY(); ++dy)
646+
for (int dy = 0; dy < pBlockingW.getY(); ++dy) {
641647
for (int dx = 0; dx < pBlockingW.getX(); ++dx) {
642648
MiniTile miniTile = getData().getMiniTile(
643-
pBlocking.getTopLeft().toWalkPosition().add(new WalkPosition(dx, dy)));
649+
pBlocking.getTopLeft().toWalkPosition().add(new WalkPosition(dx, dy)));
644650
if (miniTile.isWalkable()) {
645651
miniTile.replaceBlockedAreaId(newId);
646652
}
647653
}
654+
}
648655

649656
// Unblock the Tiles of pBlocking:
650-
for (int dy = 0; dy < pBlocking.getSize().getY(); ++dy)
657+
for (int dy = 0; dy < pBlocking.getSize().getY(); ++dy) {
651658
for (int dx = 0; dx < pBlocking.getSize().getX(); ++dx) {
652659
getData().getTile(pBlocking.getTopLeft().add(new TilePosition(dx, dy)))
653660
.resetAreaId();
654661
setAreaIdInTile(pBlocking.getTopLeft().add(new TilePosition(dx, dy)));
655662
}
663+
}
656664

657665
if (automaticPathUpdate()) {
658666
getGraph().computeChokePointDistanceMatrix();

src/main/java/bwem/ChokePoint.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,10 @@ public CPPath getPathTo(final ChokePoint cp) {
274274
}
275275

276276
void onBlockingNeutralDestroyed(final Neutral pBlocking) {
277-
if (!(pBlocking != null && pBlocking.isBlocking())) {
277+
if (pBlocking == null) {
278+
throw new IllegalStateException();
279+
}
280+
if (!pBlocking.isBlocking()) {
278281
graph.getMap().asserter.throwIllegalStateException("");
279282
}
280283

0 commit comments

Comments
 (0)