
br.com.ingenieux.mojo.apigateway.util.Unthrow Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of apigateway-maven-plugin Show documentation
Show all versions of apigateway-maven-plugin Show documentation
Beanstalker's support for AWS API Gateway
The newest version!
/*
* Copyright (c) 2016 ingenieux Labs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package br.com.ingenieux.mojo.apigateway.util;
import java.util.stream.Stream;
/**
* Throw unchecker
*
* @author SeregaLBN how to use - see unit test
*/
public class Unthrow {
@SuppressWarnings("unchecked")
static R rethrow(Exception ex) throws E {
throw (E) ex;
}
public static Stream of(Stream stream) throws E {
return stream;
}
public static Stream of2(Stream stream) throws E1, E2 {
return stream;
}
public static Stream of3(Stream stream) throws E1, E2, E3 {
return stream;
}
public static Stream of4(Stream stream)
throws E1, E2, E3, E4 {
return stream;
}
////////////////////////////////// interfaces ProcedureN //////////////////////////////////
/**
* like as {@link java.lang.Runnable}
*/
@FunctionalInterface
public interface IProc0 {
void accept() throws Exception;
}
/**
* like as {@link java.util.function.Consumer}
*/
@FunctionalInterface
public interface IProc1 {
void accept(T t) throws Exception;
}
/**
* like as {@link java.util.function.BiConsumer}
*/
@FunctionalInterface
public interface IProc2 {
void accept(T1 t1, T2 t2) throws Exception;
}
@FunctionalInterface
public interface IProc3 {
void accept(T1 t1, T2 t2, T3 t3) throws Exception;
}
////////////////////////////////// interfaces FunctionN //////////////////////////////////
/**
* like as {@link java.util.concurrent.Callable}
*/
@FunctionalInterface
public interface IFunc0 {
R apply() throws Exception;
}
/**
* like as {@link java.util.function.Function}
*/
@FunctionalInterface
public interface IFunc1 {
R apply(T t) throws Exception;
}
/**
* like as {@link java.util.function.BiFunction}
*/
@FunctionalInterface
public interface IFunc2 {
R apply(T1 t1, T2 t2) throws Exception;
}
@FunctionalInterface
public interface IFunc3 {
R apply(T1 t1, T2 t2, T3 t3) throws Exception;
}
////////////////////////////////// wrap Procedures //////////////////////////////////
public static void wrapProc(IProc0 proc) {
try {
proc.accept();
} catch (Exception ex) {
rethrow(ex);
}
}
public static void wrapProc(IProc1 proc, T t) {
try {
proc.accept(t);
} catch (Exception ex) {
rethrow(ex);
}
}
public static void wrapProc(IProc2 proc, T1 t1, T2 t2) {
try {
proc.accept(t1, t2);
} catch (Exception ex) {
rethrow(ex);
}
}
public static void wrapProc(IProc3 proc, T1 t1, T2 t2, T3 t3) {
try {
proc.accept(t1, t2, t3);
} catch (Exception ex) {
rethrow(ex);
}
}
////////////////////////////////// wrap Functions //////////////////////////////////
public static R wrap(IFunc0 func) {
try {
return func.apply();
} catch (Exception ex) {
return rethrow(ex);
}
}
public static R wrap(IFunc1 func, T t) {
try {
return func.apply(t);
} catch (Exception ex) {
return rethrow(ex);
}
}
public static R wrap(IFunc2 func, T1 t1, T2 t2) {
try {
return func.apply(t1, t2);
} catch (Exception ex) {
return rethrow(ex);
}
}
public static R wrap(IFunc3 func, T1 t1, T2 t2, T3 t3) {
try {
return func.apply(t1, t2, t3);
} catch (Exception ex) {
return rethrow(ex);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy