gishur.core
Class Sweep

java.lang.Object
  |
  +--gishur.core.Sweep
All Implemented Interfaces:
java.util.EventListener, SweepListener
Direct Known Subclasses:
PolygonIntersectionSweep, SegmentIntersectionSweep

public class Sweep
extends java.lang.Object
implements SweepListener

The basic class for sweep algorithms. Each instance holds an event- and a status-structure. To implement a certain sweep algorithm it is recommended to derive a new class from this one and to override its processEvent(gishur.core.SweepEvent) -method. After the creation of an event-structure and a status-structure, SweepEvents can be generated and the algorithm can be started with execute(). As an alternative, a SweepListener can be defined with setSweepListener(gishur.core.SweepListener) which is then responsible for the processing of any events, instead of overriding the processEvent(gishur.core.SweepEvent)-method. In opposite to GUI-events, SweepEvents can be processed only once (as there is only one status-structure). That means that either the overridden processEvent(gishur.core.SweepEvent)-method or the processEvent(gishur.core.SweepEvent) -method of one SweepListener will be called. Before a sweep algorithm can be started with execute(), an event-structure must have been created with createEventStructure(gishur.core.Comparitor, boolean) and a status-structure including a matching Comparitor as well with createSSS(gishur.core.Comparitor, boolean). Besides, events must be added using insertEvent(int, java.lang.Object, java.lang.Object) which can start the sweep. The status-structure is a balanced BinarySearchTree and can thus be manipulated with tree methods.

Version:
1.0
Author:
Thomas Wolf
See Also:
SweepEvent

Constructor Summary
Sweep()
          Empty constructor.
Sweep(SweepListener sweep)
          Creates a Sweep-object and defines sweep as its SweepListener.
 
Method Summary
 void createEventStructure(Comparitor comparitor)
          Creates a new event-structure with Comparitor comparitor.
 void createEventStructure(Comparitor comparitor, boolean smallfirst)
          Creates a new event-structure with Comparitor comparitor.
 void createSSS(Comparitor comparitor)
          Creates a new status-structure which will be ordered by comparitor
 void createSSS(Comparitor comparitor, boolean smallfirst)
          Creates a new status-structure which will be ordered by comparitor in the order defined by smallfirst.
 void execute()
          Starts the execution of the Sweep.
 void insertEvent(int id, java.lang.Object key, java.lang.Object value)
          Inserts an event into the event-structure.
 void processEvent(SweepEvent e)
          Processes SweepEvent e.
 void setSweepListener(SweepListener sweep)
          Sets the SweepListener of this Sweep to sweep.
 BinarySearchTree sss()
          Returns the status-structure.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Sweep

public Sweep()
Empty constructor.

Sweep

public Sweep(SweepListener sweep)
Creates a Sweep-object and defines sweep as its SweepListener.
Parameters:
sweep - new SweepListener
Method Detail

setSweepListener

public void setSweepListener(SweepListener sweep)
Sets the SweepListener of this Sweep to sweep. That means that sweep's processEvent(gishur.core.SweepEvent)-method will be called when execution starts instead of this' processEvent(gishur.core.SweepEvent)-routine.
Parameters:
sweep - new SweepListener

execute

public final void execute()
Starts the execution of the Sweep. An event-structure must have been defined before! All events in the event-structure will be processed after each other calling processEvent(gishur.core.SweepEvent). While this process is in work, new events can be added to the structure. execute() ends when the last event stored

processEvent

public void processEvent(SweepEvent e)
Processes SweepEvent e.
Specified by:
processEvent in interface SweepListener
Parameters:
e - a SweepEvent

createEventStructure

public void createEventStructure(Comparitor comparitor,
                                 boolean smallfirst)
Creates a new event-structure with Comparitor comparitor. Besides, the chronological order of procession is defined by smallfirst.
Parameters:
comparitor - a Comparitor providing order to the event-structure
smallfirst - if true, 'smaller' events (due to comparitor!) will be processed before bigger ones, otherwise after them

createEventStructure

public void createEventStructure(Comparitor comparitor)
Creates a new event-structure with Comparitor comparitor.
Parameters:
comparitor - a Comparitor providing order to the event-structure

insertEvent

public void insertEvent(int id,
                        java.lang.Object key,
                        java.lang.Object value)
Inserts an event into the event-structure. The operation takes O(log n) -time, where n is the number of already inserted events.
Parameters:
id - the event-id
key - the key which defines the position of this event inside the event-structure (by being compared to the other events' keys by the structure's Comparitor)
value - the value which shall be stored for the event

createSSS

public void createSSS(Comparitor comparitor,
                      boolean smallfirst)
Creates a new status-structure which will be ordered by comparitor in the order defined by smallfirst.
Parameters:
comparitor - a Comparitor defining an order on the new structure
smallfirst - if true smaller objects will be stored first, otherwise vice versa

createSSS

public void createSSS(Comparitor comparitor)
Creates a new status-structure which will be ordered by comparitor
Parameters:
comparitor - a Comparitor defining an order on the new structure

sss

public BinarySearchTree sss()
Returns the status-structure. Insertion, search and deletion of elements take O(log n)-time where n is the number of elements stored in the structure.
Returns:
this Sweep's status-structure as a RedBlackTree