/** recursively renders a network of spaces */ protected void renderNetworkRecursive( Graphics g, AbstractCollection<Tile> finished, Tile origin, int x, int y, Color hilight) { int dummyHeight = 0; if (x >= 0 && x < boardWidth && y >= 0 && y < boardHeight) { dummyHeight = spaceHeights[x][y]; } renderSpace(g, origin, dummyHeight, x, y); g.setColor(hilight); g.fillRect((x + 1) * TILE_WIDTH, (y + 1) * TILE_HEIGHT, TILE_WIDTH, TILE_HEIGHT); if (x >= 0 && x < boardWidth && y >= 0 && y < boardHeight) { renderText( g, Integer.toString(spaceHeights[x][y]), (x + 1) * TILE_WIDTH, (y + 1) * TILE_HEIGHT + g.getFont().getSize()); } if (origin.getJoined(Grid.LEFT) != null && !finished.contains(origin.getJoined(Grid.LEFT))) { finished.add(origin.getJoined(Grid.LEFT)); renderNetworkRecursive(g, finished, origin.getJoined(Grid.LEFT), x - 1, y, hilight); } if (origin.getJoined(Grid.RIGHT) != null && !finished.contains(origin.getJoined(Grid.RIGHT))) { finished.add(origin.getJoined(Grid.RIGHT)); renderNetworkRecursive(g, finished, origin.getJoined(Grid.RIGHT), x + 1, y, hilight); } if (origin.getJoined(Grid.TOP) != null && !finished.contains(origin.getJoined(Grid.TOP))) { finished.add(origin.getJoined(Grid.TOP)); renderNetworkRecursive(g, finished, origin.getJoined(Grid.TOP), x, y - 1, hilight); } if (origin.getJoined(Grid.BOTTOM) != null && !finished.contains(origin.getJoined(Grid.BOTTOM))) { finished.add(origin.getJoined(Grid.BOTTOM)); renderNetworkRecursive(g, finished, origin.getJoined(Grid.BOTTOM), x, y + 1, hilight); } }
/** * A specialized mapcar that operates on stacks * * @param coll Stack * @param fn Function * @param <T> Type * @return Returns a AbstractCollection<T> which is the result of operating fn on every element of * coll */ static <T> AbstractCollection<T> mapcar(Stack<T> coll, Function<T> fn) { AbstractCollection<T> list = new Stack<>(); for (T t : coll) { list.add(fn.operate(t)); } return list; }
public Alphabet[] getAlphabets() { AbstractCollection<Alphabet> alphs = new ArrayList<Alphabet>(); for (FormalDefinitionComponent comp : this.getComponents()) { if (comp instanceof Alphabet) { alphs.add((Alphabet) comp); } } return alphs.toArray(new Alphabet[0]); }
private long testingAbstractCollectionLinkedBlockingDeque() { AbstractCollection<Object> array = new LinkedBlockingDeque<Object>(); long start = System.currentTimeMillis(); for (int i = 0; i < getMax(); i++) { array.add(i); } long end = System.currentTimeMillis(); long time = (end - start); refreshTotalTime(time); return time; }