|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.ObjectballWorlds.framework.BallManagerWorld
public class BallManagerWorld
An BallManagerWorld provides a thread-safe implementation of BallManager, subject to the CAUTION below. It maintains the List of all Balls in its World.
The methods in this class that modify or iterate through this BallManager's List of Balls are synchronized. This prevents the ConcurrentModificationException that might arise if one Thread (e.g. the GUI Thread) adds or removes a Ball from the List of Balls while another Thread (e.g. the Thread that asks each Ball to "act") is iterating through the List of Balls.
CAUTION: Two methods return the List of Balls maintained by this BallManager:
| Constructor Summary | |
|---|---|
BallManagerWorld()
Initializes the list of Balls to an empty list. |
|
| Method Summary | |
|---|---|
void |
addBall(Ball ballToAdd)
Adds the given Ball to this World. |
List<Ball> |
allBallsInWorld()
Returns a List |
protected List<Ball> |
getBallsInWorld()
Returns the actual List |
Ball |
intersectingBall(Ball ballToCheckForIntersections)
Returns a Ball that intersects the given Ball, or null if no Ball intersects the given Ball. |
List<Ball> |
intersectingBalls(Ball ballToCheckForIntersections)
Returns a List |
Ball |
nearestBall(Point2D p)
Returns the Ball in this World that is nearest the given point. |
void |
removeBall(Ball ballToRemove)
Removes the given Ball from this World. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public BallManagerWorld()
universe - All the Worlds in the Universe| Method Detail |
|---|
public void addBall(Ball ballToAdd)
BallManager
addBall in interface BallManagerballToAdd - the Ball to add to this World.public void removeBall(Ball ballToRemove)
BallManager
removeBall in interface BallManagerballToRemove - the Ball to remove from this World.public Ball nearestBall(Point2D p)
BallManager
nearestBall in interface BallManagerp - the point for which to find the nearest Ball.
public Ball intersectingBall(Ball ballToCheckForIntersections)
BallManager
intersectingBall in interface BallManagerballToCheckForIntersections - Ball to check for intersection with other Balls.
public List<Ball> intersectingBalls(Ball ballToCheckForIntersections)
BallManager
Each call to this method returns a fresh List
intersectingBalls in interface BallManager
ballToCheckForIntersections - Ball to check for intersection with other Balls.
public List<Ball> allBallsInWorld()
BallManager
Each call to this method returns a fresh List
allBallsInWorld in interface BallManager
protected final List<Ball> getBallsInWorld()
CAUTION: Methods that call this method must be synchronized with this method (and the other methods of this class). Otherwise, the method that calls this method might experience the ConcurrentModificationException that would arise if one Thread (e.g. the GUI Thread) adds or removes a Ball from the List of Balls while the Thread of the method calling this method is iterating through that same List of Balls returned by this method.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||