Reconstructed too many codes

This commit is contained in:
huanghongxun
2015-12-09 21:03:56 +08:00
parent 8e2fa57868
commit a436e10d93
38 changed files with 606 additions and 822 deletions

View File

@@ -46,9 +46,9 @@ public class ContentGetAndShowTask extends HTTPGetTask implements Event<String>
@Override
public boolean call(Object sender, String value) {
LogWindow.instance.clean();
LogWindow.instance.log(value);
LogWindow.instance.setVisible(true);
LogWindow.INSTANCE.clean();
LogWindow.INSTANCE.log(value);
LogWindow.INSTANCE.setVisible(true);
return true;
}
}

View File

@@ -17,11 +17,11 @@
*/
package org.jackhuang.hellominecraft.utils;
import org.jackhuang.hellominecraft.utils.functions.Consumer;
import org.jackhuang.hellominecraft.utils.functions.Predicate;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import rx.Observable;
/**
*
@@ -29,17 +29,9 @@ import java.util.Iterator;
*/
public final class CollectionUtils {
public static <T> void forEach(Collection<T> coll, Consumer<T> p) {
for (T t : coll)
p.accept(t);
}
public static <T> ArrayList<T> map(Collection<T> coll, Predicate<T> p) {
ArrayList<T> newColl = new ArrayList<>();
forEach(coll, t -> {
if (p.apply(t))
newColl.add(t);
});
Observable.from(coll).filter(p).subscribe(newColl::add);
return newColl;
}

View File

@@ -29,6 +29,8 @@ import java.net.URL;
import java.util.Map;
import org.jackhuang.hellominecraft.HMCLog;
import org.jackhuang.hellominecraft.utils.system.IOUtils;
import rx.Observable;
import rx.subscriptions.Subscriptions;
/**
*
@@ -156,4 +158,15 @@ public final class NetUtils {
throw new IllegalArgumentException("Could not concatenate given URL with GET arguments!", ex);
}
}
public static Observable<String> getRx(String url) {
return Observable.create(t1 -> {
try {
t1.onNext(get(url));
} catch(Exception e) {
t1.onError(e);
}
return Subscriptions.empty();
});
}
}

View File

@@ -21,6 +21,7 @@ import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.jackhuang.hellominecraft.C;
import org.jackhuang.hellominecraft.HMCLog;
/**
@@ -40,6 +41,14 @@ public class Java {
return name;
}
public String getLocalizedName() {
if (name.equals("Default"))
return C.i18n("settings.default");
if (name.equals("Custom"))
return C.i18n("settings.custom");
return name;
}
public String getHome() {
return home;
}

View File

@@ -17,7 +17,14 @@
*/
package org.jackhuang.hellominecraft.version;
import java.io.File;
import java.io.IOException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import org.jackhuang.hellominecraft.C;
import org.jackhuang.hellominecraft.HMCLog;
import org.jackhuang.hellominecraft.utils.ArrayUtils;
import org.jackhuang.hellominecraft.utils.NetUtils;
/**
* @author huangyuhui
@@ -59,4 +66,127 @@ public class MinecraftVersionRequest {
}
return text;
}
private static int lessThan32(byte[] b, int x) {
for (; x < b.length; x++)
if (b[x] < 32)
return x;
return -1;
}
private static MinecraftVersionRequest getVersionOfOldMinecraft(ZipFile file, ZipEntry entry) throws IOException {
MinecraftVersionRequest r = new MinecraftVersionRequest();
byte[] tmp = NetUtils.getBytesFromStream(file.getInputStream(entry));
byte[] bytes = "Minecraft Minecraft ".getBytes("ASCII");
int j;
if ((j = ArrayUtils.matchArray(tmp, bytes)) < 0) {
r.type = MinecraftVersionRequest.UNKOWN;
return r;
}
int i = j + bytes.length;
if ((j = lessThan32(tmp, i)) < 0) {
r.type = MinecraftVersionRequest.UNKOWN;
return r;
}
String ver = new String(tmp, i, j - i, "ASCII");
r.version = ver;
r.type = file.getEntry("META-INF/MANIFEST.MF") == null
? MinecraftVersionRequest.MODIFIED : MinecraftVersionRequest.OK;
return r;
}
private static MinecraftVersionRequest getVersionOfNewMinecraft(ZipFile file, ZipEntry entry) throws IOException {
MinecraftVersionRequest r = new MinecraftVersionRequest();
byte[] tmp = NetUtils.getBytesFromStream(file.getInputStream(entry));
byte[] str = "-server.txt".getBytes("ASCII");
int j = ArrayUtils.matchArray(tmp, str);
if (j < 0) {
r.type = MinecraftVersionRequest.UNKOWN;
return r;
}
int i = j + str.length;
i += 11;
j = lessThan32(tmp, i);
if (j < 0) {
r.type = MinecraftVersionRequest.UNKOWN;
return r;
}
r.version = new String(tmp, i, j - i, "ASCII");
char ch = r.version.charAt(0);
// 1.8.1+
if (ch < '0' || ch > '9') {
str = "Can't keep up! Did the system time change, or is the server overloaded?".getBytes("ASCII");
j = ArrayUtils.matchArray(tmp, str);
if (j < 0) {
r.type = MinecraftVersionRequest.UNKOWN;
return r;
}
i = -1;
while (j > 0) {
if (tmp[j] >= 48 && tmp[j] <= 57) {
i = j;
break;
}
j--;
}
if (i == -1) {
r.type = MinecraftVersionRequest.UNKOWN;
return r;
}
int k = i;
while (tmp[k] >= 48 && tmp[k] <= 57 || tmp[k] == 46)
k--;
k++;
r.version = new String(tmp, k, i - k + 1);
}
r.type = file.getEntry("META-INF/MANIFEST.MF") == null
? MinecraftVersionRequest.MODIFIED : MinecraftVersionRequest.OK;
return r;
}
public static MinecraftVersionRequest minecraftVersion(File file) {
MinecraftVersionRequest r = new MinecraftVersionRequest();
if (!file.exists()) {
r.type = MinecraftVersionRequest.NOT_FOUND;
return r;
}
if (!file.isFile()) {
r.type = MinecraftVersionRequest.NOT_FILE;
return r;
}
if (!file.canRead()) {
r.type = MinecraftVersionRequest.UNREADABLE;
return r;
}
ZipFile localZipFile = null;
try {
localZipFile = new ZipFile(file);
ZipEntry minecraft = localZipFile
.getEntry("net/minecraft/client/Minecraft.class");
if (minecraft != null)
return getVersionOfOldMinecraft(localZipFile, minecraft);
ZipEntry main = localZipFile.getEntry("net/minecraft/client/main/Main.class");
ZipEntry minecraftserver = localZipFile.getEntry("net/minecraft/server/MinecraftServer.class");
if ((main != null) && (minecraftserver != null))
return getVersionOfNewMinecraft(localZipFile, minecraftserver);
r.type = MinecraftVersionRequest.INVALID;
return r;
} catch (IOException localException) {
HMCLog.warn("Zip file is invalid", localException);
r.type = MinecraftVersionRequest.INVALID_JAR;
return r;
} finally {
if (localZipFile != null)
try {
localZipFile.close();
} catch (IOException ex) {
HMCLog.warn("Failed to close zip file", ex);
}
}
}
}

View File

@@ -57,7 +57,7 @@ public class LogWindow extends javax.swing.JFrame {
System.setErr(new LauncherPrintStream(err));
}
public static LogWindow instance = new LogWindow();
public static final LogWindow INSTANCE = new LogWindow();
/**
* This method is called from within the constructor to initialize the form.

View File

@@ -2478,6 +2478,10 @@ public class Observable<T> {
public Observable<T> where(Func1<T, Boolean> predicate) {
return where(this, predicate);
}
public final <R> Observable<R> flatMap(Func1<? super T, ? extends Observable<? extends R>> func) {
return merge(map(func));
}
/**
* Returns the last element of an observable sequence with a specified source.

View File

@@ -1,7 +1,19 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see {http://www.gnu.org/licenses/}.
*/
package rx.concurrency;

View File

@@ -55,12 +55,7 @@ public class OperationSubscribeOn {
@Override
public void unsubscribe() {
scheduler.schedule(new Action0() {
@Override
public void call() {
underlying.unsubscribe();
}
});
scheduler.schedule(underlying::unsubscribe);
}
}

View File

@@ -1,12 +1,12 @@
/**
* Copyright 2013 Netflix, Inc.
*
* <p>
* 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
*
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
*
* <p>
* 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.
@@ -22,24 +22,18 @@ import org.jackhuang.hellominecraft.logging.logger.Logger;
/**
* Allows execution of functions from multiple different languages.
* <p>
* Language support is provided via implementations of {@link FunctionLanguageAdaptor}.
* Language support is provided via implementations of
* {@link FunctionLanguageAdaptor}.
* <p>
* This class will dynamically look for known language adaptors on the classpath at startup or new ones can be registered using {@link #registerLanguageAdaptor(Class[], FunctionLanguageAdaptor)}.
* This class will dynamically look for known language adaptors on the classpath
* at startup or new ones can be registered using
* {@link #registerLanguageAdaptor(Class[], FunctionLanguageAdaptor)}.
*/
public class Functions {
private static final Logger logger = new Logger("Functions");
private final static ConcurrentHashMap<Class<?>, FunctionLanguageAdaptor> languageAdaptors = new ConcurrentHashMap<Class<?>, FunctionLanguageAdaptor>();
static {
/* optimistically look for supported languages if they are in the classpath */
loadLanguageAdaptor("Groovy");
loadLanguageAdaptor("JRuby");
loadLanguageAdaptor("Clojure");
loadLanguageAdaptor("Scala");
// as new languages arise we can add them here but this does not prevent someone from using 'registerLanguageAdaptor' directly
}
private final static ConcurrentHashMap<Class<?>, FunctionLanguageAdaptor> languageAdaptors = new ConcurrentHashMap<>();
private static boolean loadLanguageAdaptor(String name) {
String className = "rx.lang." + name.toLowerCase() + "." + name + "Adaptor";
@@ -60,9 +54,8 @@ public class Functions {
public static void registerLanguageAdaptor(Class<?>[] functionClasses, FunctionLanguageAdaptor adaptor) {
for (Class<?> functionClass : functionClasses) {
if (functionClass.getPackage().getName().startsWith("java.")) {
if (functionClass.getPackage().getName().startsWith("java."))
throw new IllegalArgumentException("FunctionLanguageAdaptor implementations can not specify java.lang.* classes.");
}
languageAdaptors.put(functionClass, adaptor);
}
}
@@ -76,24 +69,24 @@ public class Functions {
}
/**
* Utility method for determining the type of closure/function and executing it.
*
* Utility method for determining the type of closure/function and executing
* it.
*
* @param function
*/
@SuppressWarnings({ "rawtypes" })
@SuppressWarnings({"rawtypes"})
public static FuncN from(final Object function) {
if (function == null) {
if (function == null)
throw new RuntimeException("function is null. Can't send arguments to null function.");
}
/* check for typed Rx Function implementation first */
if (function instanceof Function) {
if (function instanceof Function)
return fromFunction((Function) function);
} else {
else
/* not an Rx Function so try language adaptors */
// check for language adaptor
for (final Class c : languageAdaptors.keySet()) {
for (final Class c : languageAdaptors.keySet())
if (c.isInstance(function)) {
final FunctionLanguageAdaptor la = languageAdaptors.get(c);
// found the language adaptor so wrap in FuncN and return
@@ -105,10 +98,7 @@ public class Functions {
}
};
}
}
// no language adaptor found
}
} // no language adaptor found
// no support found
throw new RuntimeException("Unsupported closure type: " + function.getClass().getSimpleName());
@@ -213,338 +203,254 @@ public class Functions {
//
// throw new RuntimeException("Unknown implementation of Function: " + function.getClass().getSimpleName());
// }
@SuppressWarnings({ "unchecked", "rawtypes" })
@SuppressWarnings({"unchecked", "rawtypes"})
private static FuncN fromFunction(Function function) {
// check Func* classes
if (function instanceof Func0) {
if (function instanceof Func0)
return fromFunc((Func0) function);
} else if (function instanceof Func1) {
else if (function instanceof Func1)
return fromFunc((Func1) function);
} else if (function instanceof Func2) {
else if (function instanceof Func2)
return fromFunc((Func2) function);
} else if (function instanceof Func3) {
else if (function instanceof Func3)
return fromFunc((Func3) function);
} else if (function instanceof Func4) {
else if (function instanceof Func4)
return fromFunc((Func4) function);
} else if (function instanceof Func5) {
else if (function instanceof Func5)
return fromFunc((Func5) function);
} else if (function instanceof Func6) {
else if (function instanceof Func6)
return fromFunc((Func6) function);
} else if (function instanceof Func7) {
else if (function instanceof Func7)
return fromFunc((Func7) function);
} else if (function instanceof Func8) {
else if (function instanceof Func8)
return fromFunc((Func8) function);
} else if (function instanceof Func9) {
else if (function instanceof Func9)
return fromFunc((Func9) function);
} else if (function instanceof FuncN) {
else if (function instanceof FuncN)
return (FuncN) function;
} else if (function instanceof Action0) {
else if (function instanceof Action0)
return fromAction((Action0) function);
} else if (function instanceof Action1) {
else if (function instanceof Action1)
return fromAction((Action1) function);
} else if (function instanceof Action2) {
else if (function instanceof Action2)
return fromAction((Action2) function);
} else if (function instanceof Action3) {
else if (function instanceof Action3)
return fromAction((Action3) function);
}
throw new RuntimeException("Unknown implementation of Function: " + function.getClass().getSimpleName());
}
/**
* Convert a function to FuncN to allow heterogeneous handling of functions with different arities.
*
* Convert a function to FuncN to allow heterogeneous handling of functions
* with different arities.
*
* @param f
* @return {@link FuncN}
*/
public static <R> FuncN<R> fromFunc(final Func0<R> f) {
return new FuncN<R>() {
@Override
public R call(Object... args) {
if (args.length != 0) {
throw new RuntimeException("Func0 expecting 0 arguments.");
}
return f.call();
}
return (Object... args) -> {
if (args.length != 0)
throw new RuntimeException("Func0 expecting 0 arguments.");
return f.call();
};
}
/**
* Convert a function to FuncN to allow heterogeneous handling of functions with different arities.
*
* Convert a function to FuncN to allow heterogeneous handling of functions
* with different arities.
*
* @param f
* @return {@link FuncN}
*/
public static <T0, R> FuncN<R> fromFunc(final Func1<T0, R> f) {
return new FuncN<R>() {
@SuppressWarnings("unchecked")
@Override
public R call(Object... args) {
if (args.length != 1) {
throw new RuntimeException("Func1 expecting 1 argument.");
}
return f.call((T0) args[0]);
}
return (Object... args) -> {
if (args.length != 1)
throw new RuntimeException("Func1 expecting 1 argument.");
return f.call((T0) args[0]);
};
}
/**
* Convert a function to FuncN to allow heterogeneous handling of functions with different arities.
*
* Convert a function to FuncN to allow heterogeneous handling of functions
* with different arities.
*
* @param f
* @return {@link FuncN}
*/
public static <T0, T1, R> FuncN<R> fromFunc(final Func2<T0, T1, R> f) {
return new FuncN<R>() {
@SuppressWarnings("unchecked")
@Override
public R call(Object... args) {
if (args.length != 2) {
throw new RuntimeException("Func2 expecting 2 arguments.");
}
return f.call((T0) args[0], (T1) args[1]);
}
return (Object... args) -> {
if (args.length != 2)
throw new RuntimeException("Func2 expecting 2 arguments.");
return f.call((T0) args[0], (T1) args[1]);
};
}
/**
* Convert a function to FuncN to allow heterogeneous handling of functions with different arities.
*
* Convert a function to FuncN to allow heterogeneous handling of functions
* with different arities.
*
* @param f
* @return {@link FuncN}
*/
public static <T0, T1, T2, R> FuncN<R> fromFunc(final Func3<T0, T1, T2, R> f) {
return new FuncN<R>() {
@SuppressWarnings("unchecked")
@Override
public R call(Object... args) {
if (args.length != 3) {
throw new RuntimeException("Func3 expecting 3 arguments.");
}
return f.call((T0) args[0], (T1) args[1], (T2) args[2]);
}
return (Object... args) -> {
if (args.length != 3)
throw new RuntimeException("Func3 expecting 3 arguments.");
return f.call((T0) args[0], (T1) args[1], (T2) args[2]);
};
}
/**
* Convert a function to FuncN to allow heterogeneous handling of functions with different arities.
*
* Convert a function to FuncN to allow heterogeneous handling of functions
* with different arities.
*
* @param f
* @return {@link FuncN}
*/
public static <T0, T1, T2, T3, R> FuncN<R> fromFunc(final Func4<T0, T1, T2, T3, R> f) {
return new FuncN<R>() {
@SuppressWarnings("unchecked")
@Override
public R call(Object... args) {
if (args.length != 4) {
throw new RuntimeException("Func4 expecting 4 arguments.");
}
return f.call((T0) args[0], (T1) args[1], (T2) args[2], (T3) args[3]);
}
return (Object... args) -> {
if (args.length != 4)
throw new RuntimeException("Func4 expecting 4 arguments.");
return f.call((T0) args[0], (T1) args[1], (T2) args[2], (T3) args[3]);
};
}
/**
* Convert a function to FuncN to allow heterogeneous handling of functions with different arities.
*
* Convert a function to FuncN to allow heterogeneous handling of functions
* with different arities.
*
* @param f
* @return {@link FuncN}
*/
public static <T0, T1, T2, T3, T4, R> FuncN<R> fromFunc(final Func5<T0, T1, T2, T3, T4, R> f) {
return new FuncN<R>() {
@SuppressWarnings("unchecked")
@Override
public R call(Object... args) {
if (args.length != 5) {
throw new RuntimeException("Func5 expecting 5 arguments.");
}
return f.call((T0) args[0], (T1) args[1], (T2) args[2], (T3) args[3], (T4) args[4]);
}
return (Object... args) -> {
if (args.length != 5)
throw new RuntimeException("Func5 expecting 5 arguments.");
return f.call((T0) args[0], (T1) args[1], (T2) args[2], (T3) args[3], (T4) args[4]);
};
}
/**
* Convert a function to FuncN to allow heterogeneous handling of functions with different arities.
*
* Convert a function to FuncN to allow heterogeneous handling of functions
* with different arities.
*
* @param f
* @return {@link FuncN}
*/
public static <T0, T1, T2, T3, T4, T5, R> FuncN<R> fromFunc(final Func6<T0, T1, T2, T3, T4, T5, R> f) {
return new FuncN<R>() {
@SuppressWarnings("unchecked")
@Override
public R call(Object... args) {
if (args.length != 6) {
throw new RuntimeException("Func6 expecting 6 arguments.");
}
return f.call((T0) args[0], (T1) args[1], (T2) args[2], (T3) args[3], (T4) args[4], (T5) args[5]);
}
return (Object... args) -> {
if (args.length != 6)
throw new RuntimeException("Func6 expecting 6 arguments.");
return f.call((T0) args[0], (T1) args[1], (T2) args[2], (T3) args[3], (T4) args[4], (T5) args[5]);
};
}
/**
* Convert a function to FuncN to allow heterogeneous handling of functions with different arities.
*
* Convert a function to FuncN to allow heterogeneous handling of functions
* with different arities.
*
* @param f
* @return {@link FuncN}
*/
public static <T0, T1, T2, T3, T4, T5, T6, R> FuncN<R> fromFunc(final Func7<T0, T1, T2, T3, T4, T5, T6, R> f) {
return new FuncN<R>() {
@SuppressWarnings("unchecked")
@Override
public R call(Object... args) {
if (args.length != 7) {
throw new RuntimeException("Func7 expecting 7 arguments.");
}
return f.call((T0) args[0], (T1) args[1], (T2) args[2], (T3) args[3], (T4) args[4], (T5) args[5], (T6) args[6]);
}
return (Object... args) -> {
if (args.length != 7)
throw new RuntimeException("Func7 expecting 7 arguments.");
return f.call((T0) args[0], (T1) args[1], (T2) args[2], (T3) args[3], (T4) args[4], (T5) args[5], (T6) args[6]);
};
}
/**
* Convert a function to FuncN to allow heterogeneous handling of functions with different arities.
*
* Convert a function to FuncN to allow heterogeneous handling of functions
* with different arities.
*
* @param f
* @return {@link FuncN}
*/
public static <T0, T1, T2, T3, T4, T5, T6, T7, R> FuncN<R> fromFunc(final Func8<T0, T1, T2, T3, T4, T5, T6, T7, R> f) {
return new FuncN<R>() {
@SuppressWarnings("unchecked")
@Override
public R call(Object... args) {
if (args.length != 8) {
throw new RuntimeException("Func8 expecting 8 arguments.");
}
return f.call((T0) args[0], (T1) args[1], (T2) args[2], (T3) args[3], (T4) args[4], (T5) args[5], (T6) args[6], (T7) args[7]);
}
return (Object... args) -> {
if (args.length != 8)
throw new RuntimeException("Func8 expecting 8 arguments.");
return f.call((T0) args[0], (T1) args[1], (T2) args[2], (T3) args[3], (T4) args[4], (T5) args[5], (T6) args[6], (T7) args[7]);
};
}
/**
* Convert a function to FuncN to allow heterogeneous handling of functions with different arities.
*
* Convert a function to FuncN to allow heterogeneous handling of functions
* with different arities.
*
* @param f
* @return {@link FuncN}
*/
public static <T0, T1, T2, T3, T4, T5, T6, T7, T8, R> FuncN<R> fromFunc(final Func9<T0, T1, T2, T3, T4, T5, T6, T7, T8, R> f) {
return new FuncN<R>() {
@SuppressWarnings("unchecked")
@Override
public R call(Object... args) {
if (args.length != 9) {
throw new RuntimeException("Func9 expecting 9 arguments.");
}
return f.call((T0) args[0], (T1) args[1], (T2) args[2], (T3) args[3], (T4) args[4], (T5) args[5], (T6) args[6], (T7) args[7], (T8) args[8]);
}
return (Object... args) -> {
if (args.length != 9)
throw new RuntimeException("Func9 expecting 9 arguments.");
return f.call((T0) args[0], (T1) args[1], (T2) args[2], (T3) args[3], (T4) args[4], (T5) args[5], (T6) args[6], (T7) args[7], (T8) args[8]);
};
}
/**
* Convert a function to FuncN to allow heterogeneous handling of functions with different arities.
*
* Convert a function to FuncN to allow heterogeneous handling of functions
* with different arities.
*
* @param f
* @return {@link FuncN}
*/
public static FuncN<Void> fromAction(final Action0 f) {
return new FuncN<Void>() {
@Override
public Void call(Object... args) {
if (args.length != 0) {
throw new RuntimeException("Action0 expecting 0 arguments.");
}
f.call();
return null;
}
return (Object... args) -> {
if (args.length != 0)
throw new RuntimeException("Action0 expecting 0 arguments.");
f.call();
return null;
};
}
/**
* Convert a function to FuncN to allow heterogeneous handling of functions with different arities.
*
* Convert a function to FuncN to allow heterogeneous handling of functions
* with different arities.
*
* @param f
* @return {@link FuncN}
*/
public static <T0> FuncN<Void> fromAction(final Action1<T0> f) {
return new FuncN<Void>() {
@SuppressWarnings("unchecked")
@Override
public Void call(Object... args) {
if (args.length != 1) {
throw new RuntimeException("Action1 expecting 1 argument.");
}
f.call((T0) args[0]);
return null;
}
return (Object... args) -> {
if (args.length != 1)
throw new RuntimeException("Action1 expecting 1 argument.");
f.call((T0) args[0]);
return null;
};
}
/**
* Convert a function to FuncN to allow heterogeneous handling of functions with different arities.
*
* Convert a function to FuncN to allow heterogeneous handling of functions
* with different arities.
*
* @param f
* @return {@link FuncN}
*/
public static <T0, T1> FuncN<Void> fromAction(final Action2<T0, T1> f) {
return new FuncN<Void>() {
@SuppressWarnings("unchecked")
@Override
public Void call(Object... args) {
if (args.length != 2) {
throw new RuntimeException("Action3 expecting 2 arguments.");
}
f.call((T0) args[0], (T1) args[1]);
return null;
}
return (Object... args) -> {
if (args.length != 2)
throw new RuntimeException("Action3 expecting 2 arguments.");
f.call((T0) args[0], (T1) args[1]);
return null;
};
}
/**
* Convert a function to FuncN to allow heterogeneous handling of functions with different arities.
*
* Convert a function to FuncN to allow heterogeneous handling of functions
* with different arities.
*
* @param f
* @return {@link FuncN}
*/
public static <T0, T1, T2> FuncN<Void> fromAction(final Action3<T0, T1, T2> f) {
return new FuncN<Void>() {
@SuppressWarnings("unchecked")
@Override
public Void call(Object... args) {
if (args.length != 3) {
throw new RuntimeException("Action3 expecting 3 arguments.");
}
f.call((T0) args[0], (T1) args[1], (T2) args[2]);
return null;
}
return (Object... args) -> {
if (args.length != 3)
throw new RuntimeException("Action3 expecting 3 arguments.");
f.call((T0) args[0], (T1) args[1], (T2) args[2]);
return null;
};
}