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
public int compare(Object o1, Object o2)
{
String a = o1.toString();
String b = o2.toString();
@Override
public int compare(Object o1, Object o2)
{
String a = o1.toString();
String b = o2.toString();
int ia = 0, ib = 0;
int nza = 0, nzb = 0;
char ca, cb;
int result;
int ia = 0, ib = 0;
int nza = 0, nzb = 0;
char ca, cb;
int result;
while (true)
{
// only count the number of zeroes leading the last number compared
nza = nzb = 0;
while (true)
{
// only count the number of zeroes leading the last number compared
nza = nzb = 0;
ca = charAt(a, ia);
cb = charAt(b, ib);
ca = charAt(a, ia);
cb = charAt(b, ib);
// skip over leading spaces or zeros
while (Character.isSpaceChar(ca) || ca == '0')
{
if (ca == '0')
{
nza++;
}
else
{
// only count consecutive zeroes
nza = 0;
}
// skip over leading spaces or zeros
while (Character.isSpaceChar(ca) || ca == '0')
{
if (ca == '0')
{
nza++;
}
else
{
// only count consecutive zeroes
nza = 0;
}
ca = charAt(a, ++ia);
}
ca = charAt(a, ++ia);
}
while (Character.isSpaceChar(cb) || cb == '0')
{
if (cb == '0')
{
nzb++;
}
else
{
// only count consecutive zeroes
nzb = 0;
}
while (Character.isSpaceChar(cb) || cb == '0')
{
if (cb == '0')
{
nzb++;
}
else
{
// only count consecutive zeroes
nzb = 0;
}
cb = charAt(b, ++ib);
}
cb = charAt(b, ++ib);
}
// process run of digits
if (Character.isDigit(ca) && Character.isDigit(cb))
{
if ((result = compareRight(a.substring(ia), b.substring(ib))) != 0)
{
return result;
}
}
// process run of digits
if (Character.isDigit(ca) && Character.isDigit(cb))
{
if ((result = compareRight(a.substring(ia), b.substring(ib))) != 0)
{
return result;
}
}
if (ca == 0 && cb == 0)
{
// The strings compare the same. Perhaps the caller
// will want to call strcmp to break the tie.
return nza - nzb;
}
if (ca == 0 && cb == 0)
{
// The strings compare the same. Perhaps the caller
// will want to call strcmp to break the tie.
return nza - nzb;
}
if (ca < cb)
{
return -1;
}
else if (ca > cb)
{
return +1;
}
if (ca < cb)
{
return -1;
}
else if (ca > cb)
{
return +1;
}
++ia;
++ib;
}
}
++ia;
++ib;
}
}
// -------------------------------------------- //
// UTIL
// -------------------------------------------- //
int compareRight(String a, String b)
{
int bias = 0;
int ia = 0;
int ib = 0;
int compareRight(String a, String b)
{
int bias = 0;
int ia = 0;
int ib = 0;
// The longest run of digits wins. That aside, the greatest
// 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
// remember it in BIAS.
for (;; ia++, ib++)
{
char ca = charAt(a, ia);
char cb = charAt(b, ib);
// The longest run of digits wins. That aside, the greatest
// 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
// remember it in BIAS.
for (;; ia++, ib++)
{
char ca = charAt(a, ia);
char cb = charAt(b, ib);
if (!Character.isDigit(ca) && !Character.isDigit(cb))
{
return bias;
}
else if (!Character.isDigit(ca))
{
return -1;
}
else if (!Character.isDigit(cb))
{
return +1;
}
else if (ca < cb)
{
if (bias == 0)
{
bias = -1;
}
}
else if (ca > cb)
{
if (bias == 0)
bias = +1;
}
else if (ca == 0 && cb == 0)
{
return bias;
}
}
}
if (!Character.isDigit(ca) && !Character.isDigit(cb))
{
return bias;
}
else if (!Character.isDigit(ca))
{
return -1;
}
else if (!Character.isDigit(cb))
{
return +1;
}
else if (ca < cb)
{
if (bias == 0)
{
bias = -1;
}
}
else if (ca > cb)
{
if (bias == 0)
bias = +1;
}
else if (ca == 0 && cb == 0)
{
return bias;
}
}
}
static char charAt(String s, int i)
{
if (i >= s.length())
{
return 0;
}
else
{
return s.charAt(i);
}
}
static char charAt(String s, int i)
{
if (i >= s.length())
{
return 0;
}
else
{
return s.charAt(i);
}
}
}

View File

