jezuch.utils.starmapper2
Class StarsMap

java.lang.Object
  |
  +--jezuch.utils.starmapper2.StarsMap
All Implemented Interfaces:
java.io.Serializable

public class StarsMap
extends java.lang.Object
implements java.io.Serializable

A class that encapsulates Stars! MAP file. It is a collection of Planets and Players. Map has also it's size calculated from postitions of all planets, and a name (called also "signature" or "prefix"). Map's name is immutable property and can be exposed as public final.

Since:
2.0
Version:
2.0
Author:
Krzysztof Sobolewski
See Also:
Planet, Player, Serialized Form

Nested Class Summary
 class StarsMap.DefaultStarsPlaReader
          A default implementation of StarsPlaReader that reads PlanetInfos from reports generated by Stars!.
 class StarsMap.StarsPla
          A class that encapsulates a Stars!
 
Field Summary
 java.lang.String name
          Map's name.
 
Constructor Summary
StarsMap(java.lang.String name)
          Creates a map with a given name.
 
Method Summary
 Planet addPlanet(Planet planet)
          Adds a Planet to list of planets in this map.
 int addPlayer(Player player)
          Adds a Player to this map in a first free slot.
 Player addPlayer(Player player, int number)
          Adds Player in specified player slot in this map.
 boolean containsPlanet(Planet planet)
           
 boolean containsPlayer(Player player)
           
 boolean equals(java.lang.Object o)
          Checks if this map is equal to another map; the comparison is done by identity check, so map is equal only to itself.
 java.awt.Rectangle getBounds()
           
 Planet getPlanet(java.lang.String name)
           
 int getPlanetCount()
           
 Player getPlayer(int number)
           
 Player getPlayer(java.lang.String name)
           
 Planet removePlanet(java.lang.String name)
          Removes planet with a given name from this map.
 Player removePlayer(int number)
          Removes a player from a given player slot.
 Player removePlayer(Player player)
          Removes a given player from this map.
 Player removePlayer(java.lang.String name)
          Removes first player with given name from this map.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

name

public final java.lang.String name
Map's name. Can't be changed after creation.

Constructor Detail

StarsMap

public StarsMap(java.lang.String name)
Creates a map with a given name.

Parameters:
name - map's name
Method Detail

addPlanet

public Planet addPlanet(Planet planet)
Adds a Planet to list of planets in this map.

Parameters:
planet - the planet to be added
Returns:
Planet of the same name that was previously in this map, or null if there was no such planet; it guarantees that planets have unique names

addPlayer

public int addPlayer(Player player)
Adds a Player to this map in a first free slot.

Parameters:
player - the Player to be added
Returns:
int number of slot that this player was placed in

addPlayer

public Player addPlayer(Player player,
                        int number)
Adds Player in specified player slot in this map.

Parameters:
player - the Player to be added
number - number of slot
Returns:
Player that was previously in the specified slot or null if there was noone

containsPlanet

public boolean containsPlanet(Planet planet)
Parameters:
planet - planet to be checked
Returns:
true if the planet has been found in this map, false otherwise

containsPlayer

public boolean containsPlayer(Player player)
Parameters:
player - Player to check
Returns:
true if this Player was found in this map, false otherwise

equals

public boolean equals(java.lang.Object o)
Checks if this map is equal to another map; the comparison is done by identity check, so map is equal only to itself.

Overrides:
equals in class java.lang.Object
See Also:
Object.equals(Object)

getBounds

public java.awt.Rectangle getBounds()
Returns:
this map's bounds as Rectangle

getPlanet

public Planet getPlanet(java.lang.String name)
Parameters:
name - planet's name
Returns:
a Planet with a given name from this map

getPlanetCount

public int getPlanetCount()
Returns:
number of planets in this map

getPlayer

public Player getPlayer(int number)
Parameters:
number - number of player slot
Returns:
Player found in the player slot with specified number

getPlayer

public Player getPlayer(java.lang.String name)
Parameters:
name - Player's name
Returns:
first Player with a given name found in this map

removePlanet

public Planet removePlanet(java.lang.String name)
Removes planet with a given name from this map.

Parameters:
name - planet's name
Returns:
the removed Planet or null if planet with the name was not found

removePlayer

public Player removePlayer(int number)
Removes a player from a given player slot.

Parameters:
number - number of slot
Returns:
Player removed or null if slot was empty

removePlayer

public Player removePlayer(Player player)
Removes a given player from this map.

Parameters:
player - Player to be removed
Returns:
Player removed or null if it was not found

removePlayer

public Player removePlayer(java.lang.String name)
Removes first player with given name from this map.

Parameters:
name - name of the player to be removed
Returns:
Player removed or null if it was not found