Fix formatting and documentation in util package

git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@169 72836036-5685-4462-b002-a69064685172
This commit is contained in:
Matthias Schiffer 2011-05-06 11:20:21 +02:00
parent 4390c76630
commit 8ee379b1ab
7 changed files with 48 additions and 39 deletions

View file

@ -1,5 +1,11 @@
package jrummikub.util;
/**
* A Connection object can be used to remove a listener from a event
*/
public interface Connection {
/**
* Removes the listener
*/
public void remove();
}

View file

@ -4,29 +4,29 @@ import java.util.HashSet;
/** Simple parameterless event generator */
public class Event implements IEvent {
private HashSet<IListener> listeners = new HashSet<IListener>();
private HashSet<IListener> listeners = new HashSet<IListener>();
@Override
public Connection add(final IListener listener) {
listeners.add(listener);
return new Connection() {
@Override
public void remove() {
Event.this.remove(listener);
@Override
public Connection add(final IListener listener) {
listeners.add(listener);
return new Connection() {
@Override
public void remove() {
Event.this.remove(listener);
}
};
}
@Override
public void remove(IListener listener) {
listeners.remove(listener);
}
/** Generate a single event */
public void emit() {
for (IListener listener : listeners) {
listener.handle();
}
};
}
@Override
public void remove(IListener listener) {
listeners.remove(listener);
}
/** Generate a single event */
public void emit() {
for (IListener listener : listeners) {
listener.handle();
}
}
}
}

View file

@ -6,7 +6,7 @@ import java.util.HashSet;
* Simple single parameter event generator
*
* @param <T>
* type of the event parameter
* type of the event parameter
*/
public class Event1<T> implements IEvent1<T> {
private HashSet<IListener1<T>> listeners = new HashSet<IListener1<T>>();
@ -14,8 +14,8 @@ public class Event1<T> implements IEvent1<T> {
@Override
public Connection add(final IListener1<T> listener) {
listeners.add(listener);
return new Connection() {
return new Connection() {
@Override
public void remove() {
Event1.this.remove(listener);
@ -32,9 +32,9 @@ public class Event1<T> implements IEvent1<T> {
* Generate a single event
*
* @param value
* the event parameter
* the event parameter
*/
public void emit(T value) {
public void emit(T value) {
for (IListener1<T> listener : listeners) {
listener.handle(value);
}

View file

@ -6,9 +6,9 @@ import java.util.HashSet;
* Simple single parameter event generator
*
* @param <T1>
* type of the first event parameter
* type of the first event parameter
* @param <T2>
* type of the second event parameter
* type of the second event parameter
*/
public class Event2<T1, T2> implements IEvent2<T1, T2> {
private HashSet<IListener2<T1, T2>> listeners = new HashSet<IListener2<T1, T2>>();
@ -16,8 +16,8 @@ public class Event2<T1, T2> implements IEvent2<T1, T2> {
@Override
public Connection add(final IListener2<T1, T2> listener) {
listeners.add(listener);
return new Connection() {
return new Connection() {
@Override
public void remove() {
Event2.this.remove(listener);
@ -34,11 +34,11 @@ public class Event2<T1, T2> implements IEvent2<T1, T2> {
* Generate a single event
*
* @param value1
* the first event parameter
* the first event parameter
* @param value2
* the second event parameter
* the second event parameter
*/
public void emit(T1 value1, T2 value2) {
public void emit(T1 value1, T2 value2) {
for (IListener2<T1, T2> listener : listeners) {
listener.handle(value1, value2);
}

View file

@ -7,6 +7,7 @@ public interface IEvent {
*
* @param listener
* target listener
* @return a connection to remove the listener
*/
public Connection add(IListener listener);

View file

@ -12,6 +12,7 @@ public interface IEvent1<T> {
*
* @param listener
* target listener
* @return a connection to remove the listener
*/
public Connection add(IListener1<T> listener);

View file

@ -4,16 +4,17 @@ package jrummikub.util;
* Interface for classes that can generate events having a two parameters
*
* @param <T1>
* type of the first event parameter
* type of the first event parameter
* @param <T2>
* type of the second event parameter
* type of the second event parameter
*/
public interface IEvent2<T1, T2> {
/**
* Start to publish all events to a given listener
*
* @param listener
* target listener
* target listener
* @return a connection to remove the listener
*/
public Connection add(IListener2<T1, T2> listener);
@ -21,7 +22,7 @@ public interface IEvent2<T1, T2> {
* Stop publishing events to a given listener
*
* @param listener
* target listener
* target listener
*/
public void remove(IListener2<T1, T2> listener);
}