Class 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 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. not null.
        Returns:
        true is the parameter vlaue was set, otherwise false
        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, otherwise true
        See Also:
        isSet()
      • equals

        @Pure
        public boolean equals​(Object obj)
        Overrides:
        equals in class Object
      • hashCode

        @Pure
        public int hashCode()
        Overrides:
        hashCode in class Object