Now that I think of it the default case is the null case.

This commit is contained in:
Olof Larsson 2013-04-19 18:58:34 +02:00
parent e8e8de834b
commit dc15ec2d6c
3 changed files with 12 additions and 94 deletions

View File

@ -8,7 +8,7 @@ public class Money
// MIXIN // MIXIN
// -------------------------------------------- // // -------------------------------------------- //
private static MoneyMixin mixin = MoneyMixinDefault.get(); private static MoneyMixin mixin = null;
public static MoneyMixin mixin() { return mixin; }; public static MoneyMixin mixin() { return mixin; };
public static void mixin(MoneyMixin newMixin) { mixin = newMixin; } public static void mixin(MoneyMixin newMixin) { mixin = newMixin; }
@ -36,6 +36,7 @@ public class Money
public static boolean enabled(Object universe) public static boolean enabled(Object universe)
{ {
if (mixin == null) return false;
return mixin.enabled(universe(universe)); return mixin.enabled(universe(universe));
} }
@ -50,16 +51,19 @@ public class Money
public static String format(Object universe, double amount) public static String format(Object universe, double amount)
{ {
if (disabled(universe)) return String.valueOf(amount);
return mixin.format(universe(universe), amount); return mixin.format(universe(universe), amount);
} }
public static String singular(Object universe) public static String singular(Object universe)
{ {
if (disabled(universe)) return "singular";
return mixin.singular(universe(universe)); return mixin.singular(universe(universe));
} }
public static String plural(Object universe) public static String plural(Object universe)
{ {
if (disabled(universe)) return "plural";
return mixin.plural(universe(universe)); return mixin.plural(universe(universe));
} }
@ -69,11 +73,13 @@ public class Money
public static boolean exists(Object universe, Object accountId) public static boolean exists(Object universe, Object accountId)
{ {
if (disabled(universe)) return false;
return mixin.exists(universe(universe), accountId(accountId)); return mixin.exists(universe(universe), accountId(accountId));
} }
public static boolean create(Object universe, Object accountId) public static boolean create(Object universe, Object accountId)
{ {
if (disabled(universe)) return false;
return mixin.create(universe(universe), accountId(accountId)); return mixin.create(universe(universe), accountId(accountId));
} }
@ -83,11 +89,13 @@ public class Money
public static double get(Object universe, Object accountId) public static double get(Object universe, Object accountId)
{ {
if (disabled(universe)) return 0D;
return mixin.get(universe(universe), accountId(accountId)); return mixin.get(universe(universe), accountId(accountId));
} }
public static boolean set(Object universe, Object accountId, double amount) public static boolean set(Object universe, Object accountId, double amount)
{ {
if (disabled(universe)) return false;
return mixin.set(universe(universe), accountId(accountId), amount); return mixin.set(universe(universe), accountId(accountId), amount);
} }
@ -97,11 +105,13 @@ public class Money
public static boolean add(Object universe, Object accountId, double amount) public static boolean add(Object universe, Object accountId, double amount)
{ {
if (disabled(universe)) return false;
return mixin.add(universe(universe), accountId(accountId), amount); return mixin.add(universe(universe), accountId(accountId), amount);
} }
public static boolean subtract(Object universe, Object accountId, double amount) public static boolean subtract(Object universe, Object accountId, double amount)
{ {
if (disabled(universe)) return false;
return mixin.subtract(universe(universe), accountId(accountId), amount); return mixin.subtract(universe(universe), accountId(accountId), amount);
} }

View File

@ -1,92 +0,0 @@
package com.massivecraft.mcore.money;
public class MoneyMixinDefault extends MoneyMixinAbstract
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static final MoneyMixinDefault i = new MoneyMixinDefault();
public static MoneyMixinDefault get() { return i; }
// -------------------------------------------- //
// ENABLED AND DISABLED
// -------------------------------------------- //
@Override
public boolean enabled(String universe)
{
return false;
}
// -------------------------------------------- //
// FORMAT AND NAME
// -------------------------------------------- //
@Override
public String format(String universe, double amount)
{
return String.valueOf(amount);
}
@Override
public String singular(String universe)
{
return "singular";
}
@Override
public String plural(String universe)
{
return "plural";
}
// -------------------------------------------- //
// EXISTS AND CREATE
// -------------------------------------------- //
@Override
public boolean exists(String universe, String accountId)
{
return false;
}
@Override
public boolean create(String universe, String accountId)
{
return false;
}
// -------------------------------------------- //
// GET AND SET
// -------------------------------------------- //
@Override
public double get(String universe, String accountId)
{
return 0D;
}
@Override
public boolean set(String universe, String accountId, double amount)
{
return false;
}
// -------------------------------------------- //
// MODIFY
// -------------------------------------------- //
@Override
public boolean add(String universe, String accountId, double amount)
{
return false;
}
@Override
public boolean subtract(String universe, String accountId, double amount)
{
return false;
}
}

View File

@ -29,7 +29,7 @@ public class MoneyMixinVault extends MoneyMixinAbstract
public void deactivate() public void deactivate()
{ {
Money.mixin(MoneyMixinDefault.get()); Money.mixin(null);
} }
// -------------------------------------------- // // -------------------------------------------- //