Big refactoring and rewrite of PropertyManager (using store backned)

master
Ondřej Hruška 8 years ago
parent 812c3c3bf8
commit 7fb7128756
  1. 9
      src/mightypork/utils/MapSort.java
  2. 4
      src/mightypork/utils/Support.java
  3. 7
      src/mightypork/utils/annotations/Alias.java
  4. 2
      src/mightypork/utils/config/SimpleConfig.java
  5. 121
      src/mightypork/utils/config/propmgr/Property.java
  6. 176
      src/mightypork/utils/config/propmgr/PropertyManager.java
  7. 79
      src/mightypork/utils/config/propmgr/PropertyStore.java
  8. 30
      src/mightypork/utils/config/propmgr/properties/BooleanProperty.java
  9. 30
      src/mightypork/utils/config/propmgr/properties/DoubleProperty.java
  10. 30
      src/mightypork/utils/config/propmgr/properties/IntegerProperty.java
  11. 30
      src/mightypork/utils/config/propmgr/properties/StringProperty.java
  12. 119
      src/mightypork/utils/config/propmgr/store/PropertyFile.java
  13. 32
      src/mightypork/utils/config/propmgr/store/SortedProperties.java
  14. 9
      src/mightypork/utils/eventbus/EventBus.java
  15. 3
      src/mightypork/utils/eventbus/EventChannel.java
  16. 3
      src/mightypork/utils/eventbus/clients/ClientList.java
  17. 3
      src/mightypork/utils/eventbus/events/UpdateEvent.java
  18. 7
      src/mightypork/utils/eventbus/events/flags/DelayedEvent.java
  19. 7
      src/mightypork/utils/eventbus/events/flags/DirectEvent.java
  20. 7
      src/mightypork/utils/eventbus/events/flags/NotLoggedEvent.java
  21. 7
      src/mightypork/utils/eventbus/events/flags/SingleReceiverEvent.java
  22. 12
      src/mightypork/utils/exceptions/CorruptDataException.java
  23. 12
      src/mightypork/utils/exceptions/IllegalValueException.java
  24. 12
      src/mightypork/utils/exceptions/KeyAlreadyExistsException.java
  25. 3
      src/mightypork/utils/files/FileSuffixFilter.java
  26. 12
      src/mightypork/utils/files/FileTreeDiff.java
  27. 26
      src/mightypork/utils/files/FileUtils.java
  28. 71
      src/mightypork/utils/files/config/Property.java
  29. 7
      src/mightypork/utils/files/zip/ZipBuilder.java
  30. 18
      src/mightypork/utils/files/zip/ZipUtils.java
  31. 17
      src/mightypork/utils/ion/Ion.java
  32. 17
      src/mightypork/utils/ion/IonInput.java
  33. 6
      src/mightypork/utils/ion/IonMapWrapper.java
  34. 16
      src/mightypork/utils/ion/IonOutput.java
  35. 6
      src/mightypork/utils/ion/IonSequenceWrapper.java
  36. 9
      src/mightypork/utils/ion/IonizerBinary.java
  37. 6
      src/mightypork/utils/ion/IonizerBundled.java
  38. 10
      src/mightypork/utils/logging/writers/ArchivingLog.java
  39. 3
      src/mightypork/utils/logging/writers/SimpleLog.java
  40. 3
      src/mightypork/utils/math/Calc.java
  41. 6
      src/mightypork/utils/math/Polar.java
  42. 9
      src/mightypork/utils/math/Range.java
  43. 9
      src/mightypork/utils/math/algo/Coord.java
  44. 5
      src/mightypork/utils/math/algo/Move.java
  45. 4
      src/mightypork/utils/math/algo/pathfinding/PathFinder.java
  46. 3
      src/mightypork/utils/math/algo/pathfinding/PathFinderProxy.java
  47. 12
      src/mightypork/utils/math/animation/Animator.java
  48. 12
      src/mightypork/utils/math/animation/AnimatorBounce.java
  49. 12
      src/mightypork/utils/math/animation/AnimatorRewind.java
  50. 6
      src/mightypork/utils/math/animation/Easing.java
  51. 18
      src/mightypork/utils/math/animation/NumAnimated.java
  52. 9
      src/mightypork/utils/math/animation/NumAnimatedDeg.java
  53. 9
      src/mightypork/utils/math/animation/NumAnimatedRad.java
  54. 6
      src/mightypork/utils/math/animation/VectAnimated.java
  55. 3
      src/mightypork/utils/math/color/ColorAlphaAdjuster.java
  56. 3
      src/mightypork/utils/math/color/ColorHsb.java
  57. 3
      src/mightypork/utils/math/color/ColorRgb.java
  58. 1
      src/mightypork/utils/math/color/pal/RGB.java
  59. 6
      src/mightypork/utils/math/constraints/num/NumConst.java
  60. 3
      src/mightypork/utils/math/constraints/num/caching/AbstractNumCache.java
  61. 3
      src/mightypork/utils/math/constraints/num/caching/NumCache.java
  62. 3
      src/mightypork/utils/math/constraints/num/caching/NumDigest.java
  63. 6
      src/mightypork/utils/math/constraints/num/proxy/NumProxy.java
  64. 6
      src/mightypork/utils/math/constraints/num/var/NumVar.java
  65. 1
      src/mightypork/utils/math/constraints/rect/Rect.java
  66. 9
      src/mightypork/utils/math/constraints/rect/RectConst.java
  67. 3
      src/mightypork/utils/math/constraints/rect/builders/TiledRect.java
  68. 3
      src/mightypork/utils/math/constraints/rect/caching/AbstractRectCache.java
  69. 3
      src/mightypork/utils/math/constraints/rect/caching/RectCache.java
  70. 6
      src/mightypork/utils/math/constraints/rect/caching/RectDigest.java
  71. 6
      src/mightypork/utils/math/constraints/rect/proxy/RectProxy.java
  72. 3
      src/mightypork/utils/math/constraints/rect/proxy/RectVectAdapter.java
  73. 3
      src/mightypork/utils/math/constraints/rect/var/RectVar.java
  74. 6
      src/mightypork/utils/math/constraints/vect/VectConst.java
  75. 3
      src/mightypork/utils/math/constraints/vect/caching/AbstractVectCache.java
  76. 3
      src/mightypork/utils/math/constraints/vect/caching/VectCache.java
  77. 3
      src/mightypork/utils/math/constraints/vect/caching/VectDigest.java
  78. 6
      src/mightypork/utils/math/constraints/vect/proxy/VectNumAdapter.java
  79. 6
      src/mightypork/utils/math/constraints/vect/proxy/VectProxy.java
  80. 3
      src/mightypork/utils/math/constraints/vect/var/VectVar.java
  81. 6
      src/mightypork/utils/math/noise/NoiseGen.java
  82. 11
      src/mightypork/utils/math/noise/PerlinNoiseGenerator.java
  83. 1
      src/mightypork/utils/math/timing/Profiler.java
  84. 3
      src/mightypork/utils/math/timing/TaskRepeater.java
  85. 3
      src/mightypork/utils/math/timing/TimerDelta.java
  86. 3
      src/mightypork/utils/math/timing/TimerFps.java
  87. 3
      src/mightypork/utils/string/StringWrapper.java
  88. 3
      src/mightypork/utils/string/validation/CharFilterRegex.java
  89. 3
      src/mightypork/utils/string/validation/CharFilterWhitelist.java
  90. 3
      src/mightypork/utils/struct/Mutable.java
  91. 3
      src/mightypork/utils/struct/Pair.java
  92. 3
      src/mightypork/utils/struct/Triad.java

