< prev index next >

test/jdk/tools/jpackage/helpers/jdk/jpackage/test/Functional.java

Print this page




   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 package jdk.jpackage.test;
  24 
  25 import java.lang.reflect.InvocationTargetException;
  26 import java.util.function.Consumer;
  27 import java.util.function.Function;
  28 import java.util.function.Predicate;
  29 import java.util.function.Supplier;
  30 
  31 
  32 public class Functional {
  33     @FunctionalInterface
  34     public interface ThrowingConsumer<T> {
  35         void accept(T t) throws Throwable;
  36 
  37         public static <T> Consumer<T> toConsumer(ThrowingConsumer<T> v) {
  38             return o -> {
  39                 try {
  40                     v.accept(o);
  41                 } catch (Throwable ex) {
  42                     rethrowUnchecked(ex);
  43                 }
  44             };
  45         }
  46     }
  47 
  48     @FunctionalInterface















  49     public interface ThrowingSupplier<T> {
  50         T get() throws Throwable;
  51 
  52         public static <T> Supplier<T> toSupplier(ThrowingSupplier<T> v) {
  53             return () -> {
  54                 try {
  55                     return v.get();
  56                 } catch (Throwable ex) {
  57                     rethrowUnchecked(ex);
  58                 }
  59                 // Unreachable
  60                 return null;
  61             };
  62         }
  63     }
  64 
  65     @FunctionalInterface
  66     public interface ThrowingFunction<T, R> {
  67         R apply(T t) throws Throwable;
  68 


  82     @FunctionalInterface
  83     public interface ThrowingRunnable {
  84         void run() throws Throwable;
  85 
  86         public static Runnable toRunnable(ThrowingRunnable v) {
  87             return () -> {
  88                 try {
  89                     v.run();
  90                 } catch (Throwable ex) {
  91                     rethrowUnchecked(ex);
  92                 }
  93             };
  94         }
  95     }
  96 
  97     public static <T> Supplier<T> identity(Supplier<T> v) {
  98         return v;
  99     }
 100 
 101     public static <T> Consumer<T> identity(Consumer<T> v) {




 102         return v;
 103     }
 104 
 105     public static Runnable identity(Runnable v) {
 106         return v;
 107     }
 108 
 109     public static <T, R> Function<T, R> identity(Function<T, R> v) {
 110         return v;
 111     }
 112 
 113     public static <T, R> Function<T, R> identityFunction(Function<T, R> v) {
 114         return v;
 115     }
 116 
 117     public static <T> Predicate<T> identity(Predicate<T> v) {
 118         return v;
 119     }
 120 
 121     public static <T> Predicate<T> identityPredicate(Predicate<T> v) {




   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 package jdk.jpackage.test;
  24 
  25 import java.lang.reflect.InvocationTargetException;
  26 import java.util.function.*;



  27 
  28 
  29 public class Functional {
  30     @FunctionalInterface
  31     public interface ThrowingConsumer<T> {
  32         void accept(T t) throws Throwable;
  33 
  34         public static <T> Consumer<T> toConsumer(ThrowingConsumer<T> v) {
  35             return o -> {
  36                 try {
  37                     v.accept(o);
  38                 } catch (Throwable ex) {
  39                     rethrowUnchecked(ex);
  40                 }
  41             };
  42         }
  43     }
  44 
  45     @FunctionalInterface
  46     public interface ThrowingBiConsumer<T, U> {
  47         void accept(T t, U u) throws Throwable;
  48 
  49         public static <T, U> BiConsumer<T, U> toBiConsumer(ThrowingBiConsumer<T, U> v) {
  50             return (t, u) -> {
  51                 try {
  52                     v.accept(t, u);
  53                 } catch (Throwable ex) {
  54                     rethrowUnchecked(ex);
  55                 }
  56             };
  57         }
  58     }
  59 
  60     @FunctionalInterface
  61     public interface ThrowingSupplier<T> {
  62         T get() throws Throwable;
  63 
  64         public static <T> Supplier<T> toSupplier(ThrowingSupplier<T> v) {
  65             return () -> {
  66                 try {
  67                     return v.get();
  68                 } catch (Throwable ex) {
  69                     rethrowUnchecked(ex);
  70                 }
  71                 // Unreachable
  72                 return null;
  73             };
  74         }
  75     }
  76 
  77     @FunctionalInterface
  78     public interface ThrowingFunction<T, R> {
  79         R apply(T t) throws Throwable;
  80 


  94     @FunctionalInterface
  95     public interface ThrowingRunnable {
  96         void run() throws Throwable;
  97 
  98         public static Runnable toRunnable(ThrowingRunnable v) {
  99             return () -> {
 100                 try {
 101                     v.run();
 102                 } catch (Throwable ex) {
 103                     rethrowUnchecked(ex);
 104                 }
 105             };
 106         }
 107     }
 108 
 109     public static <T> Supplier<T> identity(Supplier<T> v) {
 110         return v;
 111     }
 112 
 113     public static <T> Consumer<T> identity(Consumer<T> v) {
 114         return v;
 115     }
 116 
 117     public static <T, U> BiConsumer<T, U> identity(BiConsumer<T, U> v) {
 118         return v;
 119     }
 120 
 121     public static Runnable identity(Runnable v) {
 122         return v;
 123     }
 124 
 125     public static <T, R> Function<T, R> identity(Function<T, R> v) {
 126         return v;
 127     }
 128 
 129     public static <T, R> Function<T, R> identityFunction(Function<T, R> v) {
 130         return v;
 131     }
 132 
 133     public static <T> Predicate<T> identity(Predicate<T> v) {
 134         return v;
 135     }
 136 
 137     public static <T> Predicate<T> identityPredicate(Predicate<T> v) {


< prev index next >