-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Revert "[Refactoring] Mediator pattern for ControlDesk.java""
This reverts commit 552b2d2.
- Loading branch information
Showing
5 changed files
with
190 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import java.io.IOException; | ||
|
||
public class BowlerRegistrationManager { | ||
private ControlDesk controlDesk; | ||
|
||
public BowlerRegistrationManager(ControlDesk controlDesk) { | ||
this.controlDesk = controlDesk; | ||
} | ||
|
||
/** | ||
* Retrieves a matching Bowler from the bowler database. | ||
* | ||
* @param nickName The NickName of the Bowler | ||
* | ||
* @return a Bowler object. | ||
* | ||
*/ | ||
|
||
public Bowler registerPatron(String nickName) { | ||
Bowler patron = null; | ||
|
||
try { | ||
// only one patron / nick.... no dupes, no checks | ||
|
||
patron = BowlerFile.getBowlerInfo(nickName); | ||
|
||
} catch (IOException e) { | ||
System.err.println("Error..." + e); | ||
} | ||
|
||
return patron; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import java.util.HashSet; | ||
import java.util.Iterator; | ||
|
||
public class LaneManager { | ||
private ControlDesk controlDesk; | ||
|
||
/** The collection of Lanes */ | ||
private HashSet<Lane> lanes; | ||
|
||
/** The number of lanes represented */ | ||
private int numLanes; | ||
|
||
public LaneManager(ControlDesk controlDesk, int numLanes) { | ||
this.controlDesk = controlDesk; | ||
this.lanes = new HashSet<>(numLanes); | ||
this.numLanes = numLanes; | ||
|
||
for (int i = 0; i < numLanes; i++) { | ||
lanes.add(new Lane()); | ||
} | ||
} | ||
|
||
/** | ||
* Iterate through the available lanes and assign the paties in the wait queue if lanes are available. | ||
* | ||
*/ | ||
|
||
public void assignLane() { | ||
Iterator<Lane> it = lanes.iterator(); | ||
|
||
while (it.hasNext() && controlDesk.getWaitQueue().hasMoreElements()) { | ||
Lane curLane = it.next(); | ||
|
||
if (!curLane.isPartyAssigned()) { | ||
System.out.println("ok... assigning this party"); | ||
curLane.assignParty(((Party) controlDesk.getWaitQueue().next())); | ||
} | ||
} | ||
controlDesk.publish(new PartyQueueEvent(controlDesk.getPartyQueue())); | ||
} | ||
|
||
/** | ||
* Accessor for the number of lanes represented by the ControlDesk | ||
* | ||
* @return an int containing the number of lanes represented | ||
* | ||
*/ | ||
|
||
public int getNumLanes() { | ||
return numLanes; | ||
} | ||
|
||
/** | ||
* Accessor method for lanes | ||
* | ||
* @return a HashSet of Lanes | ||
* | ||
*/ | ||
|
||
public HashSet<Lane> getLanes() { | ||
return lanes; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import java.util.Vector; | ||
|
||
public class PartyQueueManager { | ||
private ControlDesk controlDesk; | ||
|
||
/** The party wait queue */ | ||
private Queue partyQueue; | ||
|
||
public PartyQueueManager(ControlDesk controlDesk) { | ||
this.controlDesk = controlDesk; | ||
partyQueue = new Queue(); | ||
} | ||
|
||
/** | ||
* Creates a party from a Vector of nickNAmes and adds them to the wait queue. | ||
* | ||
* @param partyNicks A Vector of NickNames | ||
* | ||
*/ | ||
|
||
public void addPartyQueue(Vector<String> partyNicks) { | ||
Vector<Bowler> partyBowlers = new Vector<>(); | ||
for (String partyNick : partyNicks) { | ||
Bowler newBowler = controlDesk.registerBowler(partyNick); | ||
partyBowlers.add(newBowler); | ||
} | ||
Party newParty = new Party(partyBowlers); | ||
partyQueue.add(newParty); | ||
controlDesk.publish(new PartyQueueEvent(getPartyQueue())); | ||
} | ||
|
||
/** | ||
* Returns a Vector of party names to be displayed in the GUI representation of the wait queue. | ||
* | ||
* @return a Vecotr of Strings | ||
* | ||
*/ | ||
|
||
public Vector<String> getPartyQueue() { | ||
Vector<String> displayPartyQueue = new Vector<>(); | ||
for ( int i=0; i < ( partyQueue.asVector()).size(); i++ ) { | ||
String nextParty = | ||
((Bowler) ( ((Party) partyQueue.asVector().get( i ) ).getMembers()) | ||
.get(0)) | ||
.getNickName() + "'s Party"; | ||
displayPartyQueue.addElement(nextParty); | ||
} | ||
return displayPartyQueue; | ||
} | ||
|
||
public Queue getWaitQueue(){ | ||
return this.partyQueue; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
public class ScoreManager { | ||
private ControlDesk controlDesk; | ||
|
||
public ScoreManager(ControlDesk controlDesk) { | ||
this.controlDesk = controlDesk; | ||
} | ||
|
||
public void viewScores(Lane ln) { | ||
// TODO: attach a LaneScoreView object to that lane | ||
} | ||
} |