@ -1,12 +1,7 @@
package mightypork.utils;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.Map.Entry;
@ -49,7 +44,7 @@ public class MapSort {
public int compare(K arg0, K arg1)
{
return ((Comparable<K>) arg0).compareTo(arg1);
}
}
};
}

@ -153,7 +153,6 @@ public final class Support {
return new IterableEnumerationWrapper<>(enumeration);
}
/**
* Helper class for iterationg over an {@link Enumeration}
*
@ -168,8 +167,7 @@ public final class Support {
/**
* @param enumeration the iterated enumeration
*/
public IterableEnumerationWrapper(Enumeration<? extends T> enumeration)
{
public IterableEnumerationWrapper(Enumeration<? extends T> enumeration) {
this.enumeration = enumeration;
}

@ -1,12 +1,7 @@
package mightypork.utils.annotations;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.annotation.*;
/**

@ -1,4 +1,4 @@
package mightypork.utils.files.config;
package mightypork.utils.config;
import java.io.File;

@ -0,0 +1,121 @@
package mightypork.utils.config.propmgr;
import mightypork.utils.Convert;
import mightypork.utils.annotations.Stub;
/**
* Property entry for the {@link PropertyManager}.<br>
* Extending this class can be used to add custom property types that are not
* supported by default.
*
* @author Ondřej Hruška (MightyPork)
* @param <T> property type
*/
public abstract class Property<T> {
protected final String comment;
protected final String key;
protected T value;
protected final T defaultValue;
/**
* Create a property without comment
*
* @param key key in the config file
* @param defaultValue defualt property value (used as fallback when
* parsing)
*/
public Property(String key, T defaultValue) {
this(key, defaultValue, null);
}
/**
* Create a property with a comment
*
* @param key key in the config file
* @param defaultValue defualt property value (used as fallback when
* parsing)
* @param comment optional property comment included above the property in
* the config file. Can be null.
*/
public Property(String key, T defaultValue, String comment) {
this.comment = comment;
this.key = key;
this.value = defaultValue;
this.defaultValue = defaultValue;
}
/**
* Parse a string representation of the value into this property. If the
* value cannot be decoded, use the default value instead.
*
* @param string property value as string
*/
public abstract void fromString(String string);
/**
* Get property value as string (compatible with `fromString())
*
* @return property value as string
*/
@Override
@Stub
public String toString()
{
return Convert.toString(value, Convert.toString(defaultValue));
}
/**
* Get the current property value
*
* @return the value
*/
public final T getValue()
{
return value;
}
/**
* Set property value.<br>
* Uses Object to allow setValue(Object) method in {@link PropertyManager}
*
* @param value value to set.
* @throws ClassCastException in case of incompatible type.
*/
@SuppressWarnings("unchecked")
public final void setValue(Object value)
{
this.value = (T) value;
}
/**
* Get property comment.
*
* @return the comment text (can be null if no comment is defined)
*/
public final String getComment()
{
return comment;
}
/**
* Get property key
*
* @return property key
*/
public final String getKey()
{
return key;
}
}

@ -1,15 +1,16 @@
package mightypork.utils.files.config;
package mightypork.utils.config.propmgr;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Map.Entry;
import java.util.TreeMap;
import mightypork.utils.Convert;
import mightypork.utils.config.propmgr.properties.BooleanProperty;
import mightypork.utils.config.propmgr.properties.DoubleProperty;
import mightypork.utils.config.propmgr.properties.IntegerProperty;
import mightypork.utils.config.propmgr.properties.StringProperty;
import mightypork.utils.logging.Log;
@ -20,131 +21,46 @@ import mightypork.utils.logging.Log;
*/
public class PropertyManager {
private class BooleanProperty extends Property<Boolean> {
public BooleanProperty(String key, Boolean defaultValue, String comment)
{
super(key, defaultValue, comment);
}
@Override
public Boolean decode(String string, Boolean defval)
{
return Convert.toBoolean(string, defval);
}
}
private class IntegerProperty extends Property<Integer> {
public IntegerProperty(String key, Integer defaultValue, String comment)
{
super(key, defaultValue, comment);
}
@Override
public Integer decode(String string, Integer defval)
{
return Convert.toInteger(string, defval);
}
}
private class DoubleProperty extends Property<Double> {
public DoubleProperty(String key, Double defaultValue, String comment)
{
super(key, defaultValue, comment);
}
@Override
public Double decode(String string, Double defval)
{
return Convert.toDouble(string, defval);
}
}
private class StringProperty extends Property<String> {
public StringProperty(String key, String defaultValue, String comment)
{
super(key, defaultValue, comment);
}
@Override
public String decode(String string, String defval)
{
return Convert.toString(string, defval);
}
}
/** put newline before entry comments */
private boolean cfgNewlineBeforeComments = true;
/** Put newline between sections. */
private boolean cfgSeparateSections = true;
private final File file;
private String fileComment = "";
private final TreeMap<String, Property<?>> entries;
private final TreeMap<String, String> renameTable;
private SortedProperties props = new SortedProperties();
private final TreeMap<String, Property<?>> entries = new TreeMap<>();
private final TreeMap<String, String> renameTable = new TreeMap<>();
private PropertyStore props;
/**
* Create property manager from file path and an initial comment.
*
* @param file file with the props
* @param comment the initial comment. Use \n in it if you want.
* @param props a property store implementation backing this property
* manager
*/
public PropertyManager(File file, String comment)
{
this.file = file;
this.entries = new TreeMap<>();
this.renameTable = new TreeMap<>();
this.fileComment = comment;
public PropertyManager(PropertyStore props) {
this.props = props;
}
/**
* Load, fix and write to file.
* Load from file
*/
public void load()
{
if (!file.getParentFile().mkdirs()) {
if (!file.getParentFile().exists()) {
throw new RuntimeException("Cound not create config file.");
}
}
try(FileInputStream fis = new FileInputStream(file)) {
props.load(fis);
} catch (final IOException e) {
props = new SortedProperties();
}
props.cfgBlankRowBetweenSections = cfgSeparateSections;
props.cfgBlankRowBeforeComment = cfgNewlineBeforeComments;
props.load();
// rename keys
// rename keys (useful if keys change but value is to be kept)
for (final Entry<String, String> entry : renameTable.entrySet()) {
final String pr = props.getProperty(entry.getKey());
final String value = props.getProperty(entry.getKey());
if (pr == null) continue;
if (value == null) continue;
props.remove(entry.getKey());
props.setProperty(entry.getValue(), pr);
final String oldKey = entry.getKey();
final String newKey = entry.getValue();
props.removeProperty(oldKey);
props.setProperty(newKey, value, entries.get(newKey).getComment());
}
for (final Property<?> entry : entries.values()) {
entry.parse(props.getProperty(entry.getKey()));
entry.fromString(props.getProperty(entry.getKey()));
}
renameTable.clear();
}
@ -157,48 +73,23 @@ public class PropertyManager {
for (final Property<?> entry : entries.values()) {
keyList.add(entry.getKey());
if (entry.getComment() != null) {
props.setKeyComment(entry.getKey(), entry.getComment());
}
props.setProperty(entry.getKey(), entry.toString());
props.setProperty(entry.getKey(), entry.toString(), entry.getComment());
}
// removed unused props
for (final String propname : props.keySet().toArray(new String[props.size()])) {
if (!keyList.contains(propname)) {
props.remove(propname);
for (final String key : props.keys()) {
if (!keyList.contains(key)) {
props.removeProperty(key);
}
}
try(FileOutputStream fos = new FileOutputStream(file)) {
props.store(fos, fileComment);
}
props.save();
} catch (final IOException ioe) {
ioe.printStackTrace();
}
}
/**
* @param newlineBeforeComments put newline before comments
*/
public void cfgNewlineBeforeComments(boolean newlineBeforeComments)
{
this.cfgNewlineBeforeComments = newlineBeforeComments;
}
/**
* @param separateSections do separate sections by newline
*/
public void cfgSeparateSections(boolean separateSections)
{
this.cfgSeparateSections = separateSections;
}
/**
* Get a property entry (rarely used)
*
@ -334,9 +225,9 @@ public class PropertyManager {
/**
* Add a range property
* Add a generic property (can be used with custom property types)
*
* @param prop property to put
* @param prop property to add
*/
public <T> void putProperty(Property<T> prop)
{
@ -369,9 +260,14 @@ public class PropertyManager {
}
/**
* Set heading comment of the property store.
*
* @param fileComment comment text (can be multi-line)
*/
public void setFileComment(String fileComment)
{
this.fileComment = fileComment;
props.setComment(fileComment);
}
}

@ -0,0 +1,79 @@
package mightypork.utils.config.propmgr;
import java.io.IOException;
import java.util.Collection;
/**
* Interface for a property store (used by {@link PropertyManager}).<br>
* Due to this abstraction, different kind of property storage can be used, not
* only a file.
*
* @author Ondřej Hruška (MightyPork)
*/
public interface PropertyStore {
/**
* Set a header comment
*
* @param comment the comment text (can be multi-line)
*/
void setComment(String comment);
/**
* Load properties from the file / store. If the file does not exist or is
* inaccessible, nothing is loaded.
*/
void load();
/**
* Save properties to the file / store.
*
* @throws IOException if the file cannot be created or written.
*/
void save() throws IOException;
/**
* Get a property value
*
* @param key property key
* @return value retrieved from the file, or null if none found.
*/
String getProperty(String key);
/**
* Set a property value
*
* @param key property key
* @param value property value to set
* @param comment property comment. Can be null.
*/
void setProperty(String key, String value, String comment);
/**
* Remove a property from the list.
*
* @param key property key to remove
*/
void removeProperty(String key);
/**
* Clear the property list
*/
void clear();
/**
* Get keys collection (can be used for iterating)
*
* @return keys collection
*/
public Collection<String> keys();
}

@ -0,0 +1,30 @@
package mightypork.utils.config.propmgr.properties;
import mightypork.utils.Convert;
import mightypork.utils.config.propmgr.Property;
/**
* Boolean property
*
* @author Ondřej Hruška (MightyPork)
*/
public class BooleanProperty extends Property<Boolean> {
public BooleanProperty(String key, Boolean defaultValue) {
super(key, defaultValue);
}
public BooleanProperty(String key, Boolean defaultValue, String comment) {
super(key, defaultValue, comment);
}
@Override
public void fromString(String string)
{
setValue(Convert.toBoolean(string, defaultValue));
}
}

@ -0,0 +1,30 @@
package mightypork.utils.config.propmgr.properties;
import mightypork.utils.Convert;
import mightypork.utils.config.propmgr.Property;
/**
* Double property
*
* @author Ondřej Hruška (MightyPork)
*/
public class DoubleProperty extends Property<Double> {
public DoubleProperty(String key, Double defaultValue) {
super(key, defaultValue);
}
public DoubleProperty(String key, Double defaultValue, String comment) {
super(key, defaultValue, comment);
}
@Override
public void fromString(String string)
{
setValue(Convert.toDouble(string, defaultValue));
}
}

@ -0,0 +1,30 @@
package mightypork.utils.config.propmgr.properties;
import mightypork.utils.Convert;
import mightypork.utils.config.propmgr.Property;
/**
* Integer property
*
* @author Ondřej Hruška (MightyPork)
*/
public class IntegerProperty extends Property<Integer> {
public IntegerProperty(String key, Integer defaultValue) {
super(key, defaultValue);
}
public IntegerProperty(String key, Integer defaultValue, String comment) {
super(key, defaultValue, comment);
}
@Override
public void fromString(String string)
{
setValue(Convert.toInteger(string, defaultValue));
}
}

@ -0,0 +1,30 @@
package mightypork.utils.config.propmgr.properties;
import mightypork.utils.Convert;
import mightypork.utils.config.propmgr.Property;
/**
* String property
*
* @author Ondřej Hruška (MightyPork)
*/
public class StringProperty extends Property<String> {
public StringProperty(String key, String defaultValue) {
super(key, defaultValue);
}
public StringProperty(String key, String defaultValue, String comment) {
super(key, defaultValue, comment);
}
@Override
public void fromString(String string)
{
setValue(Convert.toString(string, defaultValue));
}
}

@ -0,0 +1,119 @@
package mightypork.utils.config.propmgr.store;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Collection;
import mightypork.utils.config.propmgr.PropertyStore;
/**
* File based implementation utilizing {@link java.util.Properties}, hacked to
* support UTF-8.
*
* @author Ondřej Hruška (MightyPork)
*/
public class PropertyFile implements PropertyStore {
private String comment;
private File file;
private SortedProperties props;
public PropertyFile(File file) {
this.file = file;
this.comment = null;
this.props = new SortedProperties();
}
public PropertyFile(File file, String comment) {
this.file = file;
this.comment = comment;
this.props = new SortedProperties();
}
@Override
public void setComment(String comment)
{
this.comment = comment;
}
@Override
public void load()
{
if (!file.exists()) return;
try (FileInputStream in = new FileInputStream(file)) {
props.load(in);
} catch (IOException e) {
// ignore
}
}
@Override
public void save() throws IOException
{
if (!file.getParentFile().mkdirs()) {
if (!file.getParentFile().exists()) {
throw new IOException("Cound not create config file.");
}
}
try (FileOutputStream out = new FileOutputStream(file)) {
props.store(out, comment);
}
}
@Override
public String getProperty(String key)
{
return props.getProperty(key);
}
@Override
public void setProperty(String key, String value, String comment)
{
props.setProperty(key, value);
props.setKeyComment(key, comment);
}
@Override
public void removeProperty(String key)
{
props.remove(key);
}
@Override
public void clear()
{
props.clear();
}
@SuppressWarnings("unchecked")
@Override
public Collection<String> keys()
{
// Set<String> keys = new HashSet<>();
// for (Object o : props.keySet()) {
// keys.add((String) o);
// }
// return keys;
// we know it is strings.
return (Collection<String>) (Collection<?>) props.keySet();
}
}

@ -1,13 +1,7 @@
package mightypork.utils.files.config;
package mightypork.utils.config.propmgr.store;
import java.io.BufferedWriter;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.*;
import java.util.Collections;
import java.util.Enumeration;
import java.util.Hashtable;
@ -16,20 +10,13 @@ import java.util.Vector;
/**
* Properties stored in file, alphabetically sorted.<br>
* Uses UTF-8 encoding and each property can have it's own comment.
* Uses UTF-8 encoding and each property can have it's own comment.<br>
* FIXME The quality of this class is dubious. It would probably be a good idea
* to rewrite it without using {@link java.util.Properties} at all.
*
* @author Ondřej Hruška (MightyPork)
*/
public class SortedProperties extends java.util.Properties {
/** Option: put empty line before each comment. */
public boolean cfgBlankRowBeforeComment = true;
/**
* Option: Separate sections by newline<br>
* Section = string before first dot in key.
*/
public boolean cfgBlankRowBetweenSections = true;
class SortedProperties extends java.util.Properties {
/** Comments for individual keys */
private final Hashtable<String, String> keyComments = new Hashtable<>();
@ -205,7 +192,8 @@ public class SortedProperties extends java.util.Properties {
key = saveConvert(key, true, escUnicode);
val = saveConvert(val, false, escUnicode);
if (cfgBlankRowBetweenSections && !lastSectionBeginning.equals(key.split("[.]")[0])) {
// separate sections
if (!lastSectionBeginning.equals(key.split("[.]")[0])) {
if (!firstEntry) {
bw.newLine();
bw.newLine();
@ -223,7 +211,8 @@ public class SortedProperties extends java.util.Properties {
final String[] cmlines = cm.split("\n");
if (!wasNewLine && !firstEntry && cfgBlankRowBeforeComment) {
// newline before comments
if (!wasNewLine && !firstEntry) {
bw.newLine();
}
@ -298,6 +287,7 @@ public class SortedProperties extends java.util.Properties {
sb.append(c);
}
// discard comments
final String read = sb.toString().replaceAll("(#|;|//|--)[^\n]*\n", "\n");
final String inputString = escapifyStr(read);

@ -36,8 +36,7 @@ final public class EventBus implements Destroyable {
private final BusEvent<?> evt;
public DelayQueueEntry(double seconds, BusEvent<?> event)
{
public DelayQueueEntry(double seconds, BusEvent<?> event) {
super();
this.due = System.currentTimeMillis() + (long) (seconds * 1000);
this.evt = event;
@ -73,8 +72,7 @@ final public class EventBus implements Destroyable {
public volatile boolean stopped = false;
public QueuePollingThread()
{
public QueuePollingThread() {
super("Queue Polling Thread");
}
@ -135,8 +133,7 @@ final public class EventBus implements Destroyable {
/**
* Make a new bus and start it's queue thread.
*/
public EventBus()
{
public EventBus() {
busThread = new QueuePollingThread();
busThread.setDaemon(true);
busThread.start();

@ -31,8 +31,7 @@ class EventChannel<EVENT extends BusEvent<CLIENT>, CLIENT> {
* @param eventClass event class
* @param clientClass client class
*/
public EventChannel(Class<EVENT> eventClass, Class<CLIENT> clientClass)
{
public EventChannel(Class<EVENT> eventClass, Class<CLIENT> clientClass) {
if (eventClass == null || clientClass == null) {
throw new NullPointerException("Null Event or Client class.");

@ -12,8 +12,7 @@ import java.util.ArrayList;
*/
public class ClientList extends ArrayList<Object> {
public ClientList(Object... clients)
{
public ClientList(Object... clients) {
for (final Object c : clients) {
super.add(c);
}

@ -24,8 +24,7 @@ public class UpdateEvent extends BusEvent<Updateable> {
/**
* @param deltaTime time since last update (sec)
*/
public UpdateEvent(double deltaTime)
{
public UpdateEvent(double deltaTime) {
this.deltaTime = deltaTime;
}

@ -1,12 +1,7 @@
package mightypork.utils.eventbus.events.flags;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.annotation.*;
/**

@ -1,12 +1,7 @@
package mightypork.utils.eventbus.events.flags;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.annotation.*;
/**

@ -1,12 +1,7 @@
package mightypork.utils.eventbus.events.flags;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.annotation.*;
/**

@ -1,12 +1,7 @@
package mightypork.utils.eventbus.events.flags;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.annotation.*;
/**

@ -11,26 +11,22 @@ import java.io.IOException;
*/
public class CorruptDataException extends IOException {
public CorruptDataException()
{
public CorruptDataException() {
super();
}
public CorruptDataException(String message, Throwable cause)
{
public CorruptDataException(String message, Throwable cause) {
super(message, cause);
}
public CorruptDataException(String message)
{
public CorruptDataException(String message) {
super(message);
}
public CorruptDataException(Throwable cause)
{
public CorruptDataException(Throwable cause) {
super(cause);
}

@ -9,25 +9,21 @@ package mightypork.utils.exceptions;
*/
public class IllegalValueException extends RuntimeException {
public IllegalValueException()
{
public IllegalValueException() {
}
public IllegalValueException(String message)
{
public IllegalValueException(String message) {
super(message);
}
public IllegalValueException(Throwable cause)
{
public IllegalValueException(Throwable cause) {
super(cause);
}
public IllegalValueException(String message, Throwable cause)
{
public IllegalValueException(String message, Throwable cause) {
super(message, cause);
}

@ -8,26 +8,22 @@ package mightypork.utils.exceptions;
*/
public class KeyAlreadyExistsException extends RuntimeException {
public KeyAlreadyExistsException()
{
public KeyAlreadyExistsException() {
super();
}
public KeyAlreadyExistsException(String message, Throwable cause)
{
public KeyAlreadyExistsException(String message, Throwable cause) {
super(message, cause);
}
public KeyAlreadyExistsException(String message)
{
public KeyAlreadyExistsException(String message) {
super(message);
}
public KeyAlreadyExistsException(Throwable cause)
{
public KeyAlreadyExistsException(Throwable cause) {
super(cause);
}

@ -21,8 +21,7 @@ public class FileSuffixFilter implements FileFilter {
*
* @param suffixes var-args allowed suffixes, case insensitive
*/
public FileSuffixFilter(String... suffixes)
{
public FileSuffixFilter(String... suffixes) {
this.suffixes = suffixes;
}

@ -72,11 +72,9 @@ public class FileTreeDiff {
ck1.reset();
ck2.reset();
try(FileInputStream in1 = new FileInputStream(pair.a);
FileInputStream in2 = new FileInputStream(pair.b)) {
try (FileInputStream in1 = new FileInputStream(pair.a); FileInputStream in2 = new FileInputStream(pair.b)) {
try(CheckedInputStream cin1 = new CheckedInputStream(in1, ck1);
CheckedInputStream cin2 = new CheckedInputStream(in2, ck2)) {
try (CheckedInputStream cin1 = new CheckedInputStream(in1, ck1); CheckedInputStream cin2 = new CheckedInputStream(in2, ck2)) {
while (true) {
final int read1 = cin1.read(BUFFER);
@ -130,8 +128,7 @@ public class FileTreeDiff {
private class NotEqualException extends Exception {
public NotEqualException(String msg)
{
public NotEqualException(String msg) {
super(msg);
}
@ -143,8 +140,7 @@ public class FileTreeDiff {
public T b;
public Tuple(T a, T b)
{
public Tuple(T a, T b) {
this.a = a;
this.b = b;
}

@ -1,19 +1,7 @@
package mightypork.utils.files;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileFilter;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
@ -107,8 +95,7 @@ public class FileUtils {
public static void copyFile(File source, File target) throws IOException
{
try(InputStream in = new FileInputStream(source);
OutputStream out = new FileOutputStream(target)) {
try (InputStream in = new FileInputStream(source); OutputStream out = new FileOutputStream(target)) {
copyStream(in, out);
}
@ -173,7 +160,7 @@ public class FileUtils {
*/
public static String fileToString(File file) throws IOException
{
try(FileInputStream fin = new FileInputStream(file)) {
try (FileInputStream fin = new FileInputStream(file)) {
return streamToString(fin);
}
@ -365,7 +352,7 @@ public class FileUtils {
*/
public static void stringToFile(File file, String text) throws IOException
{
try(PrintStream out = new PrintStream(new FileOutputStream(file), false, "UTF-8")) {
try (PrintStream out = new PrintStream(new FileOutputStream(file), false, "UTF-8")) {
out.print(text);
@ -413,8 +400,7 @@ public class FileUtils {
*/
public static void resourceToFile(String resname, File file) throws IOException
{
try(InputStream in = FileUtils.getResource(resname);
OutputStream out = new FileOutputStream(file)) {
try (InputStream in = FileUtils.getResource(resname); OutputStream out = new FileOutputStream(file)) {
FileUtils.copyStream(in, out);
}
@ -431,7 +417,7 @@ public class FileUtils {
*/
public static String resourceToString(String resname) throws IOException
{
try(InputStream in = FileUtils.getResource(resname)) {
try (InputStream in = FileUtils.getResource(resname)) {
return streamToString(in);
}
}

@ -1,71 +0,0 @@
package mightypork.utils.files.config;
import mightypork.utils.Convert;
public abstract class Property<T extends Object> {
private final String comment;
private final String key;
private T value;
private final T defaultValue;
public Property(String key, T defaultValue, String comment)
{
super();
this.comment = comment;
this.key = key;
this.value = defaultValue;
this.defaultValue = defaultValue;
}
public final void parse(String string)
{
setValue(decode(string, defaultValue));
}
public abstract T decode(String string, T defval);
public String encode(T value)
{
return Convert.toString(value, Convert.toString(defaultValue));
}
@Override
public final String toString()
{
return encode(value);
}
public T getValue()
{
return value;
}
@SuppressWarnings("unchecked")
public void setValue(Object value)
{
this.value = (T) value;
}
public String getComment()
{
return comment;
}
public String getKey()
{
return key;
}
}

@ -29,8 +29,7 @@ public class ZipBuilder {
* @param target target zip file
* @throws IOException if the file is directory or cannot be created
*/
public ZipBuilder(File target) throws IOException
{
public ZipBuilder(File target) throws IOException {
if (!target.getParentFile().mkdirs()) throw new IOException("Could not create output directory.");
@ -76,7 +75,7 @@ public class ZipBuilder {
out.putNextEntry(new ZipEntry(path));