ppJava.serie04.oceanlife
Class Ocean

java.lang.Object
  extended by ppJava.serie04.oceanlife.Ocean
All Implemented Interfaces:
OceanInterface

public class Ocean
extends java.lang.Object
implements OceanInterface

Ocean: Management of a LinkedList of OceanObjects

See Also:
OceanInterface

Field Summary
private  int depth
           
private static java.util.logging.Logger logger
           
private  java.util.LinkedList<OceanObject> oceanObjects
           
private  int width
           
 
Constructor Summary
Ocean(int width, int depth, java.util.LinkedList<OceanObject> oceanObjects)
          Constructor for an ocean with bounds and a already defined linked list of oceanObjects which can be null
 
Method Summary
 void addOceanObject(OceanObject oceanObject)
          Appends an oceanObject to the list
 int calcAbsDistance(int[] pos1, int[] pos2)
           
 void clearObjectList()
          clears the linked list of oceanObjects
 boolean emptyOcean()
           
 int getDepth()
          Returns depth of ocean in pixels
 java.util.LinkedList<OceanObject> getOceanObjects()
          Returns a linked list of all OceanObjects
 int getWidth()
          Returns depth of ocean in pixels
 int indexOfNearestObject(int[] position)
          Compute the next item to a specific position
 OceanInterface loadOcean(java.lang.String filename)
          Reads and deserialize an objectStream from file
 void removeOceanObject(int index)
          Removes an oceanObject at a specific position (index)
 void saveOcean(java.lang.String filename)
          Serialize and write all oceanObjects to a file
 void setDepth(int depth)
          Set the depth of ocean
 void setOceanObjects(java.util.LinkedList<OceanObject> oceanObjects)
          Sets a list of OceanObjects
 void setWidth(int width)
          Set the width of ocean
 java.lang.String toString()
          Returns a readable output
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

logger

private static java.util.logging.Logger logger

width

private int width

depth

private int depth

oceanObjects

private java.util.LinkedList<OceanObject> oceanObjects
Constructor Detail

Ocean

public Ocean(int width,
             int depth,
             java.util.LinkedList<OceanObject> oceanObjects)
      throws OceanException
Constructor for an ocean with bounds and a already defined linked list of oceanObjects which can be null

Parameters:
width -
depth -
oceanObjects - - a list of OceanObjects
Throws:
OceanException - - i.e. invalid list
Method Detail

emptyOcean

public boolean emptyOcean()
Returns:
true if ocean is empty

getOceanObjects

public java.util.LinkedList<OceanObject> getOceanObjects()
Description copied from interface: OceanInterface
Returns a linked list of all OceanObjects

Specified by:
getOceanObjects in interface OceanInterface
Returns:
a linked list of all OceanObjects (null if empty)

getDepth

public int getDepth()
Description copied from interface: OceanInterface
Returns depth of ocean in pixels

Specified by:
getDepth in interface OceanInterface
Returns:
depth of ocean in pixels

getWidth

public int getWidth()
Description copied from interface: OceanInterface
Returns depth of ocean in pixels

Specified by:
getWidth in interface OceanInterface
Returns:
width of ocean in pixels

setDepth

public void setDepth(int depth)
Description copied from interface: OceanInterface
Set the depth of ocean

Specified by:
setDepth in interface OceanInterface

setWidth

public void setWidth(int width)
              throws OceanException
Description copied from interface: OceanInterface
Set the width of ocean

Specified by:
setWidth in interface OceanInterface
Throws:
OceanException - - if width is invalid

clearObjectList

public void clearObjectList()
clears the linked list of oceanObjects

See Also:
LinkedList

setOceanObjects

public void setOceanObjects(java.util.LinkedList<OceanObject> oceanObjects)
Description copied from interface: OceanInterface
Sets a list of OceanObjects

Specified by:
setOceanObjects in interface OceanInterface

addOceanObject

public void addOceanObject(OceanObject oceanObject)
                    throws OceanException
Description copied from interface: OceanInterface
Appends an oceanObject to the list

Specified by:
addOceanObject in interface OceanInterface
Throws:
OceanException - - if data of oceanObject is invalid (i.e. position)

calcAbsDistance

public int calcAbsDistance(int[] pos1,
                           int[] pos2)

indexOfNearestObject

public int indexOfNearestObject(int[] position)
                         throws OceanException
Description copied from interface: OceanInterface
Compute the next item to a specific position

Specified by:
indexOfNearestObject in interface OceanInterface
Returns:
the id of next oceanObject to the given position
Throws:
OceanException

removeOceanObject

public void removeOceanObject(int index)
                       throws java.lang.IllegalArgumentException
Description copied from interface: OceanInterface
Removes an oceanObject at a specific position (index)

Specified by:
removeOceanObject in interface OceanInterface
Throws:
java.lang.IllegalArgumentException

loadOcean

public OceanInterface loadOcean(java.lang.String filename)
                         throws java.lang.ClassNotFoundException,
                                java.io.IOException
Description copied from interface: OceanInterface
Reads and deserialize an objectStream from file

Specified by:
loadOcean in interface OceanInterface
Returns:
ocean with objectlist
Throws:
java.lang.ClassNotFoundException
java.io.IOException

saveOcean

public void saveOcean(java.lang.String filename)
               throws java.io.IOException
Description copied from interface: OceanInterface
Serialize and write all oceanObjects to a file

Specified by:
saveOcean in interface OceanInterface
Throws:
java.io.IOException

toString

public java.lang.String toString()
Description copied from interface: OceanInterface
Returns a readable output

Specified by:
toString in interface OceanInterface
Overrides:
toString in class java.lang.Object
Returns:
a readable output of the ocean and its list