Name: Anonymous 2008-10-15 22:40
from time import sleep
sleep(2/0)
sleep(2/0)
public class TurnDiscriminator // Factory Pattern
{
private static java.util.HashMap storage = new java.util.HashMap() ;
private static int currentTurnKey = 0;
public static TurnSpecifier getTurnSpecifier()
{
TurnSpecifier value = (TurnSpecifier)storage.get(currentTurnKey) ;
if (value == null)
return ZeroTurn.value ;
if (currentTurnKey == 0)
currentTurnKey = 1 ;
else if (currentTurnKey == 1)
currentTurnKey = 0 ;
return value ;
}
public static void register(final String key, final TurnSpecifier value)
{
storage.put(key, value) ; // Should guard against null keys, actually.
}
static
{
ZeroTurn.register() ;
OneTurn.register() ;
}
}
public interface TurnSpecifier
{
int getTurn() ;
}
public class ZeroTurn implements TurnSpecifier // Singleton Pattern
{
public static final ZeroTurn value = new ZeroTurn () ;
private ZeroTurn() { }
public int getTurn()
{
return 0;
}
public static final void register()
{
TurnDiscriminator.register(0, value) ;
}
}
public class OneTurn implements TurnSpecifier // Singleton Pattern
{
public static final OneTurn value = new OneTurn () ;
private OneTurn() { }
public int getTurn()
{
return 1;
}
public static final void register()
{
TurnDiscriminator.register(1, value) ;
}
}