fi.utu.cs.physics
Class Universe.CollisionNotification

java.lang.Object
  |
  +--fi.utu.cs.physics.Universe.CollisionNotification
Enclosing class:
Universe

public class Universe.CollisionNotification
extends java.lang.Object

Comprises a Body object and a Particle object that have been the counterparts in a collision. The Universe class, which is inherited from Observable, submits an instance of this class to its observers. The notification is sent if and only if (1) a body and a particle collide, and (2) either the body or the particle wants its collisions to be notified.

See Also:
Particle.addCollisionNotification(Class), Observable.notifyObservers(Object), Observer.update(Observable,Object)

Field Summary
static int BOTH
          Both of the counterparts.
static int FIRST
          The first counterpart.
static int NONE
          None of the counterparts.
static int SECOND
          The second counterpart.
 
Constructor Summary
Universe.CollisionNotification(Body b1, Body b2)
          Creates a notification for the bodies b1 and b2
Universe.CollisionNotification(Body b, Particle p)
          Creates a notification for the body b and the particle p
 
Method Summary
 int counterpart(java.lang.Class t)
          Returns which of the counterparts is of the type t.
 Body getBody()
          Returns the body involved in the collision.
 Body getCounterpart(int i)
          Deprecated. As of version 1.1, replaced by getParticle(int).
 Particle getParticle()
          Returns the particle involved in the collision.
 Particle getParticle(int i)
          Returns the ith counterpart of the collision.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NONE

public static final int NONE
None of the counterparts.

See Also:
Constant Field Values

FIRST

public static final int FIRST
The first counterpart. Always an instance of the class Body.

See Also:
Constant Field Values

SECOND

public static final int SECOND
The second counterpart. Always an instance of the class Particle.

See Also:
Constant Field Values

BOTH

public static final int BOTH
Both of the counterparts.

See Also:
Constant Field Values
Constructor Detail

Universe.CollisionNotification

public Universe.CollisionNotification(Body b1,
                                      Body b2)
Creates a notification for the bodies b1 and b2


Universe.CollisionNotification

public Universe.CollisionNotification(Body b,
                                      Particle p)
Creates a notification for the body b and the particle p

Since:
1.1
Method Detail

getCounterpart

public Body getCounterpart(int i)
Deprecated. As of version 1.1, replaced by getParticle(int).

Returns the ith counterpart of the collision. Note: Throws a ClassCastException if i == SECOND and the second counterpart is not an instance of the class Body.


getBody

public Body getBody()
Returns the body involved in the collision.

Since:
1.1

getParticle

public Particle getParticle()
Returns the particle involved in the collision.

Since:
1.1

getParticle

public Particle getParticle(int i)
Returns the ith counterpart of the collision. Returns null, if i != FIRST and i != SECOND.

Since:
1.1
See Also:
FIRST, SECOND

counterpart

public int counterpart(java.lang.Class t)
Returns which of the counterparts is of the type t.

See Also:
NONE, FIRST, SECOND, BOTH