View Javadoc

1   /*--------------------------------------------------------------------------
2    *  Copyright 2009 utgenome.org
3    *
4    *  Licensed under the Apache License, Version 2.0 (the "License");
5    *  you may not use this file except in compliance with the License.
6    *  You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *  Unless required by applicable law or agreed to in writing, software
11   *  distributed under the License is distributed on an "AS IS" BASIS,
12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *  See the License for the specific language governing permissions and
14   *  limitations under the License.
15   *--------------------------------------------------------------------------*/
16  //--------------------------------------
17  // utgb-core Project
18  //
19  // Optional.java
20  // Since: May 27, 2010
21  //
22  // $URL$ 
23  // $Author$
24  //--------------------------------------
25  package org.utgenome.gwt.utgb.client.util;
26  
27  /**
28   * variable holder that can distinguish defined/undefined states.
29   * 
30   * @author leo
31   * 
32   */
33  public class Optional<T> {
34  
35  	private boolean isDefined = false;
36  	private T holder;
37  
38  	public Optional() {
39  	}
40  
41  	public boolean isDefined() {
42  		return isDefined;
43  	}
44  
45  	public boolean isUndefined() {
46  		return !isDefined;
47  	}
48  
49  	public T get() {
50  		return holder;
51  	}
52  
53  	public void set(T value) {
54  		this.holder = value;
55  		this.isDefined = true;
56  	}
57  
58  	public void reset() {
59  		this.holder = null;
60  		this.isDefined = false;
61  	}
62  
63  }