jezuch.utils.starmapper2
Class Planet

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

public final class Planet
extends java.lang.Object
implements java.io.Serializable

Planet class is a struct-like immutable placeholder for planet name and its locaion in the Stars! map. All fields are exposed as public final. Planets are immutable, because once created, they should not move or change names. Planets, as immutable objects, can be safely used as Map keys.

Since:
2.0 (in public API)
Version:
2.0
Author:
Krzysztof Sobolewski
See Also:
Serialized Form

Field Summary
 java.lang.String name
          Planet's name
 int x
          Planet's horizontal location in the map
 int y
          Planet's vertical location in the map
 
Constructor Summary
Planet(java.lang.String name, int x, int y)
          Constructs a planet with given name and location.
 
Method Summary
 boolean equals(java.lang.Object o)
          Compares this planet to another object
 int hashCode()
          Generates Planet's hash code.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

name

public final java.lang.String name
Planet's name


x

public final int x
Planet's horizontal location in the map


y

public final int y
Planet's vertical location in the map

Constructor Detail

Planet

public Planet(java.lang.String name,
              int x,
              int y)
Constructs a planet with given name and location. Planet's location is defined in Stars! coordinates, which are not like screen coordinates, but like mathematical coords ((0, 0) is in lower-left corner and Y axis points up). Actually Stars! coords are always larger than 1000, but this constructor doesn't check this, planet's coords may be even negative and it will not complain.

Parameters:
name - planet's name
x - planet's x coordinate
y - planet's y coordinate
Throws:
java.lang.IllegalArgumentException - if planet's name is null or a null string
Method Detail

equals

public boolean equals(java.lang.Object o)
Compares this planet to another object

Overrides:
equals in class java.lang.Object
Returns:
true if the passed object is a planet with equal name and coordinates

hashCode

public int hashCode()
Generates Planet's hash code. I have no idea if it's the optimal hash code for planet ;)

Overrides:
hashCode in class java.lang.Object
Returns:
(x<<16)^(y<<8)^name.hashCode()