Simplify VersionedCallable
Simplify VersionedRunnable Remove ExceptionlessCallable
Dieser Commit ist enthalten in:
Ursprung
97a766c797
Commit
e01a72a42b
@ -1,25 +0,0 @@
|
||||
/*
|
||||
This file is a part of the SteamWar software.
|
||||
|
||||
Copyright (C) 2020 SteamWar.de-Serverteam
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.core;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface ExceptionlessCallable<T> {
|
||||
T call();
|
||||
}
|
@ -21,25 +21,27 @@
|
||||
|
||||
package de.steamwar.core;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
public class VersionedCallable<T> {
|
||||
|
||||
private ExceptionlessCallable<T> exceptionlessCallable;
|
||||
private Callable<T> callable;
|
||||
private int minVersion;
|
||||
|
||||
public VersionedCallable(ExceptionlessCallable<T> exceptionlessCallable, int minVersion) {
|
||||
this.exceptionlessCallable = exceptionlessCallable;
|
||||
public VersionedCallable(Callable<T> callable, int minVersion) {
|
||||
this.callable = callable;
|
||||
this.minVersion = minVersion;
|
||||
}
|
||||
|
||||
public T call() {
|
||||
return exceptionlessCallable.call();
|
||||
}
|
||||
|
||||
public static <T> T call(VersionedCallable<T>... versionedCallables) {
|
||||
for (int i = versionedCallables.length - 1; i >= 0; i--) {
|
||||
VersionedCallable<T> versionedCallable = versionedCallables[i];
|
||||
if (Core.getVersion() >= versionedCallable.minVersion) {
|
||||
return versionedCallable.call();
|
||||
try {
|
||||
return versionedCallable.callable.call();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Could not run version dependant code", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new SecurityException();
|
||||
|
@ -31,15 +31,11 @@ public class VersionedRunnable {
|
||||
this.minVersion = minVersion;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
runnable.run();
|
||||
}
|
||||
|
||||
public static void call(VersionedRunnable... versionedRunnables) {
|
||||
for (int i = versionedRunnables.length - 1; i >= 0; i--) {
|
||||
VersionedRunnable versionedRunnable = versionedRunnables[i];
|
||||
if (Core.getVersion() >= versionedRunnable.minVersion) {
|
||||
versionedRunnable.run();
|
||||
versionedRunnable.runnable.run();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren