Skip to content

Commit 48c9d63

Browse files
committed
remove dependency on apache.commons
1 parent 168f502 commit 48c9d63

19 files changed

+191
-123
lines changed

pom.xml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,6 @@
5959
<version>4.5.2</version>
6060
</dependency>
6161

62-
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
63-
<dependency>
64-
<groupId>org.apache.commons</groupId>
65-
<artifactId>commons-lang3</artifactId>
66-
<version>3.8.1</version>
67-
</dependency>
68-
6962
<!-- https://mvnrepository.com/artifact/junit/junit -->
7063
<dependency>
7164
<groupId>junit</groupId>

src/main/java/bwapi/Pair.java

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package bwapi;
2+
3+
import java.util.Objects;
4+
5+
public class Pair<K,V> {
6+
private K first;
7+
private V second;
8+
9+
public Pair(final K first, final V second) {
10+
this.first = first;
11+
this.second = second;
12+
}
13+
14+
//BWMIRROR SUPPORT
15+
public K getFirst() {
16+
return first;
17+
}
18+
19+
public V getSecond() {
20+
return second;
21+
}
22+
23+
//BWEM SUPPORT
24+
public K getLeft() {
25+
return first;
26+
}
27+
28+
public V getRight() {
29+
return second;
30+
}
31+
32+
public void setLeft(final K left) {
33+
first = left;
34+
}
35+
36+
public void setRight(final V right) {
37+
second = right;
38+
}
39+
40+
//MAP.ENTRY SUPPORT
41+
public K getKey() {
42+
return first;
43+
}
44+
45+
public V getValue() {
46+
return second;
47+
}
48+
49+
@Override
50+
public String toString() {
51+
return "{" + first + ", " + second + "}";
52+
}
53+
54+
@Override
55+
public boolean equals(final Object o) {
56+
if (o instanceof Pair) {
57+
final Pair op = (Pair)o;
58+
return first.equals(op.first) && second.equals(op.second);
59+
}
60+
return false;
61+
}
62+
63+
@Override
64+
public int hashCode() {
65+
return Objects.hash(first, second);
66+
}
67+
}

src/main/java/bwapi/UnitType.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ public Race getRace() {
266266
return UnitTypeContainer.unitRace[id];
267267
}
268268

