diff --git a/src/resources/Posture.java b/src/resources/Posture.java index dcc249b66..9b8479784 100644 --- a/src/resources/Posture.java +++ b/src/resources/Posture.java @@ -27,8 +27,8 @@ ***********************************************************************************/ package resources; +import java.util.Hashtable; import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; public enum Posture { UPRIGHT (0x00), @@ -48,12 +48,14 @@ public enum Posture { DEAD (0x0E), INVALID (0x0E); - private static final Map POSTURE_MAP = new ConcurrentHashMap(); + private static final Map POSTURE_MAP = new Hashtable(15); private byte id; static { - for (Posture p : values()) - POSTURE_MAP.put(p.getId(), p); + for (Posture p : values()) { + if (p != INVALID) + POSTURE_MAP.put(p.getId(), p); + } } Posture(int id) { @@ -63,7 +65,10 @@ public enum Posture { public byte getId() { return id; } public static final Posture getFromId(byte id) { - Posture p = POSTURE_MAP.get(id); + Posture p = null; + synchronized (POSTURE_MAP) { + p = POSTURE_MAP.get(id); + } if (p == null) return INVALID; return p; diff --git a/src/resources/SortedLinkedList.java b/src/resources/SortedLinkedList.java index 17529e33f..a1e335240 100644 --- a/src/resources/SortedLinkedList.java +++ b/src/resources/SortedLinkedList.java @@ -34,18 +34,13 @@ import java.util.ListIterator; public class SortedLinkedList> extends LinkedList { private static final long serialVersionUID = -6776628467181994889L; - - public SortedLinkedList() { - - } - + @Override public boolean add(E e) { - Comparable element = (Comparable) e; - ListIterator iter = listIterator(); + ListIterator iter = super.listIterator(); + while (iter.hasNext()) { - E item = iter.next(); - if (element.compareTo(item) <= 0) { + if (e.compareTo(iter.next()) <= 0) { iter.previous(); iter.add(e); return true; @@ -65,6 +60,7 @@ public class SortedLinkedList> extends LinkedList { for (E item : c) { add(item); } + return true; } diff --git a/src/resources/server_info/RelationalDatabase.java b/src/resources/server_info/RelationalDatabase.java index 451f72bf7..247039243 100644 --- a/src/resources/server_info/RelationalDatabase.java +++ b/src/resources/server_info/RelationalDatabase.java @@ -35,7 +35,7 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; -public class RelationalDatabase { +public abstract class RelationalDatabase { private DatabaseMetaData metaData; private Connection connection; diff --git a/src/resources/utilities/Scripts.java b/src/resources/utilities/Scripts.java index 7d9fe337a..204721a4b 100644 --- a/src/resources/utilities/Scripts.java +++ b/src/resources/utilities/Scripts.java @@ -35,54 +35,20 @@ import org.python.util.PythonInterpreter; public final class Scripts { private static final String SCRIPTS_PATH = "scripts/"; - // TODO: Variable arguments? - - public static void execute(String script, String method) { - if (!scriptExists(script)) - return; + public static void execute(String script, String method, Object... args) { + PythonInterpreter interp; - PythonInterpreter interp = new PythonInterpreter(); - interp.execfile(SCRIPTS_PATH + script); - interp.get(method).__call__(); - } - - public static void execute(String script, String method, Object arg1) { if (!scriptExists(script)) - return; + return; // Ziggy: For now, this method gives no indication as to whether the script that was called actually was called or not. - PythonInterpreter interp = new PythonInterpreter(); - interp.execfile(SCRIPTS_PATH + script); - interp.get(method).__call__(Py.java2py(arg1)); - } - - public static void execute(String script, String method, Object arg1, Object arg2) { - if (!scriptExists(script)) - return; + interp = new PythonInterpreter(); - PythonInterpreter interp = new PythonInterpreter(); interp.execfile(SCRIPTS_PATH + script); - interp.get(method).__call__(Py.java2py(arg1), Py.java2py(arg2)); - } - - public static void execute(String script, String method, Object arg1, Object arg2, Object arg3) { - if (!scriptExists(script)) - return; - - PythonInterpreter interp = new PythonInterpreter(); - interp.execfile(SCRIPTS_PATH + script); - interp.get(method).__call__(Py.java2py(arg1), Py.java2py(arg2), Py.java2py(arg3)); - } - - public static void execute(String script, String method, Object arg1, Object arg2, Object arg3, Object arg4) { - if (!scriptExists(script)) - return; - - PythonInterpreter interp = new PythonInterpreter(); - interp.execfile(SCRIPTS_PATH + script); - interp.get(method).__call__(Py.java2py(arg1), Py.java2py(arg2), Py.java2py(arg3), Py.java2py(arg4)); + interp.get(method).__call__(Py.javas2pys(args)); } private static boolean scriptExists(String file) { return new File(SCRIPTS_PATH + file).exists(); } + } diff --git a/test/resources/TestSortedLinkedList.java b/test/resources/TestSortedLinkedList.java new file mode 100644 index 000000000..dbcb506f1 --- /dev/null +++ b/test/resources/TestSortedLinkedList.java @@ -0,0 +1,32 @@ +package resources; + +import static org.junit.Assert.assertTrue; +import java.util.Iterator; +import org.junit.Test; + +public class TestSortedLinkedList { + + /** + * Characters are compared by numerical value and they + * should therefore be stored in such order within the list. + */ + @Test + public void testSorting() { + SortedLinkedList list = new SortedLinkedList<>(); + final char testchar1 = 'a'; + final char testchar2 = 'b'; + final char testchar3 = 'c'; + Iterator it; + + list.add(testchar2); + list.add(testchar3); + list.add(testchar1); + + it = list.listIterator(); + + assertTrue(it.next().equals(testchar1)); + assertTrue(it.next().equals(testchar2)); + assertTrue(it.next().equals(testchar3)); + } + +}