mirror of
https://github.com/ProjectSWGCore/Holocore.git
synced 2026-09-12 22:45:18 -04:00
Merged projectswg/holocore into development
This commit is contained in:
@@ -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 <Byte, Posture> POSTURE_MAP = new ConcurrentHashMap<Byte, Posture>();
|
||||
private static final Map <Byte, Posture> POSTURE_MAP = new Hashtable<Byte, Posture>(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;
|
||||
|
||||
@@ -34,18 +34,13 @@ import java.util.ListIterator;
|
||||
public class SortedLinkedList<E extends Comparable<E>> extends LinkedList<E> {
|
||||
|
||||
private static final long serialVersionUID = -6776628467181994889L;
|
||||
|
||||
public SortedLinkedList() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean add(E e) {
|
||||
Comparable<E> element = (Comparable<E>) e;
|
||||
ListIterator<E> iter = listIterator();
|
||||
ListIterator<E> 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<E extends Comparable<E>> extends LinkedList<E> {
|
||||
for (E item : c) {
|
||||
add(item);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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<Character> list = new SortedLinkedList<>();
|
||||
final char testchar1 = 'a';
|
||||
final char testchar2 = 'b';
|
||||
final char testchar3 = 'c';
|
||||
Iterator<Character> 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));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user