本文整理汇总了Java中clojure.lang.IFn.invoke方法的典型用法代码示例。如果您正苦于以下问题:Java IFn.invoke方法的具体用法?Java IFn.invoke怎么用?Java IFn.invoke使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类clojure.lang.IFn
的用法示例。
在下文中一共展示了IFn.invoke方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onLoad
import clojure.lang.IFn; //导入方法依赖的package包/类
@Override
public void onLoad() {
Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
instance = this;
logger = getLogger();
try (InputStream stream = getResource("clojure.yml")) {
clojureConfig = YamlConfiguration.loadConfiguration(stream);
mainNs = clojureConfig.getString("clojure");
if (mainNs == null) {
setEnabled(false);
throw new RuntimeException("The plugin couldn't be enabled due to Clojure ns missing.");
}
require.invoke(Clojure.read(mainNs));
} catch (IOException e) {
e.printStackTrace();
}
IFn setData = Clojure.var(mainNs, "setData");
if (setData == null) {
setEnabled(false);
throw new RuntimeException("The clojure plugin couldn't be enabled due to missing setData method.");
}
setData.invoke(this, getDataFolder(), getConfig(), getDescription(), getServer(), getLogger());
callIfExists("onLoad");
}
示例2: onCommand
import clojure.lang.IFn; //导入方法依赖的package包/类
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
IFn command = commands.get(cmd);
if (command == null) {
return true;
}
try {
command.invoke(sender, command, label, args);
} catch (Exception ex) {
//noinspection ConstantConditions
if (ex instanceof Return) {
return true;
}
sender.sendMessage(ChatColor.RED + "An error occurred within the code. Ask an admin about the stacktrace.");
getLogger().log(Level.SEVERE, "An error occurred!", ex);
}
return true;
}
示例3: expectationsRunner
import clojure.lang.IFn; //导入方法依赖的package包/类
@Test
public void expectationsRunner() {
try {
IFn require = Clojure.var("clojure.core", "require");
require.invoke(Clojure.read("expectations"));
IFn disableRun = Clojure.var("expectations", "disable-run-on-shutdown");
disableRun.invoke();
List<Symbol> namespaces = Util.importNsDeclarations(TestRunner.getTestNamespaces());
Util.tryInitNeko();
IFn runTests = Clojure.var("expectations", "run-all-tests");
Object result = runTests.invoke();
IFn shutdownAgents = Clojure.var("clojure.core", "shutdown-agents");
shutdownAgents.invoke();
} catch (Throwable t) {
t.printStackTrace();
}
}
示例4: reduce
import clojure.lang.IFn; //导入方法依赖的package包/类
@Override
public Object reduce(Object o, Iterator<Object> objectIterator) {
if(fn == null) {
IFn require = Clojure.var("clojure.core", "require");
require.invoke(Clojure.read(ns));
fn = Clojure.var(ns, sym);
}
Object result = seed;
while(objectIterator.hasNext()){
Object x = objectIterator.next();
result = fn.invoke(o, result, x);
}
return result;
}
示例5: map
import clojure.lang.IFn; //导入方法依赖的package包/类
public void map(Object key, Object value, Collector<Object, Object> collector){
if(fn == null) {
IFn require = Clojure.var("clojure.core", "require");
require.invoke(Clojure.read(ns));
fn = Clojure.var(ns, sym);
}
for (Object o : (Iterable)fn.invoke(key, value)){
Seqable s = (Seqable)o;
ISeq seq = s.seq();
Object k = seq.first();
Object v = seq.next().first();
collector.emit(k, v);
}
}
示例6: serverClose
import clojure.lang.IFn; //导入方法依赖的package包/类
public boolean serverClose(int status) {
if (!unsafe.compareAndSwapInt(this, closedRanOffset, 0, 1)) {
return false; // already closed
}
if (isWebSocket()) {
server.tryWrite(key, WsEncode(OPCODE_CLOSE, ByteBuffer.allocate(2)
.putShort((short) status).array()));
} else {
server.tryWrite(key, ByteBuffer.wrap(finalChunkBytes));
}
IFn f = closeHandler;
if (f != null) {
f.invoke(readable(0)); // server close is 0
}
return true;
}
示例7: loadClojureFn
import clojure.lang.IFn; //导入方法依赖的package包/类
private static void loadClojureFn() {
ClassLoader previous = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(IcepickProcessor.class.getClassLoader());
try {
Object ns = Clojure.read("icepick.processor");
IFn require = Clojure.var("clojure.core", "require");
require.invoke(ns);
PROCESS = Clojure.var("icepick.processor", "process");
} finally {
Thread.currentThread().setContextClassLoader(previous);
}
}
示例8: callIfExists
import clojure.lang.IFn; //导入方法依赖的package包/类
public void callIfExists(String namespace, String name, Object... args) {
require.invoke(namespace);
IFn method = Clojure.var(namespace, name);
if (method != null) {
if (args != null && args.length != 0) {
method.invoke(args);
} else {
method.invoke();
}
}
}
示例9: invoke
import clojure.lang.IFn; //导入方法依赖的package包/类
public static <T> T invoke(String namespace, String name, Object... args) {
if (!"clojure.core".equals(namespace)) {
IFn symbol = Clojure.var("clojure.core", "symbol");
IFn require = Clojure.var("clojure.core", "require");
Object sym = symbol.invoke(namespace);
require.invoke(sym);
}
IFn apply = Clojure.var("clojure.core", "apply");
return (T) apply.invoke(Clojure.var(namespace, name), args);
}
示例10: selectNamespace
import clojure.lang.IFn; //导入方法依赖的package包/类
public static NamespaceSelector selectNamespace(String namespace) {
IFn symbol = Clojure.var("clojure.core", "symbol");
IFn require = Clojure.var("clojure.core", "require");
IFn findNs = Clojure.var("clojure.core", "find-ns");
Object sym = symbol.invoke(namespace);
require.invoke(sym);
Namespace ns = (Namespace) findNs.invoke(sym);
return new NamespaceSelector(ns);
}
示例11: callClojureFn
import clojure.lang.IFn; //导入方法依赖的package包/类
public static void callClojureFn(String fn, Object... args) {
Symbol var = (Symbol)Clojure.read(fn);
IFn require = Clojure.var("clojure.core", "require");
require.invoke(Symbol.create(var.getNamespace()));
ISeq argsSeq = ArraySeq.create(args);
Clojure.var(var.getNamespace(), var.getName()).applyTo(argsSeq);
}
示例12: toBiFunction
import clojure.lang.IFn; //导入方法依赖的package包/类
public static BiFunction toBiFunction(final Optional<IFn> optFn) {
if (optFn.isPresent()) {
IFn fn = optFn.get();
return (x, y) -> fn.invoke(x, y);
} else {
return null;
}
}
示例13: toFunction
import clojure.lang.IFn; //导入方法依赖的package包/类
public static Function toFunction(final Optional<IFn> optFn) {
if (optFn.isPresent()) {
IFn fn = optFn.get();
return (x) -> fn.invoke(x);
} else {
return null;
}
}
示例14: toSupplier
import clojure.lang.IFn; //导入方法依赖的package包/类
public static Supplier toSupplier(final Optional<IFn> optFn) {
if (optFn.isPresent()) {
IFn fn = optFn.get();
return () -> fn.invoke();
} else {
return null;
}
}
示例15: warn
import clojure.lang.IFn; //导入方法依赖的package包/类
/**
* Passes the contents as a warn level message to the log.
* @param message An object containing a warn level message to be passed to the log
*/
public static void warn(Object message){
IFn requireFn = Clojure.var(CORE, Require);
requireFn.invoke(Clojure.read(TIMBRE));
IFn warnFn = Clojure.var(TIMBRE, WarnFn);
warnFn.invoke(message);
}