+ private static final class Arity1Func extends FunctionImpl1<Object, Object> {
+ private final Method method;
+ private final boolean returnsVoid;
+
+ private Arity1Func(Method method, boolean returnsVoid) {
+ this.method = method;
+ this.returnsVoid = returnsVoid;
+ }
+
+ @Override
+ public Object apply(Object p0) {
+ try {
+ Object ret = method.invoke(null, p0);
+ return returnsVoid ? Tuple0.INSTANCE : ret;
+ } catch (ReflectiveOperationException e) {
+ if (e instanceof InvocationTargetException) {
+ Throwable cause = e.getCause();
+ if(cause instanceof RuntimeException)
+ throw (RuntimeException)cause;
+ else
+ throw new RuntimeException(cause);
+ }
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public int hashCode() {
+ return method == null ? 0 : method.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ Arity1Func other = (Arity1Func) obj;
+ return method.equals(other.method);
+ }
+ }
+
+ private static final class Arity2Func extends FunctionImpl2<Object, Object, Object> {
+ private final Method method;
+ private final boolean returnsVoid;
+
+ private Arity2Func(Method method, boolean returnsVoid) {
+ this.method = method;
+ this.returnsVoid = returnsVoid;
+ }
+
+ @Override
+ public Object apply(Object p0, Object p1) {
+ try {
+ Object ret = method.invoke(null, p0, p1);
+ return returnsVoid ? Tuple0.INSTANCE : ret;
+ } catch (ReflectiveOperationException e) {
+ if (e instanceof InvocationTargetException) {
+ Throwable cause = e.getCause();
+ if(cause instanceof RuntimeException)
+ throw (RuntimeException)cause;
+ else
+ throw new RuntimeException(cause);
+ }
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public int hashCode() {
+ return method == null ? 0 : method.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ Arity2Func other = (Arity2Func) obj;
+ return method.equals(other.method);
+ }
+ }
+
+ private static final class Arity3Func extends FunctionImpl3<Object, Object, Object, Object> {
+ private final Method method;
+ private final boolean returnsVoid;
+
+ private Arity3Func(Method method, boolean returnsVoid) {
+ this.method = method;
+ this.returnsVoid = returnsVoid;
+ }
+
+ @Override
+ public Object apply(Object p0, Object p1, Object p2) {
+ try {
+ Object ret = method.invoke(null, p0, p1, p2);
+ return returnsVoid ? Tuple0.INSTANCE : ret;
+ } catch (ReflectiveOperationException e) {
+ if (e instanceof InvocationTargetException) {
+ Throwable cause = e.getCause();
+ if(cause instanceof RuntimeException)
+ throw (RuntimeException)cause;
+ else
+ throw new RuntimeException(cause);
+ }
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public int hashCode() {
+ return method == null ? 0 : method.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ Arity3Func other = (Arity3Func) obj;
+ return method.equals(other.method);
+ }
+ }
+
+ private static final class Arity4Func extends FunctionImpl4<Object, Object, Object, Object, Object> {
+ private final Method method;
+ private final boolean returnsVoid;
+
+ private Arity4Func(Method method, boolean returnsVoid) {
+ this.method = method;
+ this.returnsVoid = returnsVoid;
+ }
+
+ @Override
+ public Object apply(Object p0, Object p1, Object p2, Object p3) {
+ try {
+ Object ret = method.invoke(null, p0, p1, p2, p3);
+ return returnsVoid ? Tuple0.INSTANCE : ret;
+ } catch (ReflectiveOperationException e) {
+ if (e instanceof InvocationTargetException) {
+ Throwable cause = e.getCause();
+ if(cause instanceof RuntimeException)
+ throw (RuntimeException)cause;
+ else
+ throw new RuntimeException(cause);
+ }
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public int hashCode() {
+ return method == null ? 0 : method.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ Arity4Func other = (Arity4Func) obj;
+ return method.equals(other.method);
+ }
+ }
+
+ private static final class ArityNFunc extends FunctionImplN {
+ private final Method method;
+ private final boolean returnsVoid;
+
+ private ArityNFunc(int arity, Method method, boolean returnsVoid) {
+ super(arity);
+ this.method = method;
+ this.returnsVoid = returnsVoid;
+ }
+
+ @Override
+ public Object doApply(Object... ps) {
+ try {
+ Object ret = method.invoke(null, ps);
+ return returnsVoid ? Tuple0.INSTANCE : ret;
+ } catch (ReflectiveOperationException e) {
+ if (e instanceof InvocationTargetException) {
+ Throwable cause = e.getCause();
+ if(cause instanceof RuntimeException)
+ throw (RuntimeException)cause;
+ else
+ throw new RuntimeException(cause);
+ }
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public int hashCode() {
+ return method == null ? 0 : method.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ ArityNFunc other = (ArityNFunc) obj;
+ return method.equals(other.method);
+ }
+ }
+