/*
 * (c) Copyright Christian P. Fries, Germany. Contact: email@christian-fries.de.
 *
 * Created on 21.10.2007
 * Created on 02.02.2014
 */
package net.finmath.stochastic;

import java.util.Objects;
import java.util.function.Function;
import java.util.function.UnaryOperator;

/**
 * @author Chrisitan Fries
 */
@FunctionalInterface
public interface RandomOperator extends UnaryOperator<RandomVariable> {

    /**
     * Applies this function to the given argument.
     *
     * @param value the function argument
     * @return the function result
     */
	RandomVariable apply(RandomVariable value);

    /**
     * Returns a composed function that first applies the {@code before}
     * function to its input, and then applies this function to the result.
     * If evaluation of either function throws an exception, it is relayed to
     * the caller of the composed function.
     *
     * @param before the function to apply before this function is applied
     * @return a composed function that first applies the {@code before}
     * function and then applies this function
     * @throws NullPointerException if before is null
     *
     * @see #andThen(Function)
     */
    default RandomOperator compose(RandomOperator before) {
        Objects.requireNonNull(before);
        return v -> apply(before.apply(v));
    }

    /**
     * Returns a composed function that first applies this function to
     * its input, and then applies the {@code after} function to the result.
     * If evaluation of either function throws an exception, it is relayed to
     * the caller of the composed function.
     *
     * @param after the function to apply after this function is applied
     * @return a composed function that first applies this function and then
     * applies the {@code after} function
     * @throws NullPointerException if after is null
     *
     * @see #compose(Function)
     */
    default RandomOperator andThen(RandomOperator after) {
        Objects.requireNonNull(after);
        return t -> after.apply(apply(t));
    }

    /**
     * Returns a function that always returns its input argument.
     *
     * @return a function that always returns its input argument
     */
    static RandomOperator identity() {
        return t -> t;
    }
}

@@ -400,28 +400,22 @@
 ble%3E %7B%0A%0A
-    /**%0A    
+%09/**%0A%09
  * Appli
@@ -450,35 +450,29 @@
 n argument.%0A
-     *%0A    
+%09 *%0A%09
  * @param va
@@ -497,20 +497,17 @@
 rgument%0A
-    
+%09
  * @retu
@@ -529,24 +529,32 @@
  result%0A
-    
+%09
  */%0A
+%09@Override%0A
 %09RandomV
@@ -591,28 +591,22 @@
 alue);%0A%0A
-    /**%0A    
+%09/**%0A%09
  * Retur
@@ -658,36 +658,33 @@
  %7B@code before%7D%0A
-    
+%09
  * function to i
@@ -731,36 +731,33 @@
  to the result.%0A
-    
+%09
  * If evaluation
@@ -806,36 +806,33 @@
 t is relayed to%0A
-    
+%09
  * the caller of
@@ -851,35 +851,29 @@
 d function.%0A
-     *%0A    
+%09 *%0A%09
  * @param be
@@ -923,36 +923,33 @@
 tion is applied%0A
-    
+%09
  * @return a com
@@ -1001,20 +1001,17 @@
 before%7D%0A
-    
+%09
  * funct
@@ -1037,36 +1037,33 @@
 s this function%0A
-    
+%09
  * @throws NullP
@@ -1092,35 +1092,29 @@
 ore is null%0A
-     *%0A    
+%09 *%0A%09
  * @see #and
@@ -1124,36 +1124,30 @@
 n(Function)%0A
-     */%0A    
+%09 */%0A%09
 default Rand
@@ -1186,32 +1186,26 @@
 r before) %7B%0A
-        
+%09%09
 Objects.requ
@@ -1224,24 +1224,18 @@
 efore);%0A
-        
+%09%09
 return v
@@ -1262,35 +1262,26 @@
 ly(v));%0A
-    %7D%0A%0A    /**%0A    
+%09%7D%0A%0A%09/**%0A%09
  * Retur
@@ -1339,20 +1339,17 @@
 tion to%0A
-    
+%09
  * its i
@@ -1413,20 +1413,17 @@
 result.%0A
-    
+%09
  * If ev
@@ -1488,20 +1488,17 @@
 ayed to%0A
-    
+%09
  * the c
@@ -1529,27 +1529,21 @@
 nction.%0A
-     *%0A    
+%09 *%0A%09
  * @para
@@ -1603,20 +1603,17 @@
 applied%0A
-    
+%09
  * @retu
@@ -1677,20 +1677,17 @@
 nd then%0A
-    
+%09
  * appli
@@ -1716,20 +1716,17 @@
 unction%0A
-    
+%09
  * @thro
@@ -1766,27 +1766,21 @@
 is null%0A
-     *%0A    
+%09 *%0A%09
  * @see 
@@ -1798,28 +1798,22 @@
 nction)%0A
-     */%0A    
+%09 */%0A%09
 default 
@@ -1859,24 +1859,18 @@
 fter) %7B%0A
-        
+%09%09
 Objects.
@@ -1892,24 +1892,18 @@
 after);%0A
-        
+%09%09
 return t
@@ -1933,27 +1933,18 @@
 ));%0A
-    %7D%0A%0A    /**%0A    
+%09%7D%0A%0A%09/**%0A%09
  * R
@@ -2005,19 +2005,13 @@
 nt.%0A
-     *%0A    
+%09 *%0A%09
  * @
@@ -2071,20 +2071,14 @@
 ent%0A
-     */%0A    
+%09 */%0A%09
 stat
@@ -2112,16 +2112,10 @@
 ) %7B%0A
-        
+%09%09
 retu
@@ -2129,12 +2129,9 @@
  t;%0A
-    
+%09
 %7D%0A%7D%0A

Clean up.