Project

General

Profile

Download (1.67 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy 
4
* http://www.e-taxonomy.eu
5
* 
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9

    
10
package eu.etaxonomy.cdm.common;
11

    
12
import org.apache.log4j.Logger;
13

    
14
//import org.apache.log4j.Logger;
15

    
16
/**
17
 * Wrapps a result object so it can be used as method parameter and changed within the method.
18
 * This is useful especially for simple data types like <code>Boolean</code> etc.<br>
19
 * Example (usage):<br><code>
20
 * 	public String myMethod(String oneParameter, ResultWrapper<Boolean> success){<br>
21
 * 	    __if (oneParameter.equals("foo")){<br>
22
 * 	    ____success = success.setValue(false);<br>
23
 * 	    ____return "Foo";<br>
24
 * 	__}else{<br>
25
 * 	____//don't change success<br>
26
 * 	____return "All the best";<br>
27
 * 	__}<br>
28
 * 	}
29
 * </code>
30
 * Here a String is returned but the boolean value may also be changed and it's value is useable 
31
 * by the calling method
32
 *  
33
 * @author a.mueller
34
 * @since 01.11.2008
35
 * @version 1.0
36
 */
37
public class ResultWrapper<T> {
38
	private static final Logger logger = Logger.getLogger(ResultWrapper.class);
39

    
40
	public static final ResultWrapper<Boolean> NewInstance(Boolean value){
41
		ResultWrapper<Boolean> result = new ResultWrapper<Boolean>();
42
		result.setValue(value);
43
		if (logger.isDebugEnabled()){logger.debug("New Instance");}
44
		return result;
45
	}
46
	
47
	T object;
48

    
49
	/**
50
	 * @return the object
51
	 */
52
	public T getValue() {
53
		return object;
54
	}
55

    
56
	/**
57
	 * @param object the object to set
58
	 */
59
	public void setValue(T value) {
60
		this.object = value;
61
	}
62
}
(14-14/21)