Central model instance via singleton
This commit is contained in:
parent
ca92fd78c8
commit
1a9aa98c72
2 changed files with 19 additions and 10 deletions
|
@ -17,13 +17,9 @@ public class Main {
|
|||
* @param args Die Programmargumente
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
Model m;
|
||||
HttpServer s = null;
|
||||
|
||||
m = new Model();
|
||||
m.fillMockData();
|
||||
|
||||
|
||||
/**HttpServer s = null;
|
||||
Model.getModel().fillMockData();
|
||||
|
||||
try {
|
||||
s = HttpServer.create(new InetSocketAddress("127.0.0.1", 8000), 0);
|
||||
|
@ -36,10 +32,10 @@ public class Main {
|
|||
s.setExecutor(null);
|
||||
s.start();
|
||||
} catch (IOException e) {
|
||||
System.err.println("IOException bei der Erstellung des HTTP Servers. Stack Trace folgt.");
|
||||
System.err.println("IOException bei der Erstellung des HTTP Servers.");
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}**/
|
||||
}
|
||||
// schließen ist nicht nötig, da beim Beenden die ganze JVM zerstört wird
|
||||
}
|
||||
|
||||
|
|
|
@ -19,9 +19,21 @@ import java.util.HashMap;
|
|||
*/
|
||||
public class Model {
|
||||
|
||||
// die Hilfsvariable für das Singleton-Pattern
|
||||
private static Model model = null;
|
||||
|
||||
private HashMap<String, DataObject> objs;
|
||||
private HashMap<String, String> relations;
|
||||
|
||||
/**
|
||||
* Singleton.
|
||||
*/
|
||||
public static Model getModel() {
|
||||
if (model == null)
|
||||
model = new Model();
|
||||
return model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialisiert ein leeres Model.
|
||||
*/
|
||||
|
@ -56,8 +68,9 @@ public class Model {
|
|||
g1.addMember("students/jotto5");
|
||||
g2.addMember("students/vnachn");
|
||||
g2.addMember("students/ltorva");
|
||||
g3.addMember("alovel");
|
||||
g3.addMember("aturin");
|
||||
g3.addMember("students/alovel");
|
||||
g3.addMember("students/aturin");
|
||||
g3.addMember("students/ltorva");
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue