本文整理了Java中org.jruby.RubyHash.fastARef
方法的一些代码示例,展示了RubyHash.fastARef
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。RubyHash.fastARef
方法的具体详情如下:
包路径:org.jruby.RubyHash
类名称:RubyHash
方法名:fastARef
暂无
代码示例来源:origin: org.jruby/jruby-complete
private static IRubyObject hashGet(final ThreadContext context, final RubyHash hash, final String key) {
IRubyObject val = hash.fastARef(context.runtime.newSymbol(key));
if (val == null || val == context.nil) return null;
return val;
}
代码示例来源:origin: org.jruby/jruby-complete
@JRubyMethod(name = { "[]", "find" })
public final IRubyObject find(ThreadContext context, IRubyObject query) {
if (query instanceof RubySymbol) {
IRubyObject value = kv_map.fastARef(query);
return value != null ? value : context.nil;
} else if (query instanceof RubyInteger) {
RubySymbol symbol = valueToSymbol.get((Long)((RubyInteger) query).getLongValue());
return symbol != null ? symbol : context.nil;
} else {
return context.nil;
}
}
代码示例来源:origin: org.jruby/jruby-core
@JRubyMethod(name = { "[]", "find" })
public final IRubyObject find(ThreadContext context, IRubyObject query) {
if (query instanceof RubySymbol) {
IRubyObject value = kv_map.fastARef(query);
return value != null ? value : context.nil;
} else if (query instanceof RubyInteger) {
RubySymbol symbol = valueToSymbol.get((Long)((RubyInteger) query).getLongValue());
return symbol != null ? symbol : context.nil;
} else {
return context.nil;
}
}
代码示例来源:origin: org.jruby/jruby-complete
@Override
public void visit(ThreadContext context, RubyHash self, IRubyObject key, IRubyObject value, int index, RubyHash otherHash) {
IRubyObject value2 = otherHash.fastARef(key);
if (value2 == null) {
// other hash does not contain key
throw MISMATCH;
}
if (!Helpers.rbEql(context, value, value2).isTrue()) {
throw MISMATCH;
}
}
};
代码示例来源:origin: org.jruby/jruby-core
@Override
public void visit(ThreadContext context, RubyHash self, IRubyObject key, IRubyObject value, int index, RubyHash otherHash) {
IRubyObject value2 = otherHash.fastARef(key);
if (value2 == null) {
// other hash does not contain key
throw MISMATCH;
}
if (!Helpers.rbEql(context, value, value2).isTrue()) {
throw MISMATCH;
}
}
};
代码示例来源:origin: org.jruby/jruby-complete
@Override
public void visit(ThreadContext context, RubyHash self, IRubyObject key, IRubyObject value, int index, RubyHash otherHash) {
IRubyObject value2 = otherHash.fastARef(key);
if (value2 == null) {
// other hash does not contain key
throw MISMATCH;
}
if (!Helpers.rbEqual(context, value, value2).isTrue()) {
throw MISMATCH;
}
}
};
代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby
private synchronized IRubyObject lookupAndCacheValue(IRubyObject obj) {
IRubyObject value = enums.fastARef(obj);
if (value.isNil() || !(value instanceof RubyInteger)) {
throw obj.getRuntime().newArgumentError("invalid enum value, " + obj.inspect());
}
IdentityHashMap<RubySymbol, RubyInteger> s2v = new IdentityHashMap<RubySymbol, RubyInteger>(symbolToValue);
s2v.put((RubySymbol) obj, (RubyInteger) value);
this.symbolToValue = new IdentityHashMap<RubySymbol, RubyInteger>(s2v);
return value;
}
}
代码示例来源:origin: org.jruby/jruby-complete
private synchronized IRubyObject lookupAndCacheValue(ThreadContext context, IRubyObject obj) {
IRubyObject value = enums instanceof Enums ? ((Enums)enums).mapSymbol(context, obj) : ((RubyHash)enums).fastARef(obj);
if (value.isNil() || !(value instanceof RubyInteger)) {
throw obj.getRuntime().newArgumentError("invalid enum value, " + obj.inspect());
}
IdentityHashMap<RubySymbol, RubyInteger> s2v = new IdentityHashMap<RubySymbol, RubyInteger>(symbolToValue);
s2v.put((RubySymbol) obj, (RubyInteger) value);
this.symbolToValue = new IdentityHashMap<RubySymbol, RubyInteger>(s2v);
return value;
}
}
代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby
private Type lookupType(Ruby runtime, IRubyObject name) {
IRubyObject type = ffi.typedefs.fastARef(name);
if (type instanceof Type) {
return (Type) type;
}
if ((type = ffi.ffiModule.callMethod(runtime.getCurrentContext(), "find_type", name)) instanceof Type) {
return (Type) type;
}
throw runtime.newTypeError("cannot resolve type " + name);
}
}
代码示例来源:origin: org.jruby/jruby-complete
private Type lookupType(Ruby runtime, IRubyObject name, IRubyObject typeMap) {
IRubyObject type = ffi.typedefs.fastARef(name);
if (type instanceof Type) {
return (Type) type;
}
IRubyObject args[] = new IRubyObject[]{name, typeMap};
if ((type = ffi.ffiModule.callMethod(runtime.getCurrentContext(), "find_type", args)) instanceof Type) {
return (Type) type;
}
throw runtime.newTypeError("cannot resolve type " + name);
}
}
代码示例来源:origin: org.jruby/jruby-core
private RubyHash makeHash(ThreadContext context, RubyHash hash, Block block) {
for (int i = 0; i < realLength; i++) {
IRubyObject v = elt(i);
IRubyObject k = block.yield(context, v);
if (hash.fastARef(k) == null) hash.fastASet(k, v);
}
return hash;
}
代码示例来源:origin: org.jruby/jruby-core
public static IRubyObject receiveKeywordArg(ThreadContext context, IRubyObject[] args, int required, String id, boolean acceptsKeywordArgument) {
RubyHash keywordArguments = extractKwargsHash(context, args, required, acceptsKeywordArgument);
if (keywordArguments == null) return UndefinedValue.UNDEFINED;
RubySymbol keywordName = context.runtime.newSymbol(id);
if (keywordArguments.fastARef(keywordName) == null) return UndefinedValue.UNDEFINED;
// SSS FIXME: Can we use an internal delete here?
// Enebo FIXME: Delete seems wrong if we are doing this for duplication purposes.
return keywordArguments.delete(context, keywordName, Block.NULL_BLOCK);
}
代码示例来源:origin: org.jruby/jruby-complete
public static IRubyObject receiveKeywordArg(ThreadContext context, IRubyObject[] args, int required, String id, boolean acceptsKeywordArgument) {
RubyHash keywordArguments = extractKwargsHash(context, args, required, acceptsKeywordArgument);
if (keywordArguments == null) return UndefinedValue.UNDEFINED;
RubySymbol keywordName = context.runtime.newSymbol(id);
if (keywordArguments.fastARef(keywordName) == null) return UndefinedValue.UNDEFINED;
// SSS FIXME: Can we use an internal delete here?
// Enebo FIXME: Delete seems wrong if we are doing this for duplication purposes.
return keywordArguments.delete(context, keywordName, Block.NULL_BLOCK);
}
代码示例来源:origin: org.jruby/jruby-complete
private static IRubyObject hashARef(Ruby runtime, IRubyObject hash, String symbol) {
if (hash == null || !(hash instanceof RubyHash)) return runtime.getNil();
IRubyObject value = ((RubyHash) hash).fastARef(runtime.newSymbol(symbol));
return value == null ? runtime.getNil() : value;
}
代码示例来源:origin: org.jruby/jruby-complete
static void checkUnsupportedOptions(ThreadContext context, RubyHash opts, String[] unsupported, String error) {
final Ruby runtime = context.runtime;
for (String key : unsupported) {
if (opts.fastARef(runtime.newSymbol(key)) != null) {
runtime.getWarnings().warn(error + ": " + key);
}
}
}
代码示例来源:origin: org.jruby/jruby-complete
/**
* Check if HOME environment variable is not nil nor empty
* @param context
*/
private static RubyString checkHome(ThreadContext context) {
Ruby runtime = context.runtime;
IRubyObject home = runtime.getENV().fastARef(RubyString.newStringShared(runtime, RubyDir.HOME));
if (home == null || home == context.nil || ((RubyString) home).size() == 0) {
throw runtime.newArgumentError("couldn't find HOME environment -- expanding `~'");
}
return (RubyString) home;
}
代码示例来源:origin: org.jruby/jruby-complete
@JRubyMethod(module = true)
public static IRubyObject subclasses(ThreadContext context, IRubyObject recv, IRubyObject arg, IRubyObject opts) {
boolean recurseAll = false;
opts = ArgsUtil.getOptionsArg(context.runtime, opts);
if (opts != context.nil) {
IRubyObject all = ((RubyHash) opts).fastARef(context.runtime.newSymbol("all"));
if (all != null) recurseAll = all.isTrue();
}
return subclasses(context, recv, arg instanceof RubyClass ? (RubyClass) arg : arg.getMetaClass(), recurseAll);
}
代码示例来源:origin: org.jruby/jruby-core
@JRubyMethod(module = true)
public static IRubyObject subclasses(ThreadContext context, IRubyObject recv, IRubyObject arg, IRubyObject opts) {
boolean recurseAll = false;
opts = ArgsUtil.getOptionsArg(context.runtime, opts);
if (opts != context.nil) {
IRubyObject all = ((RubyHash) opts).fastARef(context.runtime.newSymbol("all"));
if (all != null) recurseAll = all.isTrue();
}
return subclasses(context, recv, arg instanceof RubyClass ? (RubyClass) arg : arg.getMetaClass(), recurseAll);
}
代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby
@JRubyMethod(name = { "[]", "find" })
public final IRubyObject find(ThreadContext context, IRubyObject query) {
if (query instanceof RubySymbol) {
IRubyObject value = kv_map.fastARef(query);
return value != null ? value : context.runtime.getNil();
} else if (query instanceof RubyInteger) {
RubySymbol symbol = valueToSymbol.get((int) ((RubyInteger) query).getLongValue());
return symbol != null ? symbol : context.runtime.getNil();
} else {
return context.runtime.getNil();
}
}
代码示例来源:origin: org.jruby/jruby-complete
public static int intValue(IRubyObject obj, RubyHash enums) {
if (obj instanceof RubyInteger) {
return (int) ((RubyInteger) obj).getLongValue();
} else if (obj instanceof RubySymbol) {
IRubyObject value = enums.fastARef(obj);
if (value.isNil()) {
throw obj.getRuntime().newArgumentError("invalid enum value, " + obj.inspect());
}
return (int) longValue(value);
} else {
return (int) longValue(obj);
}
}
内容来源于网络,如有侵权,请联系作者删除!