jenkins the definitive guide

(Jeff_L) #1
}
return cellRepresentedBySymbol;
}

public String getSymbol() {
return symbol;
}
}

The application can print the state of the grid as a text array. Currently, the application prints our live
cells as an asterisk (*), and dead cells appear as a minus character (–). So a five-by-five grid containing
a single living cell in the center would look like this:


-----
--*--
-----

Now users have asked for a change to the application—they want pluses (+) instead of stars! So we are
going to make a slight change to the Cell class method, and rewrite it as follows (the modifications
are in bold):


package com.wakaleo.gameoflife.domain;

public enum Cell {
LIVE_CELL("+"), DEAD_CELL(".");

private String symbol;

private Cell(String symbol) {
this.symbol = symbol;
}

@Override
public String toString() {
return symbol;
}

static Cell fromSymbol(String symbol) {
Cell cellRepresentedBySymbol = null;
for (Cell cell : Cell.values()) {
if (cell.symbol.equals(symbol)) {
cellRepresentedBySymbol = cell;
break;
}
}
return cellRepresentedBySymbol;
}

public String getSymbol() {
return symbol;
}
}
Free download pdf