@ -4,6 +4,17 @@ import java.util.Comparator;
public class PriorityComparator implements Comparator<Prioritized>
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static PriorityComparator i = new PriorityComparator();
public static PriorityComparator get() { return i; }
// -------------------------------------------- //
// OVERRIDE: COMPARATOR
// -------------------------------------------- //
@Override
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());
}
// -------------------------------------------- //
// 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>
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static ReversePriorityComparator i = new ReversePriorityComparator();
public static ReversePriorityComparator get() { return i; }
// -------------------------------------------- //
// OVERRIDE: COMPARATOR
// -------------------------------------------- //
@Override
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());
}
// -------------------------------------------- //
// INSTANCE
// -------------------------------------------- //
private static ReversePriorityComparator i = new ReversePriorityComparator();
public static ReversePriorityComparator get() { return i; }
}

View File

@ -13,6 +13,7 @@ public class SimpleConfig
// -------------------------------------------- //
// FIELDS
// -------------------------------------------- //
protected transient Plugin 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 TRAIL = "trail";
public static final String COLORS = "colors";
public static final String FADE_COLORS = "fade-colors";
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 String TRAIL = "trail";
public static final String COLORS = "colors";
public static final String FADE_COLORS = "fade-colors";
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;
// -------------------------------------------- //
// TO JSON
@ -65,51 +64,51 @@ public class FireworkEffectAdapter
JsonObject json = jsonElement.getAsJsonObject();
boolean flicker = FLICKER_DEFAULT;
boolean trail = TRAIL_DEFAULT;
List<Color> colors = COLORS_DEFAULT;
List<Color> fadeColors = FADE_COLORS_DEFAULT;
Type type = TYPE_DEFAULT;
boolean flicker = FLICKER_DEFAULT;
boolean trail = TRAIL_DEFAULT;
List<Color> colors = COLORS_DEFAULT;
List<Color> fadeColors = FADE_COLORS_DEFAULT;
Type type = TYPE_DEFAULT;
JsonElement element;
JsonElement element;
element = json.get(FLICKER);
if (element != null)
{
flicker = element.getAsBoolean();
}
element = json.get(FLICKER);
if (element != null)
{
flicker = element.getAsBoolean();
}
element = json.get(TRAIL);
if (element != null)
{
trail = element.getAsBoolean();
}
element = json.get(TRAIL);
if (element != null)
{
trail = element.getAsBoolean();
}
element = json.get(COLORS);
if (element != null)
{
colors = toColorCollection(element);
}
element = json.get(COLORS);
if (element != null)
{
colors = toColorCollection(element);
}
element = json.get(FADE_COLORS);
if (element != null)
{
fadeColors = toColorCollection(element);
}
element = json.get(FADE_COLORS);
if (element != null)
{
fadeColors = toColorCollection(element);
}
element = json.get(TYPE);
if (element != null)
{
type = Type.valueOf(element.getAsString());
}
element = json.get(TYPE);
if (element != null)
{
type = Type.valueOf(element.getAsString());
}
FireworkEffect ret = FireworkEffect.builder()
.flicker(flicker)
.trail(trail)
.withColor(colors)
.withFade(fadeColors)
.with(type)
.build();
.flicker(flicker)
.trail(trail)
.withColor(colors)
.withFade(fadeColors)
.with(type)
.build();
return ret;
}

View File

@ -47,7 +47,7 @@ public class InventoryAdapter implements JsonDeserializer<Inventory>, JsonSerial
public static InventoryAdapter get() { return i; }
// -------------------------------------------- //
// IMPLEMENTATION
// OVERRIDE
// -------------------------------------------- //
@Override
@ -63,7 +63,7 @@ public class InventoryAdapter implements JsonDeserializer<Inventory>, JsonSerial
}
// -------------------------------------------- //
// JSON
// IMPLEMENTATION
// -------------------------------------------- //
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>
{
// -------------------------------------------- //
// IMPLEMENTATION
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
protected static MongoURIAdapter i = new MongoURIAdapter();
public static MongoURIAdapter get() { return i; }
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
@ -43,10 +50,4 @@ public class MongoURIAdapter implements JsonDeserializer<MongoURI>, JsonSerializ
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));
}
public static boolean exists(Object account)
{
return exists(account, account);
}
public static boolean create(Object universe, Object accountId)
{
if (disabled(universe)) return false;
return mixin.create(universe(universe), accountId(accountId));
}
public static boolean create(Object account)
{
return create(account, account);
}
// -------------------------------------------- //
// GET AND SET
// -------------------------------------------- //
@ -93,12 +103,22 @@ public class Money
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)
{
if (disabled(universe)) return false;
return mixin.set(universe(universe), accountId(accountId), amount);
}
public static boolean set(Object account, double amount)
{
return set(account, account, amount);
}
// -------------------------------------------- //
// MODIFY
// -------------------------------------------- //
@ -109,10 +129,20 @@ public class Money
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)
{
if (disabled(universe)) return false;
return mixin.subtract(universe(universe), accountId(accountId), amount);
}
public static boolean subtract(Object account, double amount)
{
return subtract(account, account, amount);
}
}