Skip to content

Commit abcb689

Browse files
committed
reformatting files
1 parent 95c7ef2 commit abcb689

File tree

3 files changed

+41
-51
lines changed

3 files changed

+41
-51
lines changed

src/main/java/bwapi/Client.java

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ public interface EventHandler {
5050

5151
private static final int SUPPORTED_BWAPI_VERSION = 10003;
5252
static final int MAX_COUNT = 19999;
53-
static final int MAX_STRING_SIZE = 1024;
5453

5554
private ClientData clientData;
5655
private ClientData.GameData gameData;
@@ -68,8 +67,8 @@ public interface EventHandler {
6867
/**
6968
* For test purposes only
7069
*/
71-
Client(final WrappedBuffer memory) {
72-
clientData = new ClientData(memory);
70+
Client(final WrappedBuffer buffer) {
71+
clientData = new ClientData(buffer);
7372
gameData = clientData.new GameData(0);
7473
}
7574

@@ -85,7 +84,7 @@ boolean isConnected() {
8584
return connected;
8685
}
8786

88-
void reconnect(){
87+
void reconnect() {
8988
while (!connect()) {
9089
sleep(1000);
9190
}
@@ -100,11 +99,10 @@ void disconnect() {
10099
return;
101100
}
102101

103-
if (pipeObjectHandle != null ) {
102+
if (pipeObjectHandle != null) {
104103
try {
105104
pipeObjectHandle.close();
106-
}
107-
catch (Exception e) {
105+
} catch (Exception e) {
108106
e.printStackTrace();
109107
}
110108
pipeObjectHandle = null;
@@ -130,17 +128,15 @@ boolean connect() {
130128
.OpenFileMapping(READ_WRITE, false, "Local\\bwapi_shared_memory_game_list"), READ_WRITE,
131129
0, 0, GameTable.SIZE);
132130
gameTableFileHandle = new WrappedBuffer(gameTableView, GameTable.SIZE);
133-
}
134-
catch (Exception e) {
131+
} catch (Exception e) {
135132
System.err.println("Game table mapping not found.");
136133
return false;
137134
}
138135

139136
GameTable gameTable;
140137
try {
141138
gameTable = new GameTable(gameTableFileHandle);
142-
}
143-
catch (Exception e) {
139+
} catch (Exception e) {
144140
System.err.println("Unable to map Game table.");
145141
if (debugConnection) {
146142
e.printStackTrace();
@@ -149,11 +145,11 @@ boolean connect() {
149145
}
150146

151147
int latest = 0;
152-
for(int i = 0; i < GameTable.MAX_GAME_INSTANCES; i++) {
148+
for (int i = 0; i < GameTable.MAX_GAME_INSTANCES; i++) {
153149
GameInstance gameInstance = gameTable.gameInstances[i];
154150
System.out.println(i + " | " + gameInstance.serverProcessID + " | " + (gameInstance.isConnected ? 1 : 0) + " | " + gameInstance.lastKeepAliveTime);
155151
if (gameInstance.serverProcessID != 0 && !gameInstance.isConnected) {
156-
if ( gameTableIndex == -1 || latest == 0 || gameInstance.lastKeepAliveTime < latest ) {
152+
if (gameTableIndex == -1 || latest == 0 || gameInstance.lastKeepAliveTime < latest) {
157153
latest = gameInstance.lastKeepAliveTime;
158154
gameTableIndex = i;
159155
}
@@ -172,9 +168,8 @@ boolean connect() {
172168
final String sharedMemoryName = "Local\\bwapi_shared_memory_" + serverProcID;
173169
final String communicationPipe = "\\\\.\\pipe\\bwapi_pipe_" + serverProcID;
174170
try {
175-
pipeObjectHandle = new RandomAccessFile(communicationPipe, "rw");
176-
}
177-
catch (Exception e) {
171+
pipeObjectHandle = new RandomAccessFile(communicationPipe, "rw");
172+
} catch (Exception e) {
178173
System.err.println("Unable to open communications pipe: " + communicationPipe);
179174
if (debugConnection) {
180175
e.printStackTrace();
@@ -189,8 +184,7 @@ boolean connect() {
189184
.OpenFileMapping(READ_WRITE, false, sharedMemoryName), READ_WRITE,
190185
0, 0, GameData.SIZE);
191186
mapFileHandle = new WrappedBuffer(mapFileView, GameData.SIZE);
192-
}
193-
catch (Exception e) {
187+
} catch (Exception e) {
194188
System.err.println("Unable to open shared memory mapping: " + sharedMemoryName);
195189
if (debugConnection) {
196190
e.printStackTrace();
@@ -202,8 +196,7 @@ boolean connect() {
202196
try {
203197
clientData = new ClientData(mapFileHandle);
204198
gameData = clientData.new GameData(0);
205-
}
206-
catch (Exception e) {
199+
} catch (Exception e) {
207200
System.err.println("Unable to map game data.");
208201
if (debugConnection) {
209202
e.printStackTrace();
@@ -223,8 +216,7 @@ boolean connect() {
223216
while (code != 2) {
224217
try {
225218
code = pipeObjectHandle.readByte();
226-
}
227-
catch (Exception e) {
219+
} catch (Exception e) {
228220
System.err.println("Unable to read pipe object.");
229221
if (debugConnection) {
230222
e.printStackTrace();
@@ -243,8 +235,7 @@ void update(final EventHandler handler) {
243235
byte code = 1;
244236
try {
245237
pipeObjectHandle.writeByte(code);
246-
}
247-
catch (Exception e) {
238+
} catch (Exception e) {
248239
System.err.println("failed, disconnecting");
249240
if (debugConnection) {
250241
e.printStackTrace();
@@ -255,8 +246,7 @@ void update(final EventHandler handler) {
255246
while (code != 2) {
256247
try {
257248
code = pipeObjectHandle.readByte();
258-
}
259-
catch (Exception e) {
249+
} catch (Exception e) {
260250
System.err.println("failed, disconnecting");
261251
if (debugConnection) {
262252
e.printStackTrace();
@@ -313,10 +303,9 @@ ClientData.UnitCommand addUnitCommand() {
313303
}
314304

315305
private void sleep(final int millis) {
316-
try{
306+
try {
317307
Thread.sleep(millis);
318-
}
319-
catch (Exception ignored) {
308+
} catch (Exception ignored) {
320309
}
321310
}
322311
}

src/main/java/bwapi/WrappedBuffer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@
88
import java.nio.ByteBuffer;
99

1010
/**
11-
* Wrapper around offheap memory that uses sun.misc.Unsafe to for fast access.
11+
* Wrapper around offheap memory that uses sun.misc.Unsafe for fast access.
1212
*/
1313
class WrappedBuffer {
1414
private final ByteBuffer buffer;
1515
private final long address;
1616

1717
private static Unsafe unsafe;
18+
1819
static {
1920
try {
2021
final Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe");

src/test/java/bwapi/GameTest.java

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
@RunWith(Theories.class)
2121
public class GameTest {
2222

23-
private List<Unit> allUnits = new ArrayList<>();
24-
private Game sut = new Game(mock(Client.class)) {
23+
private final List<Unit> allUnits = new ArrayList<>();
24+
private final Game sut = new Game(mock(Client.class)) {
2525
@Override
2626
public List<Unit> getAllUnits() {
2727
return allUnits;
@@ -30,24 +30,24 @@ public List<Unit> getAllUnits() {
3030
private Unit dummy;
3131

3232
@DataPoints("overlapping")
33-
public static final Pair[] overlapping = {
34-
new Pair<>(new Position(15, 35), new Position(20, 40)),
35-
new Pair<>(new Position(15, 32), new Position(25, 38)),
36-
new Pair<>(new Position(15, 28), new Position(25, 42)),
37-
new Pair<>(new Position(5, 35), new Position(15, 40)),
38-
new Pair<>(new Position(0, 32), new Position(15, 38)),
39-
new Pair<>(new Position(0, 28), new Position(15, 42)),
40-
new Pair<>(new Position(12, 25), new Position(22, 35)),
41-
new Pair<>(new Position(15, 38), new Position(28, 42)),
42-
new Pair<>(new Position(5, 20), new Position(25, 45))
33+
public static final Pair<?, ?>[] overlapping = {
34+
new Pair<>(new Position(15, 35), new Position(20, 40)),
35+
new Pair<>(new Position(15, 32), new Position(25, 38)),
36+
new Pair<>(new Position(15, 28), new Position(25, 42)),
37+
new Pair<>(new Position(5, 35), new Position(15, 40)),
38+
new Pair<>(new Position(0, 32), new Position(15, 38)),
39+
new Pair<>(new Position(0, 28), new Position(15, 42)),
40+
new Pair<>(new Position(12, 25), new Position(22, 35)),
41+
new Pair<>(new Position(15, 38), new Position(28, 42)),
42+
new Pair<>(new Position(5, 20), new Position(25, 45))
4343
};
4444

4545
@DataPoints("non-overlapping")
46-
public static final Pair[] nonOverlapping = {
47-
new Pair<>(new Position(0, 0), new Position(200, 20)),
48-
new Pair<>(new Position(50, 0), new Position(55, 200)),
49-
new Pair<>(new Position(0, 0), new Position(5, 200)),
50-
new Pair<>(new Position(0, 45), new Position(20, 50))
46+
public static final Pair<?, ?>[] nonOverlapping = {
47+
new Pair<>(new Position(0, 0), new Position(200, 20)),
48+
new Pair<>(new Position(50, 0), new Position(55, 200)),
49+
new Pair<>(new Position(0, 0), new Position(5, 200)),
50+
new Pair<>(new Position(0, 45), new Position(20, 50))
5151
};
5252

5353
@Before
@@ -61,27 +61,27 @@ public void setup() {
6161

6262
@Theory
6363
public void shouldFindOverlappingUnits(
64-
@FromDataPoints("overlapping") Pair<Position, Position> rect) {
64+
@FromDataPoints("overlapping") Pair<Position, Position> rect) {
6565
// GIVEN
6666
allUnits.add(dummy);
6767

6868
// WHEN
6969
List<Unit> unitsInRectangle = sut
70-
.getUnitsInRectangle(rect.getLeft(), rect.getRight(), unused -> true);
70+
.getUnitsInRectangle(rect.getLeft(), rect.getRight(), unused -> true);
7171

7272
// THEN
7373
assertThat(unitsInRectangle).contains(dummy);
7474
}
7575

7676
@Theory
7777
public void shouldNotFindNonOverlappingUnits(
78-
@FromDataPoints("non-overlapping") Pair<Position, Position> rect) {
78+
@FromDataPoints("non-overlapping") Pair<Position, Position> rect) {
7979
// GIVEN
8080
allUnits.add(dummy);
8181

8282
// WHEN
8383
List<Unit> unitsInRectangle = sut
84-
.getUnitsInRectangle(rect.getLeft(), rect.getRight(), unused -> true);
84+
.getUnitsInRectangle(rect.getLeft(), rect.getRight(), unused -> true);
8585

8686
// THEN
8787
assertThat(unitsInRectangle).doesNotContain(dummy);

0 commit comments

Comments
 (0)