Fixed IslandCacheTest

Also commented out CellState.RESERVED.

That was a tough one. I had to rewrite IslandGrid#getIslandAt(int, int) quite a few times before using the stream() thing. I tested it a bit - it seems it is working like a charm.
I just hope that it won't be something useless - another plumbing change that adds nothing. It shouldn't - because of the "RESERVED" thing - but, well... it's been quite a hard thing!
This commit is contained in:
Florian CUNY 2018-08-14 11:38:44 +02:00
parent 4af03ee939
commit 8fb4e58994
2 changed files with 10 additions and 15 deletions

View File

@ -59,11 +59,14 @@ public class IslandGrid {
* @return Island or null * @return Island or null
*/ */
public Island getIslandAt(int x, int z) { public Island getIslandAt(int x, int z) {
if (grid.contains(x, z)) { Table.Cell<Integer, Integer, Cell> tableCell = grid.cellSet()
Cell cell = grid.get(x, z); .stream()
if (cell.getState().equals(CellState.OCCUPIED)) { .filter(cell -> (cell.getValue().getState().equals(CellState.OCCUPIED)))
return (Island) cell.getObject(); .filter(cell -> ((Island) cell.getValue().getObject()).inIslandSpace(x, z))
} .findFirst().orElse(null);
if (tableCell != null) {
return (Island) tableCell.getValue().getObject();
} }
return null; return null;
} }
@ -93,7 +96,7 @@ public class IslandGrid {
* @author Poslovitch * @author Poslovitch
*/ */
private enum CellState { private enum CellState {
RESERVED, //RESERVED,
OCCUPIED OCCUPIED
} }
} }

View File

@ -61,8 +61,6 @@ public class IslandCacheTest {
IslandsManager im = mock(IslandsManager.class); IslandsManager im = mock(IslandsManager.class);
when(plugin.getIslands()).thenReturn(im); when(plugin.getIslands()).thenReturn(im);
island = mock(Island.class); island = mock(Island.class);
when(island.getWorld()).thenReturn(world); when(island.getWorld()).thenReturn(world);
location = mock(Location.class); location = mock(Location.class);
@ -197,14 +195,8 @@ public class IslandCacheTest {
assertNull(ic.getIslandAt(location2)); assertNull(ic.getIslandAt(location2));
} }
/*
@Test @Test
public void testGetIslands() { public void testGetMembers() {
fail("Not yet implemented"); // TODO
}
*/
@Test
public void testgetMembers() {
// New cache // New cache
IslandCache ic = new IslandCache(); IslandCache ic = new IslandCache();
ic.addIsland(island); ic.addIsland(island);