You're looking for a Map
.
public static Map<String, List<Waypoint>> wayPoints = new HashMap<String, List<Waypoint>>();
Although, a better approach would be to make your own ShipType
class and store a list of waypoints on the ship itself. More than likely, you'll have many more properties which are specific to one ship type. This allows you to consolidate those in a single class, making for a much more manageable design.
public class ShipType {
private List<Waypoint> wayPoints = new ArrayList<Waypoint>();
/* ... */
}
Your Ship
s could then have a ShipType
instead of "just" the name of their ship type.
public class Ship {
private ShipType type;
/* ... */
}
Then, simply keep a Map
of your ShipType
s to properly construct your Ship
s.
public static Map<String, ShipType> ships = new HashMap<String, ShipType>();
// Register ship types
ships.put("wood", new WoodShipType());
// Construct a ship
Ship myShip = new Ship();
myShip.setType(ships.get("wood"));
Alternatively, you can use an enum
with overloaded methods to represent a fixed number of ship types and get rid of that static
collection altogether.