Introductie type ArrayCycle en consequent maken van add en remove methodes: nu zonder type in de naam.

This commit is contained in:
2011-02-08 14:38:20 +00:00
parent f653fc7f3d
commit 091dcdf855
2 changed files with 43 additions and 17 deletions

View File

@@ -12,50 +12,47 @@ import pm.exception.ActionException;
import pm.exception.action.NotImplementedActionException;
import pm.exception.action.UnknownTargetException;
import pm.listener.ActionListener;
import pm.util.ArrayCycle;
public class Main {
protected static final int SLEEP = 100;
ArrayList<Application> applicationList;
ArrayCycle<Application> applicationCycle;
ArrayList<Device> deviceList;
Queue<Action> actionQueue;
boolean run;
Application currentApplication;
public Main() {
applicationList = new ArrayList<Application>();
//applicationList.iterator();
applicationCycle = new ArrayCycle<Application>();
deviceList = new ArrayList<Device>();
actionQueue = new ConcurrentLinkedQueue<Action>();
ActionListener.initialise(actionQueue);
}
public void addApplication(Application application) {
applicationList.add(application);
public void add(Application application) {
applicationCycle.add(application);
}
public boolean removeApplication(Application application) {
return applicationList.remove(application);
public boolean remove(Application application) {
return applicationCycle.remove(application);
}
public void addDevice(Device device) {
public void add(Device device) {
deviceList.add(device);
}
public boolean removeDevie(Device device) {
public boolean remove(Device device) {
return deviceList.remove(device);
}
public void start() throws Exception {
//addDevice(new ExampleDevice());
//addDevice(new RumblepadDevice());
addDevice(new Extreme3DDevice());
add(new Extreme3DDevice());
Application application = new VoorbeeldApplication();
addApplication(application);
currentApplication = application;
add(application);
for (Device device : deviceList) {
device.start();
@@ -67,7 +64,6 @@ public class Main {
public void run() throws ActionException {
run = true;
while (run) {
//System.out.println("Print!");
if (actionQueue.isEmpty()) {
try {
Thread.sleep(SLEEP);
@@ -80,7 +76,7 @@ public class Main {
object = this;
break;
case APPLICATION:
object = currentApplication;
object = applicationCycle.current();
break;
default:
throw new UnknownTargetException();
@@ -99,7 +95,6 @@ public class Main {
for (Device device : deviceList) {
device.exit();
}
System.out.println("Als ie nu niet uit gaat, dan hebben we een verstekeling! Dat is vervelend ende naar!");
}
public static void main(String[] args) {

View File

@@ -0,0 +1,31 @@
package pm.util;
import java.util.ArrayList;
public class ArrayCycle<T> extends ArrayList<T> {
protected static final long serialVersionUID = 1L;
protected int index = 0;
public T current() {
return this.get(index);
}
public T previous() {
if (--index < 0) {
index = Math.max(0, size() - 1);
}
return get(index);
}
public T next() {
if (++index >= size()) {
index = 0;
}
return get(index);
}
public T reset() {
return get(index = 0);
}
}