- java.lang.Object
-
- org.arakhne.afc.util.OutputParameter<T>
-
- Type Parameters:
T
- is the type of the value to output with this object.
public class OutputParameter<T> extends Object
Utilities class that permits to obtain output parameters for Java functions.The generic type describes the type of the parameter.
Example of the classic swap function:
class SwapTest { public static void swap(OutputParameter<Long> a, OutputParameter<Long> b) { Long tmp = a.get(); a.set(b.get(); b.set(tmp); } public static void main(String[]) { OutputParameter<Long> opx = new OuputParameter(24); OutputParameter<Long> opy = new OuputParameter(36); System.out.println("before, x="+opx.get()); System.out.println("before, y="+opy.get()); swap(opx,opy); System.out.println("after, x="+opx.get()); System.out.println("after, y="+opy.get()); } }
The example outputs the text:
before, x=24 before, y=36 after, x=36 after, y=24
- Version:
- 17.0 2020-01-04 14:41:38
- Author:
- Stéphane GALLAND
- Maven Group Id:
- org.arakhne.afc.core
- Maven Artifact Id:
- util
-
-
Constructor Summary
Constructors Constructor Description OutputParameter()
Create empty output parameter.OutputParameter(T initialValue)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
Clear this parameter.boolean
equals(Object obj)
T
get()
Replies the parameter value.int
hashCode()
boolean
isEmpty()
Replies if the value was not set, i.e.boolean
isSet()
Replies if the value was set, i.e. notnull
.T
set(T newValue)
Set the parameter.String
toString()
-
-
-
Constructor Detail
-
OutputParameter
public OutputParameter(T initialValue)
Constructor.- Parameters:
initialValue
- is the initial value of the output parameter.
-
OutputParameter
public OutputParameter()
Create empty output parameter.
-
-
Method Detail
-
get
@Pure public T get()
Replies the parameter value.- Returns:
- the value embedded inside this output parameter.
-
set
public T set(T newValue)
Set the parameter.- Parameters:
newValue
- is the value of the parameter.- Returns:
- the old value of the parameter.
-
clear
public void clear()
Clear this parameter.
-
isSet
@Pure public boolean isSet()
Replies if the value was set, i.e. notnull
.- Returns:
true
is the parameter vlaue was set, otherwisefalse
- See Also:
isEmpty()
-
isEmpty
@Pure public boolean isEmpty()
Replies if the value was not set, i.e.null
.- Returns:
false
is the parameter vlaue was set, otherwisetrue
- See Also:
isSet()
-
-