Fix some comments and indent style

This commit is contained in:
Olof Larsson 2013-04-20 15:50:50 +02:00
parent dc15ec2d6c
commit c24a9a63dc
8 changed files with 239 additions and 200 deletions

View File

@ -44,145 +44,145 @@ public class NaturalOrderComparator implements Comparator<Object>
// OVERRIDE // OVERRIDE
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public int compare(Object o1, Object o2) public int compare(Object o1, Object o2)
{ {
String a = o1.toString(); String a = o1.toString();
String b = o2.toString(); String b = o2.toString();
int ia = 0, ib = 0; int ia = 0, ib = 0;
int nza = 0, nzb = 0; int nza = 0, nzb = 0;
char ca, cb; char ca, cb;
int result; int result;
while (true) while (true)
{ {
// only count the number of zeroes leading the last number compared // only count the number of zeroes leading the last number compared
nza = nzb = 0; nza = nzb = 0;
ca = charAt(a, ia); ca = charAt(a, ia);
cb = charAt(b, ib); cb = charAt(b, ib);
// skip over leading spaces or zeros // skip over leading spaces or zeros
while (Character.isSpaceChar(ca) || ca == '0') while (Character.isSpaceChar(ca) || ca == '0')
{ {
if (ca == '0') if (ca == '0')
{ {
nza++; nza++;
} }
else else
{ {
// only count consecutive zeroes // only count consecutive zeroes
nza = 0; nza = 0;
} }
ca = charAt(a, ++ia); ca = charAt(a, ++ia);
} }
while (Character.isSpaceChar(cb) || cb == '0') while (Character.isSpaceChar(cb) || cb == '0')
{ {
if (cb == '0') if (cb == '0')
{ {
nzb++; nzb++;
} }
else else
{ {
// only count consecutive zeroes // only count consecutive zeroes
nzb = 0; nzb = 0;
} }
cb = charAt(b, ++ib); cb = charAt(b, ++ib);
} }
// process run of digits // process run of digits
if (Character.isDigit(ca) && Character.isDigit(cb)) if (Character.isDigit(ca) && Character.isDigit(cb))
{ {
if ((result = compareRight(a.substring(ia), b.substring(ib))) != 0) if ((result = compareRight(a.substring(ia), b.substring(ib))) != 0)
{ {
return result; return result;
} }
} }
if (ca == 0 && cb == 0) if (ca == 0 && cb == 0)
{ {
// The strings compare the same. Perhaps the caller // The strings compare the same. Perhaps the caller
// will want to call strcmp to break the tie. // will want to call strcmp to break the tie.
return nza - nzb; return nza - nzb;
} }
if (ca < cb) if (ca < cb)
{ {
return -1; return -1;
} }
else if (ca > cb) else if (ca > cb)
{ {
return +1; return +1;
} }
++ia; ++ia;
++ib; ++ib;
} }
} }
// -------------------------------------------- // // -------------------------------------------- //
// UTIL // UTIL
// -------------------------------------------- // // -------------------------------------------- //
int compareRight(String a, String b) int compareRight(String a, String b)
{ {
int bias = 0; int bias = 0;
int ia = 0; int ia = 0;
int ib = 0; int ib = 0;
// The longest run of digits wins. That aside, the greatest // The longest run of digits wins. That aside, the greatest
// value wins, but we can't know that it will until we've scanned // value wins, but we can't know that it will until we've scanned
// both numbers to know that they have the same magnitude, so we // both numbers to know that they have the same magnitude, so we
// remember it in BIAS. // remember it in BIAS.
for (;; ia++, ib++) for (;; ia++, ib++)
{ {
char ca = charAt(a, ia); char ca = charAt(a, ia);
char cb = charAt(b, ib); char cb = charAt(b, ib);
if (!Character.isDigit(ca) && !Character.isDigit(cb)) if (!Character.isDigit(ca) && !Character.isDigit(cb))
{ {
return bias; return bias;
} }
else if (!Character.isDigit(ca)) else if (!Character.isDigit(ca))
{ {
return -1; return -1;
} }
else if (!Character.isDigit(cb)) else if (!Character.isDigit(cb))
{ {
return +1; return +1;
} }
else if (ca < cb) else if (ca < cb)
{ {
if (bias == 0) if (bias == 0)
{ {
bias = -1; bias = -1;
} }
} }
else if (ca > cb) else if (ca > cb)
{ {
if (bias == 0) if (bias == 0)
bias = +1; bias = +1;
} }
else if (ca == 0 && cb == 0) else if (ca == 0 && cb == 0)
{ {
return bias; return bias;
} }
} }
} }
static char charAt(String s, int i) static char charAt(String s, int i)
{ {
if (i >= s.length()) if (i >= s.length())
{ {
return 0; return 0;
} }
else else
{ {
return s.charAt(i); return s.charAt(i);
} }
} }
} }

