Update of /cvsroot/neuclear/neuclear-bet/src/java/org/neuclear/bet/games
In directory sc8-pr-cvs1:/tmp/cvs-serv10206/src/java/org/neuclear/bet/games
Modified Files:
AbstractGame.java AbstractGameEvent.java
AbstractGameOutcome.java FixedGame.java
Log Message:
EncryptedFileStore now works. It uses the PBECipher with DES3 afair.
Otherwise You will Finaliate.
Anything that can be final has been made final throughout everyting. We've used IDEA's Inspector tool to find all instance of variables that could be final.
This should hopefully make everything more stable (and secure).
Index: AbstractGame.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-bet/src/java/org/neuclear/bet/games/AbstractGame.java,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** AbstractGame.java 20 Sep 2003 23:19:21 -0000 1.1.1.1
--- AbstractGame.java 21 Nov 2003 04:42:45 -0000 1.2
***************
*** 17,21 ****
*/
public class AbstractGame extends AbstractResultPropagator implements EventSource {
! public AbstractGame(EventFactory factory) {
this.listeners = new LinkedList();
this.factory = factory;
--- 17,21 ----
*/
public class AbstractGame extends AbstractResultPropagator implements EventSource {
! public AbstractGame(final EventFactory factory) {
this.listeners = new LinkedList();
this.factory = factory;
***************
*** 24,57 ****
}
! public void buildEvents() {
! BettingEvent event = factory.createEvent(this);
getClockDaemon().executeAt(event.getClosingTime(), (Runnable) event);
spewEvent(event);
}
! protected void spewEvent(BettingEvent event) {
! Iterator iter = listeners.iterator();
while (iter.hasNext()) {
! NewEventListener listener = (NewEventListener) iter.next();
listener.addEvent(event);
}
}
! public void addNewEventListener(NewEventListener listener) {
listeners.add(listener);
}
! protected ClockDaemon getClockDaemon() {
return clockd;
}
! protected Random getRandom() {
return random;
}
! private ClockDaemon clockd;
! private List listeners;
! private EventFactory factory;
! private SecureRandom random;
}
--- 24,57 ----
}
! public final void buildEvents() {
! final BettingEvent event = factory.createEvent(this);
getClockDaemon().executeAt(event.getClosingTime(), (Runnable) event);
spewEvent(event);
}
! protected final void spewEvent(final BettingEvent event) {
! final Iterator iter = listeners.iterator();
while (iter.hasNext()) {
! final NewEventListener listener = (NewEventListener) iter.next();
listener.addEvent(event);
}
}
! public final void addNewEventListener(final NewEventListener listener) {
listeners.add(listener);
}
! protected final ClockDaemon getClockDaemon() {
return clockd;
}
! protected final Random getRandom() {
return random;
}
! private final ClockDaemon clockd;
! private final List listeners;
! private final EventFactory factory;
! private final SecureRandom random;
}
Index: AbstractGameEvent.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-bet/src/java/org/neuclear/bet/games/AbstractGameEvent.java,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** AbstractGameEvent.java 20 Sep 2003 23:19:21 -0000 1.1.1.1
--- AbstractGameEvent.java 21 Nov 2003 04:42:45 -0000 1.2
***************
*** 16,20 ****
*/
public class AbstractGameEvent implements Runnable, BettingEvent {
! public AbstractGameEvent(ResultListener result, String id, String title, Date close) {
this.title = title;
this.result = result;
--- 16,20 ----
*/
public class AbstractGameEvent implements Runnable, BettingEvent {
! public AbstractGameEvent(final ResultListener result, final String id, final String title, final Date close) {
this.title = title;
this.result = result;
***************
*** 23,58 ****
}
! public void addOutcome(String id, String title) {
outcomes.add(new AbstractGameOutcome(this, getId() + "/" + id, title));
}
! public Iterator listOutcomes() {
return outcomes.iterator();
}
! public boolean hasOutcome(EventOutcome outcome) {
return outcomes.contains(outcome);
}
! public boolean hasOutcome(String outcome) {
return outcomes.contains(outcome);
}
! public String getId() {
return id;
}
! public String getTitle() {
return title;
}
! public Date getClosingTime() {
return close;
}
! public void run() {
System.out.print("Race Started for: " + getClosingTime() + " ... ");
! EventOutcome winner = pickWinner();
System.out.println("Sending results");
try {
--- 23,58 ----
}
! public final void addOutcome(final String id, final String title) {
outcomes.add(new AbstractGameOutcome(this, getId() + "/" + id, title));
}
! public final Iterator listOutcomes() {
return outcomes.iterator();
}
! public final boolean hasOutcome(final EventOutcome outcome) {
return outcomes.contains(outcome);
}
! public final boolean hasOutcome(final String outcome) {
return outcomes.contains(outcome);
}
! public final String getId() {
return id;
}
! public final String getTitle() {
return title;
}
! public final Date getClosingTime() {
return close;
}
! public final void run() {
System.out.print("Race Started for: " + getClosingTime() + " ... ");
! final EventOutcome winner = pickWinner();
System.out.println("Sending results");
try {
***************
*** 68,85 ****
* @param outcome
*/
! public void scratch(EventOutcome outcome) {
outcomes.remove(outcome);
}
public EventOutcome pickWinner() {
! Iterator iter = listOutcomes();
int amount = 0;
! ArrayList outcomes = new ArrayList();
while (iter.hasNext()) {
! EventOutcome outcome = (EventOutcome) iter.next();
amount++;
outcomes.add(outcome);
}
! Random rand = new SecureRandom();
winner = (EventOutcome) outcomes.get(rand.nextInt(amount));
SEED = rand.nextLong();
--- 68,85 ----
* @param outcome
*/
! public final void scratch(final EventOutcome outcome) {
outcomes.remove(outcome);
}
public EventOutcome pickWinner() {
! final Iterator iter = listOutcomes();
int amount = 0;
! final ArrayList outcomes = new ArrayList();
while (iter.hasNext()) {
! final EventOutcome outcome = (EventOutcome) iter.next();
amount++;
outcomes.add(outcome);
}
! final Random rand = new SecureRandom();
winner = (EventOutcome) outcomes.get(rand.nextInt(amount));
SEED = rand.nextLong();
***************
*** 87,110 ****
}
! public boolean isClosed() {
return close.before(new Date());
}
! public boolean isFinished() {
return winner != null;
}
! public EventOutcome getWinner() {
return winner;
}
public static long SEED = 1231423425;
! ResultListener result;
! private Set outcomes;
! private String title;
private String id;
! private Date close;
private EventOutcome winner;
--- 87,110 ----
}
! public final boolean isClosed() {
return close.before(new Date());
}
! public final boolean isFinished() {
return winner != null;
}
! public final EventOutcome getWinner() {
return winner;
}
public static long SEED = 1231423425;
! final ResultListener result;
! private final Set outcomes;
! private final String title;
private String id;
! private final Date close;
private EventOutcome winner;
Index: AbstractGameOutcome.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-bet/src/java/org/neuclear/bet/games/AbstractGameOutcome.java,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** AbstractGameOutcome.java 20 Sep 2003 23:19:21 -0000 1.1.1.1
--- AbstractGameOutcome.java 21 Nov 2003 04:42:45 -0000 1.2
***************
*** 11,15 ****
*/
public class AbstractGameOutcome implements EventOutcome {
! public AbstractGameOutcome(BettingEvent event, String id, String title) {
this.id = id;
this.title = title;
--- 11,15 ----
*/
public class AbstractGameOutcome implements EventOutcome {
! public AbstractGameOutcome(final BettingEvent event, final String id, final String title) {
this.id = id;
this.title = title;
***************
*** 18,26 ****
! public int hashCode() {
return getId().hashCode(); //To change body of overriden methods use Options | File Templates.
}
! public boolean equals(Object object) {
if (object instanceof EventOutcome)
return ((EventOutcome) object).getId().equals(getId()) && (((BettingEvent) getEvent()).equals(((EventOutcome) object).getEvent()));
--- 18,26 ----
! public final int hashCode() {
return getId().hashCode(); //To change body of overriden methods use Options | File Templates.
}
! public final boolean equals(final Object object) {
if (object instanceof EventOutcome)
return ((EventOutcome) object).getId().equals(getId()) && (((BettingEvent) getEvent()).equals(((EventOutcome) object).getEvent()));
***************
*** 28,45 ****
}
! public String getId() {
return id;
}
! public BettingEvent getEvent() {
return event;
}
! public String getTitle() {
return title; //To change body of implemented methods use Options | File Templates.
}
! private String id;
! private String title;
! private BettingEvent event;
}
--- 28,45 ----
}
! public final String getId() {
return id;
}
! public final BettingEvent getEvent() {
return event;
}
! public final String getTitle() {
return title; //To change body of implemented methods use Options | File Templates.
}
! private final String id;
! private final String title;
! private final BettingEvent event;
}
Index: FixedGame.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-bet/src/java/org/neuclear/bet/games/FixedGame.java,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** FixedGame.java 20 Sep 2003 23:19:21 -0000 1.1.1.1
--- FixedGame.java 21 Nov 2003 04:42:45 -0000 1.2
***************
*** 13,25 ****
* Time: 5:49:38 PM
*/
! public class FixedGame extends AbstractGameEvent {
! public FixedGame(ResultListener results, String id, String name) {
super(results, id, name, new Date(new Date().getTime() + DELAY));
}
! public EventOutcome pickWinner() {
! Iterator iter = listOutcomes();
while (iter.hasNext()) {
! EventOutcome outcome = (EventOutcome) iter.next();
if (outcome.getId().equals("red"))
return outcome;
--- 13,25 ----
* Time: 5:49:38 PM
*/
! public final class FixedGame extends AbstractGameEvent {
! public FixedGame(final ResultListener results, final String id, final String name) {
super(results, id, name, new Date(new Date().getTime() + DELAY));
}
! public final EventOutcome pickWinner() {
! final Iterator iter = listOutcomes();
while (iter.hasNext()) {
! final EventOutcome outcome = (EventOutcome) iter.next();
if (outcome.getId().equals("red"))
return outcome;
|