summaryrefslogtreecommitdiff
path: root/same/src/main/java/com/orbekk/util
diff options
context:
space:
mode:
authorKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-02-27 16:08:54 +0100
committerKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-02-27 16:08:54 +0100
commitc58c649531e4884a92f07d9b12f0ad77fbcf5d6a (patch)
tree38d2997ec6cdaed9120dba012b61afbb8b2e53ea /same/src/main/java/com/orbekk/util
parentee51a98e9b61336610d667de57a8cff70d0ac1d9 (diff)
Clean up source code.
Clean up source code with Eclipse. In particular remove tabs.
Diffstat (limited to 'same/src/main/java/com/orbekk/util')
-rw-r--r--same/src/main/java/com/orbekk/util/DelayedOperation.java190
-rw-r--r--same/src/main/java/com/orbekk/util/WorkQueue.java14
2 files changed, 102 insertions, 102 deletions
diff --git a/same/src/main/java/com/orbekk/util/DelayedOperation.java b/same/src/main/java/com/orbekk/util/DelayedOperation.java
index 2c37d02..cf6ca30 100644
--- a/same/src/main/java/com/orbekk/util/DelayedOperation.java
+++ b/same/src/main/java/com/orbekk/util/DelayedOperation.java
@@ -1,99 +1,99 @@
package com.orbekk.util;
public class DelayedOperation<T> {
- public static class Status {
- public final static int OK = 1;
- public final static int CONFLICT = 2;
- public final static int ERROR = 3;
-
- private int status;
- private String message;
-
- public static Status createOk() {
- return new Status(OK, "");
- }
-
- public static Status createConflict(String message) {
- return new Status(CONFLICT, message);
- }
-
- public static Status createError(String message) {
- return new Status(ERROR, message);
- }
-
- public Status(int status, String message) {
- this.status = status;
- this.message = message;
- }
-
- @Override public String toString() {
- switch(status) {
- case OK:
- return "OK";
- case CONFLICT:
- return "Conflicting update: " + message;
- case ERROR:
- return "Error: " + message;
- }
- throw new AssertionError("Unhandled case.");
- }
-
- @Override public boolean equals(Object other) {
- if (!(other instanceof Status)) {
- return false;
- }
- Status o = (Status)other;
- if (o.status != this.status) {
- return false;
- }
- if (message == null) {
- return o.message == null;
- }
- return message.equals(o.message);
- }
- }
-
- private T argument;
- private Status status;
- private boolean isDone;
- private int identifier;
-
- public DelayedOperation(T argument) {
- this.argument = argument;
- }
-
- public Status getStatus() {
- waitFor();
- return status;
- }
-
- public synchronized void waitFor() {
- while (!isDone) {
- try {
- wait();
- } catch (InterruptedException e) {
- complete(new Status(Status.ERROR, "Thread interrupted."));
- }
- }
- }
-
- public synchronized boolean isDone() {
- return isDone;
- }
-
- public synchronized void complete(Status status) {
- if (!isDone) {
- isDone = true;
- this.status = status;
- notifyAll();
- }
- }
-
- public synchronized int getIdentifier() {
- return identifier;
- }
-
- public synchronized void setIdentifier(int identifier) {
- this.identifier = identifier;
- }
+ public static class Status {
+ public final static int OK = 1;
+ public final static int CONFLICT = 2;
+ public final static int ERROR = 3;
+
+ private int status;
+ private String message;
+
+ public static Status createOk() {
+ return new Status(OK, "");
+ }
+
+ public static Status createConflict(String message) {
+ return new Status(CONFLICT, message);
+ }
+
+ public static Status createError(String message) {
+ return new Status(ERROR, message);
+ }
+
+ public Status(int status, String message) {
+ this.status = status;
+ this.message = message;
+ }
+
+ @Override public String toString() {
+ switch(status) {
+ case OK:
+ return "OK";
+ case CONFLICT:
+ return "Conflicting update: " + message;
+ case ERROR:
+ return "Error: " + message;
+ }
+ throw new AssertionError("Unhandled case.");
+ }
+
+ @Override public boolean equals(Object other) {
+ if (!(other instanceof Status)) {
+ return false;
+ }
+ Status o = (Status)other;
+ if (o.status != this.status) {
+ return false;
+ }
+ if (message == null) {
+ return o.message == null;
+ }
+ return message.equals(o.message);
+ }
+ }
+
+ private T argument;
+ private Status status;
+ private boolean isDone;
+ private int identifier;
+
+ public DelayedOperation(T argument) {
+ this.argument = argument;
+ }
+
+ public Status getStatus() {
+ waitFor();
+ return status;
+ }
+
+ public synchronized void waitFor() {
+ while (!isDone) {
+ try {
+ wait();
+ } catch (InterruptedException e) {
+ complete(new Status(Status.ERROR, "Thread interrupted."));
+ }
+ }
+ }
+
+ public synchronized boolean isDone() {
+ return isDone;
+ }
+
+ public synchronized void complete(Status status) {
+ if (!isDone) {
+ isDone = true;
+ this.status = status;
+ notifyAll();
+ }
+ }
+
+ public synchronized int getIdentifier() {
+ return identifier;
+ }
+
+ public synchronized void setIdentifier(int identifier) {
+ this.identifier = identifier;
+ }
}
diff --git a/same/src/main/java/com/orbekk/util/WorkQueue.java b/same/src/main/java/com/orbekk/util/WorkQueue.java
index 2fb2c88..397c4b8 100644
--- a/same/src/main/java/com/orbekk/util/WorkQueue.java
+++ b/same/src/main/java/com/orbekk/util/WorkQueue.java
@@ -16,21 +16,21 @@ abstract public class WorkQueue<E> extends Thread implements List<E> {
private Logger logger = LoggerFactory.getLogger(getClass());
private volatile List<E> list = null;
private volatile boolean done = false;
-
+
public WorkQueue() {
list = new ArrayList<E>();
}
-
+
public WorkQueue(Collection<? extends E> collection) {
list = new ArrayList<E>(collection);
}
-
+
public synchronized List<E> getAndClear() {
List<E> copy = new ArrayList<E>(list);
list.clear();
return copy;
}
-
+
/**
* OnChange event.
*
@@ -50,7 +50,7 @@ abstract public class WorkQueue<E> extends Thread implements List<E> {
onChange();
}
}
-
+
@Override
public void run() {
while (!done) {
@@ -71,8 +71,8 @@ abstract public class WorkQueue<E> extends Thread implements List<E> {
}
}
}
-
-
+
+
@Override
public synchronized boolean add(E e) {
notifyAll();