Big refactoring and rewrite of PropertyManager (using store backned)
This commit is contained in:
@@ -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
-1
@@ -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;
|
||||
}
|
||||
}
|
||||
+36
-140
@@ -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.");
|
||||
}
|
||||
}
|
||||
props.load();
|
||||
|
||||
try(FileInputStream fis = new FileInputStream(file)) {
|
||||
props.load(fis);
|
||||
} catch (final IOException e) {
|
||||
props = new SortedProperties();
|
||||
}
|
||||
|
||||
props.cfgBlankRowBetweenSections = cfgSeparateSections;
|
||||
props.cfgBlankRowBeforeComment = cfgNewlineBeforeComments;
|
||||
|
||||
// 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();
|
||||
}
|
||||
|
||||
}
|
||||
+11
-21
@@ -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));
|
||||
|
||||
try(InputStream in = FileUtils.stringToStream(text)) {
|
||||
try (InputStream in = FileUtils.stringToStream(text)) {
|
||||
FileUtils.copyStream(in, out);
|
||||
}
|
||||
}
|
||||
@@ -97,7 +96,7 @@ public class ZipBuilder {
|
||||
|
||||
out.putNextEntry(new ZipEntry(path));
|
||||
|
||||
try(InputStream in = FileUtils.getResource(resPath)) {
|
||||
try (InputStream in = FileUtils.getResource(resPath)) {
|
||||
FileUtils.copyStream(in, out);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,7 @@
|
||||
package mightypork.utils.files.zip;
|
||||
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
@@ -39,7 +34,7 @@ public class ZipUtils {
|
||||
*/
|
||||
public static List<String> extractZip(File file, File outputDir, StringFilter filter) throws IOException
|
||||
{
|
||||
try(ZipFile zip = new ZipFile(file)) {
|
||||
try (ZipFile zip = new ZipFile(file)) {
|
||||
return extractZip(zip, outputDir, filter);
|
||||
}
|
||||
}
|
||||
@@ -95,7 +90,7 @@ public class ZipUtils {
|
||||
*/
|
||||
public static List<String> listZip(File zipFile) throws IOException
|
||||
{
|
||||
try(ZipFile zip = new ZipFile(zipFile)) {
|
||||
try (ZipFile zip = new ZipFile(zipFile)) {
|
||||
return listZip(zip);
|
||||
}
|
||||
}
|
||||
@@ -139,10 +134,7 @@ public class ZipUtils {
|
||||
{
|
||||
if (!destFile.getParentFile().mkdirs()) throw new IOException("Could not create output directory.");
|
||||
|
||||
try(InputStream in = zip.getInputStream(entry);
|
||||
BufferedInputStream is = new BufferedInputStream(in);
|
||||
FileOutputStream fos = new FileOutputStream(destFile);
|
||||
BufferedOutputStream dest = new BufferedOutputStream(fos, BUFFER_SIZE)) {
|
||||
try (InputStream in = zip.getInputStream(entry); BufferedInputStream is = new BufferedInputStream(in); FileOutputStream fos = new FileOutputStream(destFile); BufferedOutputStream dest = new BufferedOutputStream(fos, BUFFER_SIZE)) {
|
||||
|
||||
FileUtils.copyStream(is, dest);
|
||||
}
|
||||
@@ -176,7 +168,7 @@ public class ZipUtils {
|
||||
|
||||
public static boolean entryExists(File selectedFile, String string)
|
||||
{
|
||||
try(ZipFile zf = new ZipFile(selectedFile)) {
|
||||
try (ZipFile zf = new ZipFile(selectedFile)) {
|
||||
return zf.getEntry(string) != null;
|
||||
} catch (final IOException | RuntimeException e) {
|
||||
Log.w("Error reading zip.", e);
|
||||
|
||||
@@ -1,12 +1,7 @@
|
||||
package mightypork.utils.ion;
|
||||
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -85,7 +80,6 @@ public class Ion {
|
||||
/** Array of arbitrary objects */
|
||||
public static final int OBJECT_ARRAY = 26;
|
||||
|
||||
|
||||
/** Ionizables<Mark, Class> */
|
||||
private static Map<Integer, Class<?>> markToClass = new HashMap<>();
|
||||
private static Map<Class<?>, Integer> classToMark = new HashMap<>();
|
||||
@@ -243,7 +237,7 @@ public class Ion {
|
||||
*/
|
||||
public static <T> T fromFile(File file) throws IOException
|
||||
{
|
||||
try(InputStream in = new FileInputStream(file)) {
|
||||
try (InputStream in = new FileInputStream(file)) {
|
||||
return fromStream(in);
|
||||
}
|
||||
}
|
||||
@@ -263,7 +257,7 @@ public class Ion {
|
||||
*/
|
||||
public static void toFile(File file, Object obj) throws IOException
|
||||
{
|
||||
try(OutputStream out = new FileOutputStream(file)) {
|
||||
try (OutputStream out = new FileOutputStream(file)) {
|
||||
|
||||
toStream(out, obj);
|
||||
|
||||
@@ -279,7 +273,7 @@ public class Ion {
|
||||
*/
|
||||
public static <T> T fromStream(InputStream in) throws IOException
|
||||
{
|
||||
try(final IonInput inp = new IonInput(in)) {
|
||||
try (final IonInput inp = new IonInput(in)) {
|
||||
return (T) inp.readObject();
|
||||
}
|
||||
}
|
||||
@@ -290,7 +284,7 @@ public class Ion {
|
||||
*/
|
||||
public static void toStream(OutputStream out, Object obj) throws IOException
|
||||
{
|
||||
try(IonOutput iout = new IonOutput(out)) {
|
||||
try (IonOutput iout = new IonOutput(out)) {
|
||||
iout.writeObject(obj);
|
||||
}
|
||||
}
|
||||
@@ -496,7 +490,6 @@ public class Ion {
|
||||
{
|
||||
final List<Integer> toRemove = new ArrayList<>();
|
||||
|
||||
|
||||
// remove direct
|
||||
for (final Integer mark : markToClass.keySet()) {
|
||||
if (!isMarkReserved(mark)) {
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
package mightypork.utils.ion;
|
||||
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.DataInput;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
@@ -29,14 +22,12 @@ public class IonInput implements Closeable {
|
||||
|
||||
|
||||
@SuppressWarnings("resource")
|
||||
public IonInput(File inFile) throws FileNotFoundException
|
||||
{
|
||||
public IonInput(File inFile) throws FileNotFoundException {
|
||||
this(new FileInputStream(inFile));
|
||||
}
|
||||
|
||||
|
||||
public IonInput(InputStream in)
|
||||
{
|
||||
public IonInput(InputStream in) {
|
||||
this.stream = in;
|
||||
this.in = new DataInputStream(in);
|
||||
}
|
||||
@@ -300,7 +291,6 @@ public class IonInput implements Closeable {
|
||||
{
|
||||
final int mark = readMark();
|
||||
|
||||
|
||||
try {
|
||||
|
||||
if (Ion.isMarkForBinary(mark)) {
|
||||
@@ -308,7 +298,6 @@ public class IonInput implements Closeable {
|
||||
|
||||
loaded = (IonBinary) Ion.getClassForMark(mark).newInstance();
|
||||
|
||||
|
||||
loaded.load(this);
|
||||
return loaded;
|
||||
}
|
||||
|
||||
@@ -12,14 +12,12 @@ class IonMapWrapper implements IonBinary {
|
||||
private final Map map;
|
||||
|
||||
|
||||
public IonMapWrapper()
|
||||
{
|
||||
public IonMapWrapper() {
|
||||
map = new LinkedHashMap<>();
|
||||
}
|
||||
|
||||
|
||||
public IonMapWrapper(Map saved)
|
||||
{
|
||||
public IonMapWrapper(Map saved) {
|
||||
map = saved;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
package mightypork.utils.ion;
|
||||
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.DataOutput;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.*;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
@@ -26,14 +19,12 @@ public class IonOutput implements Closeable {
|
||||
|
||||
|
||||
@SuppressWarnings("resource")
|
||||
public IonOutput(File outFile) throws FileNotFoundException
|
||||
{
|
||||
public IonOutput(File outFile) throws FileNotFoundException {
|
||||
this(new FileOutputStream(outFile));
|
||||
}
|
||||
|
||||
|
||||
public IonOutput(OutputStream out)
|
||||
{
|
||||
public IonOutput(OutputStream out) {
|
||||
this.stream = out;
|
||||
this.out = new DataOutputStream(out);
|
||||
}
|
||||
@@ -299,7 +290,6 @@ public class IonOutput implements Closeable {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (Ion.isObjectIndirectBundled(obj)) {
|
||||
final IonizerBundled<?> ionizer = Ion.getIonizerBundledForClass(obj.getClass());
|
||||
|
||||
|
||||
@@ -12,14 +12,12 @@ class IonSequenceWrapper implements IonBinary {
|
||||
private Collection collection = new ArrayList();
|
||||
|
||||
|
||||
public IonSequenceWrapper()
|
||||
{
|
||||
public IonSequenceWrapper() {
|
||||
collection = new ArrayList();
|
||||
}
|
||||
|
||||
|
||||
public IonSequenceWrapper(Collection saved)
|
||||
{
|
||||
public IonSequenceWrapper(Collection saved) {
|
||||
collection = saved;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package mightypork.utils.ion;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
@@ -13,16 +14,18 @@ import java.io.IOException;
|
||||
public abstract class IonizerBinary<T> {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
final void _save(Object object, IonOutput out) throws IOException{
|
||||
save((T)object, out);
|
||||
final void _save(Object object, IonOutput out) throws IOException
|
||||
{
|
||||
save((T) object, out);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Save an object to ion output
|
||||
*
|
||||
* @param object object to save
|
||||
* @param out ion output
|
||||
* @throws IOException
|
||||
* @throws IOException
|
||||
*/
|
||||
public abstract void save(T object, IonOutput out) throws IOException;
|
||||
|
||||
|
||||
@@ -11,10 +11,12 @@ package mightypork.utils.ion;
|
||||
public abstract class IonizerBundled<T> {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
final void _save(Object object, IonDataBundle out) {
|
||||
save((T)object, out);
|
||||
final void _save(Object object, IonDataBundle out)
|
||||
{
|
||||
save((T) object, out);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Save an object to data bundle
|
||||
*
|
||||
|
||||
@@ -32,8 +32,7 @@ public class ArchivingLog extends SimpleLog {
|
||||
* @param file log file (in log directory)
|
||||
* @param oldLogCount number of old log files to keep: -1 all, 0 none.
|
||||
*/
|
||||
public ArchivingLog(String name, File file, int oldLogCount)
|
||||
{
|
||||
public ArchivingLog(String name, File file, int oldLogCount) {
|
||||
super(name, file);
|
||||
this.logs_to_keep = oldLogCount;
|
||||
}
|
||||
@@ -45,8 +44,7 @@ public class ArchivingLog extends SimpleLog {
|
||||
* @param name log name
|
||||
* @param file log file (in log directory)
|
||||
*/
|
||||
public ArchivingLog(String name, File file)
|
||||
{
|
||||
public ArchivingLog(String name, File file) {
|
||||
super(name, file);
|
||||
this.logs_to_keep = 5;
|
||||
}
|
||||
@@ -64,7 +62,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());
|
||||
@@ -87,7 +85,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
|
||||
|
||||
@@ -48,8 +48,7 @@ public class SimpleLog implements LogWriter {
|
||||
private final long started_ms;
|
||||
|
||||
|
||||
public SimpleLog(String name, File file)
|
||||
{
|
||||
public SimpleLog(String name, File file) {
|
||||
this.name = name;
|
||||
this.file = file;
|
||||
this.started_ms = System.currentTimeMillis();
|
||||
|
||||
@@ -18,8 +18,7 @@ import mightypork.utils.math.constraints.vect.Vect;
|
||||
*/
|
||||
public final class Calc {
|
||||
|
||||
private Calc()
|
||||
{
|
||||
private Calc() {
|
||||
// not instantiable
|
||||
}
|
||||
|
||||
|
||||
@@ -26,8 +26,7 @@ public class Polar {
|
||||
* @param angle angle in RAD
|
||||
* @param distance distance from origin
|
||||
*/
|
||||
public Polar(double angle, double distance)
|
||||
{
|
||||
public Polar(double angle, double distance) {
|
||||
this(angle, false, distance);
|
||||
}
|
||||
|
||||
@@ -39,8 +38,7 @@ public class Polar {
|
||||
* @param deg angle is in DEG
|
||||
* @param distance radius
|
||||
*/
|
||||
public Polar(double angle, boolean deg, double distance)
|
||||
{
|
||||
public Polar(double angle, boolean deg, double distance) {
|
||||
this.radius = distance;
|
||||
this.angle = deg ? Math.toRadians(angle) : angle;
|
||||
}
|
||||
|
||||
@@ -23,8 +23,7 @@ public class Range {
|
||||
/**
|
||||
* Implicit range constructor 0-1
|
||||
*/
|
||||
public Range()
|
||||
{
|
||||
public Range() {
|
||||
}
|
||||
|
||||
|
||||
@@ -34,8 +33,7 @@ public class Range {
|
||||
* @param min min number
|
||||
* @param max max number
|
||||
*/
|
||||
public Range(double min, double max)
|
||||
{
|
||||
public Range(double min, double max) {
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
norm();
|
||||
@@ -47,8 +45,7 @@ public class Range {
|
||||
*
|
||||
* @param minmax min = max number
|
||||
*/
|
||||
public Range(double minmax)
|
||||
{
|
||||
public Range(double minmax) {
|
||||
this.min = minmax;
|
||||
this.max = minmax;
|
||||
}
|
||||
|
||||
@@ -39,22 +39,19 @@ public class Coord {
|
||||
}
|
||||
|
||||
|
||||
public Coord()
|
||||
{
|
||||
public Coord() {
|
||||
// for ion
|
||||
}
|
||||
|
||||
|
||||
public Coord(int x, int y)
|
||||
{
|
||||
public Coord(int x, int y) {
|
||||
super();
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
|
||||
public Coord(Coord other)
|
||||
{
|
||||
public Coord(Coord other) {
|
||||
this.x = other.x;
|
||||
this.y = other.y;
|
||||
}
|
||||
|
||||
@@ -32,10 +32,9 @@ public class Move {
|
||||
|
||||
private final byte x;
|
||||
private final byte y;
|
||||
|
||||
|
||||
public Move(int x, int y)
|
||||
{
|
||||
|
||||
public Move(int x, int y) {
|
||||
this.x = (byte) (x < 0 ? -1 : x > 0 ? 1 : 0);
|
||||
this.y = (byte) (y < 0 ? -1 : y > 0 ? 1 : 0);
|
||||
}
|
||||
|
||||
@@ -100,7 +100,6 @@ public abstract class PathFinder {
|
||||
a.h_cost = (int) (heuristic.getCost(a.pos, end) * getMinCost());
|
||||
a.parent = current;
|
||||
|
||||
|
||||
if (!closed.contains(a)) {
|
||||
|
||||
if (open.contains(a)) {
|
||||
@@ -152,8 +151,7 @@ public abstract class PathFinder {
|
||||
Node parent;
|
||||
|
||||
|
||||
public Node(Coord pos)
|
||||
{
|
||||
public Node(Coord pos) {
|
||||
this.pos = pos;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,8 +18,7 @@ public class PathFinderProxy extends PathFinder {
|
||||
private final PathFinder source;
|
||||
|
||||
|
||||
public PathFinderProxy(PathFinder other)
|
||||
{
|
||||
public PathFinderProxy(PathFinder other) {
|
||||
this.source = other;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,26 +17,22 @@ public abstract class Animator implements NumBound, Updateable, Pauseable {
|
||||
private final double lowValue;
|
||||
|
||||
|
||||
public Animator(double period)
|
||||
{
|
||||
public Animator(double period) {
|
||||
this(0, 1, period, Easing.LINEAR);
|
||||
}
|
||||
|
||||
|
||||
public Animator(double start, double end, double period)
|
||||
{
|
||||
public Animator(double start, double end, double period) {
|
||||
this(start, end, period, Easing.LINEAR);
|
||||
}
|
||||
|
||||
|
||||
public Animator(double period, Easing easing)
|
||||
{
|
||||
public Animator(double period, Easing easing) {
|
||||
this(0, 1, period, easing);
|
||||
}
|
||||
|
||||
|
||||
public Animator(double start, double end, double period, Easing easing)
|
||||
{
|
||||
public Animator(double start, double end, double period, Easing easing) {
|
||||
numAnim = new NumAnimated(0, easing);
|
||||
numAnim.setDefaultDuration(period);
|
||||
|
||||
|
||||
@@ -11,26 +11,22 @@ public class AnimatorBounce extends Animator {
|
||||
private boolean wasUp = false;
|
||||
|
||||
|
||||
public AnimatorBounce(double start, double end, double period, Easing easing)
|
||||
{
|
||||
public AnimatorBounce(double start, double end, double period, Easing easing) {
|
||||
super(start, end, period, easing);
|
||||
}
|
||||
|
||||
|
||||
public AnimatorBounce(double start, double end, double period)
|
||||
{
|
||||
public AnimatorBounce(double start, double end, double period) {
|
||||
super(start, end, period);
|
||||
}
|
||||
|
||||
|
||||
public AnimatorBounce(double period, Easing easing)
|
||||
{
|
||||
public AnimatorBounce(double period, Easing easing) {
|
||||
super(period, easing);
|
||||
}
|
||||
|
||||
|
||||
public AnimatorBounce(double period)
|
||||
{
|
||||
public AnimatorBounce(double period) {
|
||||
super(period);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,26 +9,22 @@ package mightypork.utils.math.animation;
|
||||
*/
|
||||
public class AnimatorRewind extends Animator {
|
||||
|
||||
public AnimatorRewind(double start, double end, double period, Easing easing)
|
||||
{
|
||||
public AnimatorRewind(double start, double end, double period, Easing easing) {
|
||||
super(start, end, period, easing);
|
||||
}
|
||||
|
||||
|
||||
public AnimatorRewind(double start, double end, double period)
|
||||
{
|
||||
public AnimatorRewind(double start, double end, double period) {
|
||||
super(start, end, period);
|
||||
}
|
||||
|
||||
|
||||
public AnimatorRewind(double period, Easing easing)
|
||||
{
|
||||
public AnimatorRewind(double period, Easing easing) {
|
||||
super(period, easing);
|
||||
}
|
||||
|
||||
|
||||
public AnimatorRewind(double period)
|
||||
{
|
||||
public AnimatorRewind(double period) {
|
||||
super(period);
|
||||
}
|
||||
|
||||
|
||||
@@ -67,8 +67,7 @@ public abstract class Easing {
|
||||
/**
|
||||
* @param in Easing to reverse
|
||||
*/
|
||||
public Reverse(Easing in)
|
||||
{
|
||||
public Reverse(Easing in) {
|
||||
this.ea = in;
|
||||
}
|
||||
|
||||
@@ -97,8 +96,7 @@ public abstract class Easing {
|
||||
* @param in initial EasingFunction
|
||||
* @param out terminal EasingFunction
|
||||
*/
|
||||
public Composite(Easing in, Easing out)
|
||||
{
|
||||
public Composite(Easing in, Easing out) {
|
||||
this.in = in;
|
||||
this.out = out;
|
||||
}
|
||||
|
||||
@@ -45,8 +45,7 @@ public class NumAnimated extends NumMutable implements Updateable, Pauseable {
|
||||
*
|
||||
* @param value initial value
|
||||
*/
|
||||
public NumAnimated(double value)
|
||||
{
|
||||
public NumAnimated(double value) {
|
||||
setTo(value);
|
||||
}
|
||||
|
||||
@@ -57,8 +56,7 @@ public class NumAnimated extends NumMutable implements Updateable, Pauseable {
|
||||
* @param value initial value
|
||||
* @param easing easing function
|
||||
*/
|
||||
public NumAnimated(double value, Easing easing)
|
||||
{
|
||||
public NumAnimated(double value, Easing easing) {
|
||||
this(value);
|
||||
setEasing(easing);
|
||||
}
|
||||
@@ -71,8 +69,7 @@ public class NumAnimated extends NumMutable implements Updateable, Pauseable {
|
||||
* @param easingIn easing function (fade in)
|
||||
* @param easingOut easing function (fade out)
|
||||
*/
|
||||
public NumAnimated(double value, Easing easingIn, Easing easingOut)
|
||||
{
|
||||
public NumAnimated(double value, Easing easingIn, Easing easingOut) {
|
||||
this(value);
|
||||
setEasing(easingIn, easingOut);
|
||||
}
|
||||
@@ -85,8 +82,7 @@ public class NumAnimated extends NumMutable implements Updateable, Pauseable {
|
||||
* @param easing easing function
|
||||
* @param defaultDuration default fade duration
|
||||
*/
|
||||
public NumAnimated(double value, Easing easing, double defaultDuration)
|
||||
{
|
||||
public NumAnimated(double value, Easing easing, double defaultDuration) {
|
||||
this(value);
|
||||
setEasing(easing);
|
||||
setDefaultDuration(defaultDuration);
|
||||
@@ -101,8 +97,7 @@ public class NumAnimated extends NumMutable implements Updateable, Pauseable {
|
||||
* @param easingOut easing function (fade out)
|
||||
* @param defaultDuration default fade duration
|
||||
*/
|
||||
public NumAnimated(double value, Easing easingIn, Easing easingOut, double defaultDuration)
|
||||
{
|
||||
public NumAnimated(double value, Easing easingIn, Easing easingOut, double defaultDuration) {
|
||||
this(value);
|
||||
setEasing(easingIn, easingOut);
|
||||
setDefaultDuration(defaultDuration);
|
||||
@@ -114,8 +109,7 @@ public class NumAnimated extends NumMutable implements Updateable, Pauseable {
|
||||
*
|
||||
* @param other other animator
|
||||
*/
|
||||
public NumAnimated(NumAnimated other)
|
||||
{
|
||||
public NumAnimated(NumAnimated other) {
|
||||
setTo(other);
|
||||
}
|
||||
|
||||
|
||||
@@ -12,20 +12,17 @@ import mightypork.utils.math.angles.Deg;
|
||||
*/
|
||||
public class NumAnimatedDeg extends NumAnimated {
|
||||
|
||||
public NumAnimatedDeg(NumAnimated other)
|
||||
{
|
||||
public NumAnimatedDeg(NumAnimated other) {
|
||||
super(other);
|
||||
}
|
||||
|
||||
|
||||
public NumAnimatedDeg(double value)
|
||||
{
|
||||
public NumAnimatedDeg(double value) {
|
||||
super(value);
|
||||
}
|
||||
|
||||
|
||||
public NumAnimatedDeg(double value, Easing easing)
|
||||
{
|
||||
public NumAnimatedDeg(double value, Easing easing) {
|
||||
super(value, easing);
|
||||
}
|
||||
|
||||
|
||||
@@ -12,20 +12,17 @@ import mightypork.utils.math.angles.Rad;
|
||||
*/
|
||||
public class NumAnimatedRad extends NumAnimated {
|
||||
|
||||
public NumAnimatedRad(NumAnimated other)
|
||||
{
|
||||
public NumAnimatedRad(NumAnimated other) {
|
||||
super(other);
|
||||
}
|
||||
|
||||
|
||||
public NumAnimatedRad(double value)
|
||||
{
|
||||
public NumAnimatedRad(double value) {
|
||||
super(value);
|
||||
}
|
||||
|
||||
|
||||
public NumAnimatedRad(double value, Easing easing)
|
||||
{
|
||||
public NumAnimatedRad(double value, Easing easing) {
|
||||
super(value, easing);
|
||||
}
|
||||
|
||||
|
||||
@@ -27,8 +27,7 @@ public class VectAnimated extends VectMutable implements Pauseable, Updateable {
|
||||
* @param y y animator
|
||||
* @param z z animator
|
||||
*/
|
||||
public VectAnimated(NumAnimated x, NumAnimated y, NumAnimated z)
|
||||
{
|
||||
public VectAnimated(NumAnimated x, NumAnimated y, NumAnimated z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
@@ -41,8 +40,7 @@ public class VectAnimated extends VectMutable implements Pauseable, Updateable {
|
||||
* @param start initial positioon
|
||||
* @param easing animation easing
|
||||
*/
|
||||
public VectAnimated(Vect start, Easing easing)
|
||||
{
|
||||
public VectAnimated(Vect start, Easing easing) {
|
||||
x = new NumAnimated(start.x(), easing);
|
||||
y = new NumAnimated(start.y(), easing);
|
||||
z = new NumAnimated(start.z(), easing);
|
||||
|
||||
@@ -10,8 +10,7 @@ public class ColorAlphaAdjuster extends Color {
|
||||
private final Num alphaAdjust;
|
||||
|
||||
|
||||
public ColorAlphaAdjuster(Color source, Num alphaMul)
|
||||
{
|
||||
public ColorAlphaAdjuster(Color source, Num alphaMul) {
|
||||
this.source = source;
|
||||
this.alphaAdjust = alphaMul;
|
||||
}
|
||||
|
||||
@@ -12,8 +12,7 @@ public class ColorHsb extends Color {
|
||||
private final Num a;
|
||||
|
||||
|
||||
public ColorHsb(Num h, Num s, Num b, Num a)
|
||||
{
|
||||
public ColorHsb(Num h, Num s, Num b, Num a) {
|
||||
this.h = h;
|
||||
this.s = s;
|
||||
this.b = b;
|
||||
|
||||
@@ -12,8 +12,7 @@ public class ColorRgb extends Color {
|
||||
private final Num a;
|
||||
|
||||
|
||||
public ColorRgb(Num r, Num g, Num b, Num a)
|
||||
{
|
||||
public ColorRgb(Num r, Num g, Num b, Num a) {
|
||||
this.r = r;
|
||||
this.g = g;
|
||||
this.b = b;
|
||||
|
||||
@@ -21,7 +21,6 @@ public class RGB {
|
||||
public static final Color BLACK_80 = Color.rgba(0, 0, 0, 0.8);
|
||||
public static final Color BLACK_90 = Color.rgba(0, 0, 0, 0.9);
|
||||
|
||||
|
||||
public static final Color WHITE = Color.fromHex(0xFFFFFF);
|
||||
public static final Color BLACK = Color.fromHex(0x000000);
|
||||
public static final Color GRAY_DARK = Color.fromHex(0x808080);
|
||||
|
||||
@@ -17,14 +17,12 @@ public class NumConst extends Num {
|
||||
private NumDigest digest;
|
||||
|
||||
|
||||
NumConst(Num copied)
|
||||
{
|
||||
NumConst(Num copied) {
|
||||
this.value = copied.value();
|
||||
}
|
||||
|
||||
|
||||
NumConst(double value)
|
||||
{
|
||||
NumConst(double value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
|
||||
@@ -25,8 +25,7 @@ public abstract class AbstractNumCache extends NumAdapter implements CachedConst
|
||||
private boolean cachingEnabled = true;
|
||||
|
||||
|
||||
public AbstractNumCache()
|
||||
{
|
||||
public AbstractNumCache() {
|
||||
enableDigestCaching(true); // it changes only on poll
|
||||
}
|
||||
|
||||
|
||||
@@ -14,8 +14,7 @@ public class NumCache extends AbstractNumCache {
|
||||
private final Num source;
|
||||
|
||||
|
||||
public NumCache(Num source)
|
||||
{
|
||||
public NumCache(Num source) {
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,8 +9,7 @@ public class NumDigest {
|
||||
public final double value;
|
||||
|
||||
|
||||
public NumDigest(Num num)
|
||||
{
|
||||
public NumDigest(Num num) {
|
||||
this.value = num.value();
|
||||
}
|
||||
|
||||
|
||||
@@ -16,13 +16,11 @@ public class NumProxy extends NumAdapter implements PluggableNumBound {
|
||||
private NumBound backing = null;
|
||||
|
||||
|
||||
public NumProxy()
|
||||
{
|
||||
public NumProxy() {
|
||||
}
|
||||
|
||||
|
||||
public NumProxy(NumBound bound)
|
||||
{
|
||||
public NumProxy(NumBound bound) {
|
||||
backing = bound;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,14 +14,12 @@ public class NumVar extends NumMutable {
|
||||
private double value;
|
||||
|
||||
|
||||
public NumVar(Num value)
|
||||
{
|
||||
public NumVar(Num value) {
|
||||
this(value.value());
|
||||
}
|
||||
|
||||
|
||||
public NumVar(double value)
|
||||
{
|
||||
public NumVar(double value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
|
||||
@@ -1058,5 +1058,4 @@ public abstract class Rect implements RectBound, CachedDigestable<RectDigest> {
|
||||
return ((rw < rx || rw > tx) && (rh < ry || rh > ty) && (tw < tx || tw > rx) && (th < ty || th > ry));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -50,8 +50,7 @@ public class RectConst extends Rect {
|
||||
* @param width
|
||||
* @param height
|
||||
*/
|
||||
RectConst(double x, double y, double width, double height)
|
||||
{
|
||||
RectConst(double x, double y, double width, double height) {
|
||||
this.pos = Vect.make(x, y);
|
||||
this.size = Vect.make(width, height);
|
||||
}
|
||||
@@ -63,8 +62,7 @@ public class RectConst extends Rect {
|
||||
* @param origin
|
||||
* @param size
|
||||
*/
|
||||
RectConst(Vect origin, Vect size)
|
||||
{
|
||||
RectConst(Vect origin, Vect size) {
|
||||
this.pos = origin.freeze();
|
||||
this.size = size.freeze();
|
||||
}
|
||||
@@ -75,8 +73,7 @@ public class RectConst extends Rect {
|
||||
*
|
||||
* @param another other coord
|
||||
*/
|
||||
RectConst(Rect another)
|
||||
{
|
||||
RectConst(Rect another) {
|
||||
this.pos = another.origin().freeze();
|
||||
this.size = another.size().freeze();
|
||||
}
|
||||
|
||||
@@ -23,8 +23,7 @@ public class TiledRect extends RectProxy {
|
||||
private Rect aTile;
|
||||
|
||||
|
||||
public TiledRect(Rect source, int horizontal, int vertical)
|
||||
{
|
||||
public TiledRect(Rect source, int horizontal, int vertical) {
|
||||
super(source);
|
||||
this.tilesX = horizontal;
|
||||
this.tilesY = vertical;
|
||||
|
||||
@@ -25,8 +25,7 @@ public abstract class AbstractRectCache extends RectAdapter implements CachedCon
|
||||
private boolean cachingEnabled = true;
|
||||
|
||||
|
||||
public AbstractRectCache()
|
||||
{
|
||||
public AbstractRectCache() {
|
||||
enableDigestCaching(true); // it changes only on poll
|
||||
}
|
||||
|
||||
|
||||
@@ -14,8 +14,7 @@ public class RectCache extends AbstractRectCache {
|
||||
private final Rect source;
|
||||
|
||||
|
||||
public RectCache(Rect source)
|
||||
{
|
||||
public RectCache(Rect source) {
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,8 +17,7 @@ public class RectDigest {
|
||||
public final double bottom;
|
||||
|
||||
|
||||
public RectDigest(Rect rect)
|
||||
{
|
||||
public RectDigest(Rect rect) {
|
||||
this.x = rect.origin().x();
|
||||
this.y = rect.origin().y();
|
||||
|
||||
@@ -35,7 +34,6 @@ public class RectDigest {
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return String
|
||||
.format("Rect{ at: (%.1f, %.1f), size: (%.1f, %.1f), bounds: L %.1f R %.1f T %.1f B %.1f }", x, y, width, height, left, right, top, bottom);
|
||||
return String.format("Rect{ at: (%.1f, %.1f), size: (%.1f, %.1f), bounds: L %.1f R %.1f T %.1f B %.1f }", x, y, width, height, left, right, top, bottom);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,13 +16,11 @@ public class RectProxy extends RectAdapter implements PluggableRectBound {
|
||||
private RectBound backing = null;
|
||||
|
||||
|
||||
public RectProxy()
|
||||
{
|
||||
public RectProxy() {
|
||||
}
|
||||
|
||||
|
||||
public RectProxy(RectBound proxied)
|
||||
{
|
||||
public RectProxy(RectBound proxied) {
|
||||
backing = proxied;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,8 +16,7 @@ public class RectVectAdapter extends Rect {
|
||||
private final Vect size;
|
||||
|
||||
|
||||
public RectVectAdapter(Vect origin, Vect size)
|
||||
{
|
||||
public RectVectAdapter(Vect origin, Vect size) {
|
||||
this.origin = origin;
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
@@ -19,8 +19,7 @@ public class RectVar extends RectMutable {
|
||||
* @param width
|
||||
* @param height
|
||||
*/
|
||||
public RectVar(double x, double y, double width, double height)
|
||||
{
|
||||
public RectVar(double x, double y, double width, double height) {
|
||||
this.pos.setTo(x, y);
|
||||
this.size.setTo(width, height);
|
||||
}
|
||||
|
||||
@@ -32,14 +32,12 @@ public final class VectConst extends Vect {
|
||||
private VectDigest digest;
|
||||
|
||||
|
||||
VectConst(Vect other)
|
||||
{
|
||||
VectConst(Vect other) {
|
||||
this(other.x(), other.y(), other.z());
|
||||
}
|
||||
|
||||
|
||||
VectConst(double x, double y, double z)
|
||||
{
|
||||
VectConst(double x, double y, double z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
|
||||
@@ -25,8 +25,7 @@ public abstract class AbstractVectCache extends VectAdapter implements CachedCon
|
||||
private boolean cachingEnabled = true;
|
||||
|
||||
|
||||
public AbstractVectCache()
|
||||
{
|
||||
public AbstractVectCache() {
|
||||
enableDigestCaching(true); // it changes only on poll
|
||||
}
|
||||
|
||||
|
||||
@@ -14,8 +14,7 @@ public class VectCache extends AbstractVectCache {
|
||||
private final Vect source;
|
||||
|
||||
|
||||
public VectCache(Vect source)
|
||||
{
|
||||
public VectCache(Vect source) {
|
||||
this.source = source;
|
||||
enableDigestCaching(true);
|
||||
}
|
||||
|
||||
@@ -11,8 +11,7 @@ public class VectDigest {
|
||||
public final double z;
|
||||
|
||||
|
||||
public VectDigest(Vect vect)
|
||||
{
|
||||
public VectDigest(Vect vect) {
|
||||
this.x = vect.x();
|
||||
this.y = vect.y();
|
||||
this.z = vect.z();
|
||||
|
||||
@@ -18,16 +18,14 @@ public class VectNumAdapter extends Vect {
|
||||
private final Num constrZ;
|
||||
|
||||
|
||||
public VectNumAdapter(Num x, Num y, Num z)
|
||||
{
|
||||
public VectNumAdapter(Num x, Num y, Num z) {
|
||||
this.constrX = x;
|
||||
this.constrY = y;
|
||||
this.constrZ = z;
|
||||
}
|
||||
|
||||
|
||||
public VectNumAdapter(Num x, Num y)
|
||||
{
|
||||
public VectNumAdapter(Num x, Num y) {
|
||||
this.constrX = x;
|
||||
this.constrY = y;
|
||||
this.constrZ = Num.ZERO;
|
||||
|
||||
@@ -16,13 +16,11 @@ public class VectProxy extends VectAdapter implements PluggableVectBound {
|
||||
private VectBound backing = null;
|
||||
|
||||
|
||||
public VectProxy()
|
||||
{
|
||||
public VectProxy() {
|
||||
}
|
||||
|
||||
|
||||
public VectProxy(VectBound proxied)
|
||||
{
|
||||
public VectProxy(VectBound proxied) {
|
||||
backing = proxied;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,8 +17,7 @@ public class VectVar extends VectMutable {
|
||||
* @param y Y coordinate
|
||||
* @param z Z coordinate
|
||||
*/
|
||||
public VectVar(double x, double y, double z)
|
||||
{
|
||||
public VectVar(double x, double y, double z) {
|
||||
super();
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
|
||||
@@ -27,8 +27,7 @@ public class NoiseGen {
|
||||
* @param middle middle bound ("surface")
|
||||
* @param high high bound ("hill")
|
||||
*/
|
||||
public NoiseGen(double density, double low, double middle, double high)
|
||||
{
|
||||
public NoiseGen(double density, double low, double middle, double high) {
|
||||
this(density, low, middle, high, Double.doubleToLongBits(Math.random()));
|
||||
}
|
||||
|
||||
@@ -42,8 +41,7 @@ public class NoiseGen {
|
||||
* @param high high bound ("hill")
|
||||
* @param seed random seed to use
|
||||
*/
|
||||
public NoiseGen(double density, double low, double middle, double high, long seed)
|
||||
{
|
||||
public NoiseGen(double density, double low, double middle, double high, long seed) {
|
||||
if (low > middle || middle > high) throw new IllegalArgumentException("Invalid value range.");
|
||||
|
||||
this.density = density;
|
||||
|
||||
@@ -60,8 +60,7 @@ public class PerlinNoiseGenerator {
|
||||
/**
|
||||
* Create a new noise creator with the default seed value
|
||||
*/
|
||||
public PerlinNoiseGenerator()
|
||||
{
|
||||
public PerlinNoiseGenerator() {
|
||||
this(DEFAULT_SEED);
|
||||
}
|
||||
|
||||
@@ -71,8 +70,7 @@ public class PerlinNoiseGenerator {
|
||||
*
|
||||
* @param seed The seed value to use
|
||||
*/
|
||||
public PerlinNoiseGenerator(long seed)
|
||||
{
|
||||
public PerlinNoiseGenerator(long seed) {
|
||||
p_imp = new int[DEFAULT_SAMPLE_SIZE << 1];
|
||||
|
||||
int i, j, k;
|
||||
@@ -410,10 +408,7 @@ public class PerlinNoiseGenerator {
|
||||
*/
|
||||
public double tileableNoise3(double x, double y, double z, double w, double h, double d)
|
||||
{
|
||||
return (noise3(x, y, z) * (w - x) * (h - y) * (d - z) + noise3(x - w, y, z) * x * (h - y) * (d - z) + noise3(x, y - h, z) * (w - x) * y * (d - z)
|
||||
+ noise3(x - w, y - h, z) * x * y * (d - z) + noise3(x, y, z - d) * (w - x) * (h - y) * z + noise3(x - w, y, z - d) * x * (h - y) * z
|
||||
+ noise3(x, y - h, z - d) * (w - x) * y * z + noise3(x - w, y - h, z - d) * x * y * z)
|
||||
/ (w * h * d);
|
||||
return (noise3(x, y, z) * (w - x) * (h - y) * (d - z) + noise3(x - w, y, z) * x * (h - y) * (d - z) + noise3(x, y - h, z) * (w - x) * y * (d - z) + noise3(x - w, y - h, z) * x * y * (d - z) + noise3(x, y, z - d) * (w - x) * (h - y) * z + noise3(x - w, y, z - d) * x * (h - y) * z + noise3(x, y - h, z - d) * (w - x) * y * z + noise3(x - w, y - h, z - d) * x * y * z) / (w * h * d);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package mightypork.utils.math.timing;
|
||||
|
||||
|
||||
import mightypork.utils.Support;
|
||||
|
||||
|
||||
|
||||
@@ -11,8 +11,7 @@ public abstract class TaskRepeater extends AnimatorRewind implements Runnable, E
|
||||
private boolean enabled = true;
|
||||
|
||||
|
||||
public TaskRepeater(double period)
|
||||
{
|
||||
public TaskRepeater(double period) {
|
||||
super(period);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,8 +16,7 @@ public class TimerDelta {
|
||||
/**
|
||||
* New delta timer
|
||||
*/
|
||||
public TimerDelta()
|
||||
{
|
||||
public TimerDelta() {
|
||||
lastFrame = System.nanoTime();
|
||||
}
|
||||
|
||||
|
||||
@@ -22,8 +22,7 @@ public class TimerFps {
|
||||
*
|
||||
* @param fps target FPS
|
||||
*/
|
||||
public TimerFps(long fps)
|
||||
{
|
||||
public TimerFps(long fps) {
|
||||
FRAME = Math.round(SECOND / (double) fps);
|
||||
|
||||
lastFrame = System.nanoTime();
|
||||
|
||||
@@ -11,8 +11,7 @@ public class StringWrapper implements StringProvider {
|
||||
private final String value;
|
||||
|
||||
|
||||
public StringWrapper(String value)
|
||||
{
|
||||
public StringWrapper(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,8 +6,7 @@ public class CharFilterRegex implements CharFilter {
|
||||
private final String formula;
|
||||
|
||||
|
||||
public CharFilterRegex(String regex)
|
||||
{
|
||||
public CharFilterRegex(String regex) {
|
||||
this.formula = regex;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,8 +6,7 @@ public class CharFilterWhitelist implements CharFilter {
|
||||
private final String whitelist;
|
||||
|
||||
|
||||
public CharFilterWhitelist(String allowed)
|
||||
{
|
||||
public CharFilterWhitelist(String allowed) {
|
||||
this.whitelist = allowed;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,8 +18,7 @@ public class Mutable<T> {
|
||||
*
|
||||
* @param o value
|
||||
*/
|
||||
public Mutable(T o)
|
||||
{
|
||||
public Mutable(T o) {
|
||||
this.o = o;
|
||||
}
|
||||
|
||||
|
||||
@@ -28,8 +28,7 @@ public class Pair<T1, T2> {
|
||||
* @param first 1st object
|
||||
* @param second 2nd object
|
||||
*/
|
||||
public Pair(T1 first, T2 second)
|
||||
{
|
||||
public Pair(T1 first, T2 second) {
|
||||
this.first = first;
|
||||
this.second = second;
|
||||
}
|
||||
|
||||
@@ -25,8 +25,7 @@ public class Triad<T1, T2, T3> extends Pair<T1, T2> {
|
||||
* @param objB 2nd object
|
||||
* @param objC 3rd object
|
||||
*/
|
||||
public Triad(T1 objA, T2 objB, T3 objC)
|
||||
{
|
||||
public Triad(T1 objA, T2 objB, T3 objC) {
|
||||
super(objA, objB);
|
||||
third = objC;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user