269-
public Entry<UnitType, Integer> whatBuilds() {
269+
public Pair<UnitType, Integer> whatBuilds() {
270270
// Retrieve the type
271271
final UnitType type = UnitTypeContainer.whatBuilds[id];
272272
int count = 1;
@@ -277,7 +277,7 @@ public Entry<UnitType, Integer> whatBuilds() {
277277
count = 2;
278278
}
279279
// Return the desired pair
280-
return new AbstractMap.SimpleEntry<>(type, count);
280+
return new Pair<>(type, count);
281281
}
282282

283283
public Map<UnitType, Integer> requiredUnits() {

src/main/java/bwapi/UnitTypeContainer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1455,7 +1455,7 @@ private static List<Map<UnitType, Integer>> reqUnitsInit() {
14551455
// Add the whatBuilds types to the required units map
14561456
for (final UnitType i : UnitType.values()) {
14571457
req.add(new HashMap<>());
1458-
final Map.Entry<UnitType, Integer> wb = i.whatBuilds();
1458+
final Pair<UnitType, Integer> wb = i.whatBuilds();
14591459
if (wb.getKey() != UnitType.None) {
14601460
req.get(i.id).put(wb.getKey(), wb.getValue());
14611461
}

src/main/java/bwem/ChokePoint.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import bwem.area.Area;
1717
import bwem.typedef.CPPath;
1818
import bwem.unit.Neutral;
19-
import org.apache.commons.lang3.tuple.Pair;
19+
import bwapi.Pair;
2020

2121
import java.util.List;
2222

src/main/java/bwem/ChokePointImpl.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
import bwem.typedef.CPPath;
2121
import bwem.typedef.Index;
2222
import bwem.unit.Neutral;
23-
import org.apache.commons.lang3.tuple.ImmutablePair;
24-
import org.apache.commons.lang3.tuple.MutablePair;
25-
import org.apache.commons.lang3.tuple.Pair;
23+
import bwapi.Pair;
24+
import bwapi.Pair;
25+
import bwapi.Pair;
2626

2727
import java.util.ArrayList;
2828
import java.util.List;
@@ -34,7 +34,7 @@ public class ChokePointImpl implements ChokePoint {
3434
private final Index index;
3535
private final Pair<Area, Area> areas;
3636
private final WalkPosition[] nodes;
37-
private final List<MutablePair<WalkPosition, WalkPosition>> nodesInArea;
37+
private final List<Pair<WalkPosition, WalkPosition>> nodesInArea;
3838
private final List<WalkPosition> geometry;
3939
private boolean isBlocked;
4040
private Neutral blockingNeutral;
@@ -53,7 +53,7 @@ public ChokePointImpl(
5353

5454
this.graph = graph;
5555
this.index = index;
56-
this.areas = new ImmutablePair<>(area1, area2);
56+
this.areas = new Pair<>(area1, area2);
5757
this.geometry = geometry;
5858

5959
// Ensures that in the case where several neutrals are stacked, blockingNeutral points to the
@@ -72,7 +72,7 @@ public ChokePointImpl(
7272

7373
this.nodesInArea = new ArrayList<>(Node.NODE_COUNT.ordinal());
7474
for (int i = 0; i < Node.NODE_COUNT.ordinal(); ++i) {
75-
this.nodesInArea.add(new MutablePair<>(new WalkPosition(0, 0), new WalkPosition(0, 0)));
75+
this.nodesInArea.add(new Pair<>(new WalkPosition(0, 0), new WalkPosition(0, 0)));
7676
}
7777

7878
int i = geometry.size() / 2;
@@ -143,8 +143,8 @@ > getMap().getData().getMiniTile(geometry.get(i)).getAltitude().intValue())) {
143143
*/
144144
final WalkPosition left = nodesInArea.get(n).getLeft();
145145
final WalkPosition right = nodesInArea.get(n).getRight();
146-
final MutablePair<WalkPosition, WalkPosition> replacementPair =
147-
new MutablePair<>(left, right);
146+
final Pair<WalkPosition, WalkPosition> replacementPair =
147+
new Pair<>(left, right);
148148
if (area.equals(this.areas.getLeft())) {
149149
replacementPair.setLeft(nodeInArea);
150150
} else {

src/main/java/bwem/Graph.java

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,7 @@
3434
import bwem.unit.StaticBuilding;
3535
import bwem.util.BwemExt;
3636
import bwem.util.Utils;
37-
import org.apache.commons.lang3.mutable.MutableInt;
38-
import org.apache.commons.lang3.tuple.ImmutablePair;
39-
import org.apache.commons.lang3.tuple.MutablePair;
40-
import org.apache.commons.lang3.tuple.Pair;
37+
import bwapi.Pair;
4138

4239
import java.util.*;
4340

@@ -287,7 +284,7 @@ public List<Base> getBases() {
287284

288285
// Creates a new Area for each pair (top, miniTiles) in areasList (See Area::top() and
289286
// Area::miniTiles())
290-
public void createAreas(final List<MutablePair<WalkPosition, Integer>> areasList) {
287+
public void createAreas(final List<Pair<WalkPosition, Integer>> areasList) {
291288
for (int id = 1; id <= areasList.size(); ++id) {
292289
final WalkPosition top = areasList.get(id - 1).getLeft();
293290
final int miniTileCount = areasList.get(id - 1).getRight();
@@ -322,13 +319,13 @@ private void initializeChokePointsMatrix(
322319
// ----------------------------------------------------------------------
323320
// 2) Dispatch the global raw frontier between all the relevant pairs of areas:
324321
// ----------------------------------------------------------------------
325-
private java.util.Map<MutablePair<AreaId, AreaId>, List<WalkPosition>>
322+
private java.util.Map<Pair<AreaId, AreaId>, List<WalkPosition>>
326323
createRawFrontierByAreaPairMap(
327-
final List<MutablePair<MutablePair<AreaId, AreaId>, WalkPosition>> rawFrontier) {
328-
final java.util.Map<MutablePair<AreaId, AreaId>, List<WalkPosition>> rawFrontierByAreaPair =
324+
final List<Pair<Pair<AreaId, AreaId>, WalkPosition>> rawFrontier) {
325+
final java.util.Map<Pair<AreaId, AreaId>, List<WalkPosition>> rawFrontierByAreaPair =
329326
new HashMap<>();
330327

331-
for (final MutablePair<MutablePair<AreaId, AreaId>, WalkPosition> raw : rawFrontier) {
328+
for (final Pair<Pair<AreaId, AreaId>, WalkPosition> raw : rawFrontier) {
332329
int a = raw.getLeft().getLeft().intValue();
333330
int b = raw.getLeft().getRight().intValue();
334331
if (a > b) {
@@ -345,7 +342,7 @@ private void initializeChokePointsMatrix(
345342
throw new IllegalStateException();
346343
}
347344

348-
final MutablePair<AreaId, AreaId> key = new MutablePair<>(new AreaId(a), new AreaId(b));
345+
final Pair<AreaId, AreaId> key = new Pair<>(new AreaId(a), new AreaId(b));
349346
rawFrontierByAreaPair.computeIfAbsent(key, mp -> new ArrayList<>()).add(raw.getRight());
350347
}
351348

@@ -360,7 +357,7 @@ private void initializeChokePointsMatrix(
360357
public void createChokePoints(
361358
final List<StaticBuilding> staticBuildings,
362359
final List<Mineral> minerals,
363-
final List<MutablePair<MutablePair<AreaId, AreaId>, WalkPosition>> rawFrontier) {
360+
final List<Pair<Pair<AreaId, AreaId>, WalkPosition>> rawFrontier) {
364361
Index newIndex = new Index(0);
365362

366363
final List<Neutral> blockingNeutrals = new ArrayList<>();
@@ -389,13 +386,13 @@ public void createChokePoints(
389386
initializeChokePointsMatrix(this.chokePointsMatrix, getAreaCount());
390387

391388
// 2) Dispatch the global raw frontier between all the relevant pairs of areas:
392-
final java.util.Map<MutablePair<AreaId, AreaId>, List<WalkPosition>> rawFrontierByAreaPair =
389+
final java.util.Map<Pair<AreaId, AreaId>, List<WalkPosition>> rawFrontierByAreaPair =
393390
createRawFrontierByAreaPairMap(rawFrontier);
394391

395392
// 3) For each pair of areas (A, B):
396-
for (final java.util.Map.Entry<MutablePair<AreaId, AreaId>, List<WalkPosition>> entry :
393+
for (final java.util.Map.Entry<Pair<AreaId, AreaId>, List<WalkPosition>> entry :
397394
rawFrontierByAreaPair.entrySet()) {
398-
MutablePair<AreaId, AreaId> rawleft = entry.getKey();
395+
Pair<AreaId, AreaId> rawleft = entry.getKey();
399396
final List<WalkPosition> rawFrontierAB = entry.getValue();
400397

401398
// Because our dispatching preserved order,
@@ -709,7 +706,7 @@ private int[] computeDistances(final ChokePoint start, final List<ChokePoint> ta
709706

710707
final Queue<Pair<Integer, ChokePoint>> toVisit =
711708
new PriorityQueue<>(Comparator.comparingInt(a -> a.getLeft()));
712-
toVisit.offer(new ImmutablePair<>(0, start));
709+
toVisit.offer(new Pair<>(0, start));
713710

714711
int remainingTargets = targets.size();
715712
while (!toVisit.isEmpty()) {
@@ -753,18 +750,18 @@ private int[] computeDistances(final ChokePoint start, final List<ChokePoint> ta
753750
// To update next's distance, we need to remove-insert it from toVisit:
754751
// bwem_assert(iNext != range.second);
755752
final boolean removed =
756-
toVisit.remove(new ImmutablePair<>(((TileImpl) nextTile).getInternalData(), next));
753+
toVisit.remove(new Pair<>(((TileImpl) nextTile).getInternalData(), next));
757754
if (!removed) {
758755
throw new IllegalStateException();
759756
}
760757
((TileImpl) nextTile).setInternalData(newNextDist);
761758
((ChokePointImpl) next).setPathBackTrace(current);
762-
toVisit.offer(new ImmutablePair<>(newNextDist, next));
759+
toVisit.offer(new Pair<>(newNextDist, next));
763760
}
764761
} else {
765762
((TileImpl) nextTile).setInternalData(newNextDist);
766763
((ChokePointImpl) next).setPathBackTrace(current);
767-
toVisit.offer(new ImmutablePair<>(newNextDist, next));
764+
toVisit.offer(new Pair<>(newNextDist, next));
768765
}
769766
}
770767
}

src/main/java/bwem/MutableInt.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package bwem;
2+
3+
public class MutableInt {
4+
private int value;
5+
6+
public int intValue() {
7+
return value;
8+
}
9+
10+
public void setValue(final int value) {
11+
this.value = value;
12+
}
13+
}

src/main/java/bwem/area/AreaInitializerImpl.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
import bwem.tile.TileImpl;
2626
import bwem.unit.*;
2727
import bwem.util.BwemExt;
28-
import org.apache.commons.lang3.tuple.ImmutablePair;
29-
import org.apache.commons.lang3.tuple.Pair;
28+
import bwapi.Pair;
29+
import bwapi.Pair;
3030

3131
import java.util.*;
3232

@@ -207,7 +207,7 @@ public int[] computeDistances(final TilePosition start, final List<TilePosition>
207207
Comparator.comparingInt(
208208
Pair::getLeft)); // a priority queue holding the tiles to visit ordered by their
209209
// distance to start.
210-
toVisit.offer(new ImmutablePair<>(0, start));
210+
toVisit.offer(new Pair<>(0, start));
211211

212212
int remainingTargets = targets.size();
213213
while (!toVisit.isEmpty()) {
@@ -260,17 +260,17 @@ public int[] computeDistances(final TilePosition start, final List<TilePosition>
260260
// To update next's distance, we need to remove-insert it from toVisit:
261261
// bwem_assert(iNext != range.second);
262262
final boolean removed =
263-
toVisit.remove(new ImmutablePair<>(((TileImpl) nextTile).getInternalData(), next));
263+
toVisit.remove(new Pair<>(((TileImpl) nextTile).getInternalData(), next));
264264
if (!removed) {
265265
throw new IllegalStateException();
266266
}
267267
((TileImpl) nextTile).setInternalData(newNextDist);
268-
toVisit.offer(new ImmutablePair<>(newNextDist, next));
268+
toVisit.offer(new Pair<>(newNextDist, next));
269269
}
270270
} else if ((nextTile.getAreaId().equals(getId()))
271271
|| (nextTile.getAreaId().equals(UNINITIALIZED))) {
272272
((TileImpl) nextTile).setInternalData(newNextDist);
273-
toVisit.offer(new ImmutablePair<>(newNextDist, next));
273+
toVisit.offer(new Pair<>(newNextDist, next));
274274
}
275275
}
276276
}

src/main/java/bwem/map/Map.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@
2424
import bwem.typedef.CPPath;
2525
import bwem.typedef.Pred;
2626
import bwem.unit.NeutralData;
27-
import org.apache.commons.lang3.mutable.MutableInt;
28-
import org.apache.commons.lang3.tuple.MutablePair;
27+
import bwapi.Pair;
2928

3029
import java.util.List;
3130

@@ -150,7 +149,7 @@ public interface Map {
150149
// To avoid this and the potential performance penalty, just make sure getArea(a) != nullptr
151150
// and getArea(b) != nullptr.
152151
// Then GetPath should perform very quick.
153-
CPPath getPath(Position a, Position b, MutableInt pLength);
152+
int getPathLength(Position a, Position b);
154153

155154
CPPath getPath(Position a, Position b);
156155

@@ -167,6 +166,6 @@ WalkPosition breadthFirstSearch(
167166
WalkPosition breadthFirstSearch(WalkPosition start, Pred findCond, Pred visitCond);
168167

169168
// Returns the union of the geometry of all the ChokePoints. Cf. ChokePoint::Geometry()
170-
List<MutablePair<MutablePair<AreaId, AreaId>, WalkPosition>> getRawFrontier();
169+
List<Pair<Pair<AreaId, AreaId>, WalkPosition>> getRawFrontier();
171170

172171
}

0 commit comments

Comments
 (0)