improved entity & world gen

This commit is contained in:
Ondřej Hruška
2014-04-25 23:58:33 +02:00
parent ffffbefefe
commit 5235b969c9
64 changed files with 889 additions and 787 deletions
@@ -54,9 +54,7 @@ public abstract class BusEvent<HANDLER> {
{
if (consumed) throw new IllegalStateException("Already consumed.");
if (getClass().isAnnotationPresent(NonConsumableEvent.class)) {
throw new UnsupportedOperationException("Not consumable.");
}
if (getClass().isAnnotationPresent(NonConsumableEvent.class)) { throw new UnsupportedOperationException("Not consumable."); }
consumed = true;
}
@@ -31,9 +31,7 @@ class EventChannel<EVENT extends BusEvent<CLIENT>, CLIENT> {
public EventChannel(Class<EVENT> eventClass, Class<CLIENT> clientClass)
{
if (eventClass == null || clientClass == null) {
throw new NullPointerException("Null Event or Client class.");
}
if (eventClass == null || clientClass == null) { throw new NullPointerException("Null Event or Client class."); }
this.clientClass = clientClass;
this.eventClass = eventClass;
@@ -62,9 +62,7 @@ public abstract class BusNode implements BusAccess, ClientHub {
@Override
public void addChildClient(Object client)
{
if (client instanceof RootBusNode) {
throw new IllegalArgumentException("Cannot nest RootBusNode.");
}
if (client instanceof RootBusNode) { throw new IllegalArgumentException("Cannot nest RootBusNode."); }
clients.add(client);
}
+1 -3
View File
@@ -82,9 +82,7 @@ public class FileTreeDiff {
final int read1 = cin1.read(BUFFER);
final int read2 = cin2.read(BUFFER);
if (read1 != read2 || ck1.getValue() != ck2.getValue()) {
throw new NotEqualException("Bytes differ:\n" + pair.a + "\n" + pair.b);
}
if (read1 != read2 || ck1.getValue() != ck2.getValue()) { throw new NotEqualException("Bytes differ:\n" + pair.a + "\n" + pair.b); }
if (read1 == -1) break;
}
+6 -18
View File
@@ -39,9 +39,7 @@ public class FileUtils {
if (!source.exists()) return;
if (source.isDirectory()) {
if (!target.exists() && !target.mkdir()) {
throw new IOException("Could not open destination directory.");
}
if (!target.exists() && !target.mkdir()) { throw new IOException("Could not open destination directory."); }
final String[] children = source.list();
for (final String element : children) {
@@ -49,9 +47,7 @@ public class FileUtils {
}
} else {
if (filter != null && !filter.accept(source)) {
return;
}
if (filter != null && !filter.accept(source)) { return; }
if (filesCopied != null) filesCopied.add(target);
copyFile(source, target);
@@ -76,9 +72,7 @@ public class FileUtils {
}
} else {
if (filter != null && !filter.accept(source.getAbsolutePath())) {
return;
}
if (filter != null && !filter.accept(source.getAbsolutePath())) { return; }
files.add(source);
}
@@ -112,13 +106,9 @@ public class FileUtils {
*/
public static void copyStream(InputStream in, OutputStream out) throws IOException
{
if (in == null) {
throw new NullPointerException("Input stream is null");
}
if (in == null) { throw new NullPointerException("Input stream is null"); }
if (out == null) {
throw new NullPointerException("Output stream is null");
}
if (out == null) { throw new NullPointerException("Output stream is null"); }
final byte[] buf = new byte[2048];
int len;
@@ -137,9 +127,7 @@ public class FileUtils {
*/
public static boolean delete(File path, boolean recursive)
{
if (!path.exists()) {
return true;
}
if (!path.exists()) { return true; }
if (!recursive || !path.isDirectory()) return path.delete();
+2 -6
View File
@@ -56,9 +56,7 @@ public class OsUtils {
final File f = new File(getWorkDir(dirname), subfolderName);
if (!f.exists() && create) {
if (!f.mkdirs()) {
throw new RuntimeException("Could not create.");
}
if (!f.mkdirs()) { throw new RuntimeException("Could not create."); }
}
return f;
@@ -137,9 +135,7 @@ public class OsUtils {
if (!file.exists() || !file.isDirectory()) {
if (create) {
if (!file.mkdirs()) {
throw new RuntimeException("Could not create working directory.");
}
if (!file.mkdirs()) { throw new RuntimeException("Could not create working directory."); }
}
}
@@ -182,9 +182,7 @@ public class PropertyManager {
{
boolean needsSave = false;
if (!file.getParentFile().mkdirs()) {
if (!file.getParentFile().exists()) {
throw new RuntimeException("Cound not create config file.");
}
if (!file.getParentFile().exists()) { throw new RuntimeException("Cound not create config file."); }
}
try(FileInputStream fis = new FileInputStream(file)) {
@@ -263,9 +263,7 @@ public class SortedProperties extends java.util.Properties {
private static char hexDigit(char ch, int offset)
{
final int val = (ch >> offset) & 0xF;
if (val <= 9) {
return (char) ('0' + val);
}
if (val <= 9) { return (char) ('0' + val); }
return (char) ('A' + val - 10);
}
+4 -12
View File
@@ -95,13 +95,9 @@ public class Ion {
if (mark > 255) throw new IllegalArgumentException("Mark must be < 256.");
if (mark < 0) throw new IllegalArgumentException("Mark must be positive.");
if (reservedMarkChecking && mark < 50) {
throw new IllegalArgumentException("Marks 0..49 are reserved.");
}
if (reservedMarkChecking && mark < 50) { throw new IllegalArgumentException("Marks 0..49 are reserved."); }
if (registered[mark] != null) {
throw new IllegalArgumentException("Mark " + mark + " is already in use.");
}
if (registered[mark] != null) { throw new IllegalArgumentException("Mark " + mark + " is already in use."); }
try {
objClass.getConstructor();
@@ -284,13 +280,9 @@ public class Ion {
final Class<? extends IonBinary> clz = Ion.getClassForMark(mark);
if (clz == null) {
throw new IOException("Not registered - mark: " + mark + ", class: " + Log.str(obj.getClass()));
}
if (clz == null) { throw new IOException("Not registered - mark: " + mark + ", class: " + Log.str(obj.getClass())); }
if (clz != obj.getClass()) {
throw new IOException("Class mismatch - mark: " + mark + ", class: " + Log.str(obj.getClass()));
}
if (clz != obj.getClass()) { throw new IOException("Class mismatch - mark: " + mark + ", class: " + Log.str(obj.getClass())); }
}
}
+1 -3
View File
@@ -269,9 +269,7 @@ public class IonOutput {
return;
}
if (obj instanceof IonBundled) {
throw new IOException("Bundled objects cannot be written to ION stream directly at " + obj);
}
if (obj instanceof IonBundled) { throw new IOException("Bundled objects cannot be written to ION stream directly at " + obj); }
if (obj instanceof Boolean) {
writeMark(Ion.BOOLEAN);
+2 -6
View File
@@ -295,9 +295,7 @@ public class Log {
final String nl = System.getProperty("line.separator");
if (message.equals("\n")) {
return nl;
}
if (message.equals("\n")) { return nl; }
if (message.charAt(0) == '\n') {
message = nl + message.substring(1);
@@ -359,9 +357,7 @@ public class Log {
public static String str(Class<?> cls)
{
final LogAlias ln = cls.getAnnotation(LogAlias.class);
if (ln != null) {
return ln.name();
}
if (ln != null) { return ln.name(); }
String name = cls.getName();
@@ -63,7 +63,7 @@ public class ArchivingLog extends SimpleLog {
private void cleanLoggingDirectory()
{
if (logs_to_keep == 0) return; // overwrite
final File log_file = getFile();
final File log_dir = log_file.getParentFile();
final String fname = FileUtils.getBasename(log_file.toString());
@@ -86,7 +86,7 @@ public class ArchivingLog extends SimpleLog {
}
if (logs_to_keep == -1) return; // keep all
final List<File> oldLogs = FileUtils.listDirectory(log_dir, new FileFilter() {
@Override
@@ -112,9 +112,7 @@ public class ArchivingLog extends SimpleLog {
// playing with fireee
for (int i = 0; i < oldLogs.size() - logs_to_keep; i++) {
if (!oldLogs.get(i).delete()) {
throw new RuntimeException("Could not delete old log file.");
}
if (!oldLogs.get(i).delete()) { throw new RuntimeException("Could not delete old log file."); }
}
}
+2 -6
View File
@@ -594,9 +594,7 @@ public class Calc {
*/
public static List<Integer> parseIntList(String list)
{
if (list == null) {
return null;
}
if (list == null) { return null; }
final String[] parts = list.split(",");
final ArrayList<Integer> intList = new ArrayList<>();
@@ -656,8 +654,6 @@ public class Calc {
*/
public static void assertValidIndex(int index, int length)
{
if (!inRange(index, 0, length - 1)) {
throw new IndexOutOfBoundsException();
}
if (!inRange(index, 0, length - 1)) { throw new IndexOutOfBoundsException(); }
}
}
+3 -9
View File
@@ -205,9 +205,7 @@ public abstract class Color {
*/
public static void pushAlpha(Num alpha)
{
if (!alphaStackEnabled) {
return;
}
if (!alphaStackEnabled) { return; }
alphaStack.push(alpha);
}
@@ -221,13 +219,9 @@ public abstract class Color {
*/
public static void popAlpha()
{
if (!alphaStackEnabled) {
return;
}
if (!alphaStackEnabled) { return; }
if (alphaStack.isEmpty()) {
throw new EmptyStackException();
}
if (alphaStack.isEmpty()) { throw new EmptyStackException(); }
alphaStack.pop();
}
@@ -1028,9 +1028,7 @@ public abstract class Rect implements RectBound, Digestable<RectDigest> {
double rw = other.size().x();
double rh = other.size().y();
if (rw <= 0 || rh <= 0 || tw <= 0 || th <= 0) {
return false;
}
if (rw <= 0 || rh <= 0 || tw <= 0 || th <= 0) { return false; }
final double tx = this.origin().x();
final double ty = this.origin().y();
@@ -58,13 +58,9 @@ public class TiledRect extends RectProxy {
*/
public Rect tile(int x, int y)
{
if (x >= tilesX || x < 0) {
throw new IndexOutOfBoundsException("X coordinate out fo range: " + x);
}
if (x >= tilesX || x < 0) { throw new IndexOutOfBoundsException("X coordinate out fo range: " + x); }
if (y >= tilesY || y < 0) {
throw new IndexOutOfBoundsException("Y coordinate out of range: " + y);
}
if (y >= tilesY || y < 0) { throw new IndexOutOfBoundsException("Y coordinate out of range: " + y); }
return aTile.move(perCol.mul(x), perRow.mul(y));
}
+2 -6
View File
@@ -137,9 +137,7 @@ public class Convert {
return String.format("{%f|%f}", c.getMin(), c.getMax());
}
if (o instanceof Class<?>) {
return Log.str(o);
}
if (o instanceof Class<?>) { return Log.str(o); }
return o.toString();
}
@@ -179,9 +177,7 @@ public class Convert {
final double x = Double.parseDouble(parts[0].trim());
final double y = Double.parseDouble(parts[1].trim());
if (parts.length == 2) {
return Vect.make(x, y);
}
if (parts.length == 2) { return Vect.make(x, y); }
final double z = Double.parseDouble(parts[2].trim());
+2 -6
View File
@@ -59,13 +59,9 @@ public class Pair<T1, T2> {
@Override
public boolean equals(Object obj)
{
if (obj == null) {
return false;
}
if (obj == null) { return false; }
if (!this.getClass().equals(obj.getClass())) {
return false;
}
if (!this.getClass().equals(obj.getClass())) { return false; }
final Pair<?, ?> t = (Pair<?, ?>) obj;
@@ -34,9 +34,7 @@ public class VarargsParser<K, V> {
{
final LinkedHashMap<K, V> attrs = new LinkedHashMap<>();
if (args.length % 2 != 0) {
throw new IllegalArgumentException("Odd number of elements in varargs map!");
}
if (args.length % 2 != 0) { throw new IllegalArgumentException("Odd number of elements in varargs map!"); }
K key = null;
for (final Object o : args) {
@@ -35,9 +35,7 @@ public class FileSuffixFilter implements FileFilter {
final String fname = pathname.getName().toLowerCase().trim();
for (final String suffix : suffixes) {
if (fname.endsWith(suffix.toLowerCase().trim())) {
return true;
}
if (fname.endsWith(suffix.toLowerCase().trim())) { return true; }
}
return false;
+2 -6
View File
@@ -64,15 +64,11 @@ public class TimerFps {
*/
public double getFraction()
{
if (getSkipped() >= 1) {
return 1;
}
if (getSkipped() >= 1) { return 1; }
final long time = getTime();
if (time <= nextFrame) {
return (double) (time - lastFrame) / (double) FRAME;
}
if (time <= nextFrame) { return (double) (time - lastFrame) / (double) FRAME; }
return 1;
}