Ignore maven’s “target/” directory.
[jFCPlib.git] / src / main / java / net / pterodactylus / util / thread / ObjectWrapper.java
1 /*
2  * jFCPlib - UserObject.java - Copyright © 2009 David Roden
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17  */
18
19 package net.pterodactylus.util.thread;
20
21 /**
22  * Wrapper around an object that can be set and retrieved. Its primary use is as
23  * a container for return values from anonymous classes.
24  *
25  * <pre>
26  * final ObjectWrapper&lt;Object&gt; objectWrapper = new ObjectWrapper&lt;Object&gt;();
27  * new Runnable() {
28  *     public void run() {
29  *         ...
30  *         objectWrapper.set(someResult);
31  *     }
32  * }.run();
33  * Object result = objectWrapper.get();
34  * </pre>
35  *
36  * @param <T>
37  *            The type of the wrapped object
38  * @author David ‘Bombe’ Roden &lt;bombe@pterodactylus.net&gt;
39  */
40 public class ObjectWrapper<T> {
41
42         /** The wrapped object. */
43         private volatile T wrappedObject;
44
45         /**
46          * Returns the wrapped object.
47          *
48          * @return The wrapped object
49          */
50         public T get() {
51                 return wrappedObject;
52         }
53
54         /**
55          * Sets the wrapped object.
56          *
57          * @param wrappedObject
58          *            The wrapped object
59          */
60         public void set(T wrappedObject) {
61                 this.wrappedObject = wrappedObject;
62         }
63
64 }