View File

@ -4,6 +4,17 @@ import java.util.Comparator;
public class PriorityComparator implements Comparator<Prioritized> public class PriorityComparator implements Comparator<Prioritized>
{ {
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static PriorityComparator i = new PriorityComparator();
public static PriorityComparator get() { return i; }
// -------------------------------------------- //
// OVERRIDE: COMPARATOR
// -------------------------------------------- //
@Override @Override
public int compare(Prioritized one, Prioritized two) public int compare(Prioritized one, Prioritized two)
{ {
@ -14,11 +25,4 @@ public class PriorityComparator implements Comparator<Prioritized>
return Integer.valueOf(one.getPriority()).compareTo(two.getPriority()); return Integer.valueOf(one.getPriority()).compareTo(two.getPriority());
} }
// -------------------------------------------- //
// INSTANCE
// -------------------------------------------- //
private static PriorityComparator i = new PriorityComparator();
public static PriorityComparator get() { return i; }
} }

View File

@ -4,6 +4,17 @@ import java.util.Comparator;
public class ReversePriorityComparator implements Comparator<Prioritized> public class ReversePriorityComparator implements Comparator<Prioritized>
{ {
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static ReversePriorityComparator i = new ReversePriorityComparator();
public static ReversePriorityComparator get() { return i; }
// -------------------------------------------- //
// OVERRIDE: COMPARATOR
// -------------------------------------------- //
@Override @Override
public int compare(Prioritized one, Prioritized two) public int compare(Prioritized one, Prioritized two)
{ {
@ -14,11 +25,4 @@ public class ReversePriorityComparator implements Comparator<Prioritized>
return Integer.valueOf(two.getPriority()).compareTo(one.getPriority()); return Integer.valueOf(two.getPriority()).compareTo(one.getPriority());
} }
// -------------------------------------------- //
// INSTANCE
// -------------------------------------------- //
private static ReversePriorityComparator i = new ReversePriorityComparator();
public static ReversePriorityComparator get() { return i; }
} }

View File

@ -13,6 +13,7 @@ public class SimpleConfig
// -------------------------------------------- // // -------------------------------------------- //
// FIELDS // FIELDS
// -------------------------------------------- // // -------------------------------------------- //
protected transient Plugin plugin; protected transient Plugin plugin;
protected Plugin getPlugin() { return this.plugin; } protected Plugin getPlugin() { return this.plugin; }

View File

@ -23,17 +23,16 @@ public class FireworkEffectAdapter
// -------------------------------------------- // // -------------------------------------------- //
public static final String FLICKER = "flicker"; public static final String FLICKER = "flicker";
public static final String TRAIL = "trail"; public static final String TRAIL = "trail";
public static final String COLORS = "colors"; public static final String COLORS = "colors";
public static final String FADE_COLORS = "fade-colors"; public static final String FADE_COLORS = "fade-colors";
public static final String TYPE = "type"; public static final String TYPE = "type";
public static final boolean FLICKER_DEFAULT = false;
public static final boolean TRAIL_DEFAULT = false;
public static final List<Color> COLORS_DEFAULT = Collections.unmodifiableList(MUtil.list(Color.GREEN));
public static final List<Color> FADE_COLORS_DEFAULT = Collections.unmodifiableList(new ArrayList<Color>());
public static final Type TYPE_DEFAULT = Type.BALL_LARGE;
public static final boolean FLICKER_DEFAULT = false;
public static final boolean TRAIL_DEFAULT = false;
public static final List<Color> COLORS_DEFAULT = Collections.unmodifiableList(MUtil.list(Color.GREEN));
public static final List<Color> FADE_COLORS_DEFAULT = Collections.unmodifiableList(new ArrayList<Color>());
public static final Type TYPE_DEFAULT = Type.BALL_LARGE;
// -------------------------------------------- // // -------------------------------------------- //
// TO JSON // TO JSON
@ -65,51 +64,51 @@ public class FireworkEffectAdapter
JsonObject json = jsonElement.getAsJsonObject(); JsonObject json = jsonElement.getAsJsonObject();
boolean flicker = FLICKER_DEFAULT; boolean flicker = FLICKER_DEFAULT;
boolean trail = TRAIL_DEFAULT; boolean trail = TRAIL_DEFAULT;
List<Color> colors = COLORS_DEFAULT; List<Color> colors = COLORS_DEFAULT;
List<Color> fadeColors = FADE_COLORS_DEFAULT; List<Color> fadeColors = FADE_COLORS_DEFAULT;
Type type = TYPE_DEFAULT; Type type = TYPE_DEFAULT;
JsonElement element; JsonElement element;
element = json.get(FLICKER); element = json.get(FLICKER);
if (element != null) if (element != null)
{ {
flicker = element.getAsBoolean(); flicker = element.getAsBoolean();
} }
element = json.get(TRAIL); element = json.get(TRAIL);
if (element != null) if (element != null)
{ {
trail = element.getAsBoolean(); trail = element.getAsBoolean();
} }
element = json.get(COLORS); element = json.get(COLORS);
if (element != null) if (element != null)
{ {
colors = toColorCollection(element); colors = toColorCollection(element);
} }
element = json.get(FADE_COLORS); element = json.get(FADE_COLORS);
if (element != null) if (element != null)
{ {
fadeColors = toColorCollection(element); fadeColors = toColorCollection(element);
} }
element = json.get(TYPE); element = json.get(TYPE);
if (element != null) if (element != null)
{ {
type = Type.valueOf(element.getAsString()); type = Type.valueOf(element.getAsString());
} }
FireworkEffect ret = FireworkEffect.builder() FireworkEffect ret = FireworkEffect.builder()
.flicker(flicker) .flicker(flicker)
.trail(trail) .trail(trail)
.withColor(colors) .withColor(colors)
.withFade(fadeColors) .withFade(fadeColors)
.with(type) .with(type)
.build(); .build();
return ret; return ret;
} }

View File

@ -47,7 +47,7 @@ public class InventoryAdapter implements JsonDeserializer<Inventory>, JsonSerial
public static InventoryAdapter get() { return i; } public static InventoryAdapter get() { return i; }
// -------------------------------------------- // // -------------------------------------------- //
// IMPLEMENTATION // OVERRIDE
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
@ -63,7 +63,7 @@ public class InventoryAdapter implements JsonDeserializer<Inventory>, JsonSerial
} }
// -------------------------------------------- // // -------------------------------------------- //
// JSON // IMPLEMENTATION
// -------------------------------------------- // // -------------------------------------------- //
public static JsonElement toJson(Inventory src) public static JsonElement toJson(Inventory src)

View File

@ -14,7 +14,14 @@ import com.massivecraft.mcore.xlib.mongodb.MongoURI;
public class MongoURIAdapter implements JsonDeserializer<MongoURI>, JsonSerializer<MongoURI> public class MongoURIAdapter implements JsonDeserializer<MongoURI>, JsonSerializer<MongoURI>
{ {
// -------------------------------------------- // // -------------------------------------------- //
// IMPLEMENTATION // INSTANCE & CONSTRUCT
// -------------------------------------------- //
protected static MongoURIAdapter i = new MongoURIAdapter();
public static MongoURIAdapter get() { return i; }
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
@ -43,10 +50,4 @@ public class MongoURIAdapter implements JsonDeserializer<MongoURI>, JsonSerializ
return new MongoURI(json.getAsString()); return new MongoURI(json.getAsString());
} }
// -------------------------------------------- //
// INSTANCE
// -------------------------------------------- //
protected static MongoURIAdapter i = new MongoURIAdapter();
public static MongoURIAdapter get() { return i; }
} }

View File

@ -77,12 +77,22 @@ public class Money
return mixin.exists(universe(universe), accountId(accountId)); return mixin.exists(universe(universe), accountId(accountId));
} }
public static boolean exists(Object account)
{
return exists(account, account);
}
public static boolean create(Object universe, Object accountId) public static boolean create(Object universe, Object accountId)
{ {
if (disabled(universe)) return false; if (disabled(universe)) return false;
return mixin.create(universe(universe), accountId(accountId)); return mixin.create(universe(universe), accountId(accountId));
} }
public static boolean create(Object account)
{
return create(account, account);
}
// -------------------------------------------- // // -------------------------------------------- //
// GET AND SET // GET AND SET
// -------------------------------------------- // // -------------------------------------------- //
@ -93,12 +103,22 @@ public class Money
return mixin.get(universe(universe), accountId(accountId)); return mixin.get(universe(universe), accountId(accountId));
} }
public static double get(Object account)
{
return get(account, account);
}
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; if (disabled(universe)) return false;
return mixin.set(universe(universe), accountId(accountId), amount); return mixin.set(universe(universe), accountId(accountId), amount);
} }
public static boolean set(Object account, double amount)
{
return set(account, account, amount);
}
// -------------------------------------------- // // -------------------------------------------- //
// MODIFY // MODIFY
// -------------------------------------------- // // -------------------------------------------- //
@ -109,10 +129,20 @@ public class Money
return mixin.add(universe(universe), accountId(accountId), amount); return mixin.add(universe(universe), accountId(accountId), amount);
} }
public static boolean add(Object account, double amount)
{
return add(account, account, 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; if (disabled(universe)) return false;
return mixin.subtract(universe(universe), accountId(accountId), amount); return mixin.subtract(universe(universe), accountId(accountId), amount);
} }
public static boolean subtract(Object account, double amount)
{
return subtract(account, account, amount);
}
} }