01: // Copyright 2006, 2007 The Apache Software Foundation
02: //
03: // Licensed under the Apache License, Version 2.0 (the "License");
04: // you may not use this file except in compliance with the License.
05: // You may obtain a copy of the License at
06: //
07: // http://www.apache.org/licenses/LICENSE-2.0
08: //
09: // Unless required by applicable law or agreed to in writing, software
10: // distributed under the License is distributed on an "AS IS" BASIS,
11: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: // See the License for the specific language governing permissions and
13: // limitations under the License.
14:
15: package org.apache.tapestry.internal.util;
16:
17: import java.util.concurrent.atomic.AtomicReference;
18:
19: /**
20: * An object that holds some type of other object. This is useful for communicating information from
21: * an inner class (used as a closure) to the containing method. This is similar to
22: * {@link AtomicReference}, except that it is simpler but <strong>not</strong> thread safe.
23: *
24: * @param <T>
25: */
26: public class Holder<T> {
27: private T _held;
28:
29: public void put(T object) {
30: _held = object;
31: }
32:
33: public T get() {
34: return _held;
35: }
36:
37: public boolean hasValue() {
38: return _held != null;
39: }
40:
41: public static <T> Holder<T> create() {
42: return new Holder<T>();
43: }
44: }
|