|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectde.cau.cs.kieler.core.util.Maybe<T>
T
- type of contained objectpublic class Maybe<T>
Object that may contain another object, inspired by the Haskell type Maybe.
This class can be used to wrap objects for anonymous classes:
Myclass foo() { final Maybemaybe = new Maybe (); PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() { public void run() { maybe.set(new Myclass("bar")); } }); return maybe.get(); }
Another use is as a wrapper for synchronization on objects that may be null
:
Maybemaybe = new Maybe (); void thread1() { maybe.set(new Myclass("foo")); synchronized (maybe) { maybe.notify(); ) } void thread2() { synchronized (maybe) { if (maybe.get() == null) { maybe.wait(); } } maybe.get().bar(); }
Constructor Summary | |
---|---|
Maybe()
Creates a maybe without an object. |
|
Maybe(T theobject)
Creates a maybe with the given object. |
Method Summary | ||
---|---|---|
static
|
create()
Create a maybe with inferred generic type. |
|
boolean |
equals(Object obj)
|
|
T |
get()
Returns the contained object. |
|
int |
hashCode()
|
|
void |
set(T theobject)
Sets the contained object. |
|
String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public Maybe()
public Maybe(T theobject)
theobject
- the object to containMethod Detail |
---|
public static <D> Maybe<D> create()
D
- the generic type
public boolean equals(Object obj)
equals
in class Object
public int hashCode()
hashCode
in class Object
public String toString()
toString
in class Object
public void set(T theobject)
theobject
- the object to setpublic T get()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |