本文整理汇总了Java中org.jruby.RubyHash.put方法的典型用法代码示例。如果您正苦于以下问题:Java RubyHash.put方法的具体用法?Java RubyHash.put怎么用?Java RubyHash.put使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jruby.RubyHash
的用法示例。
在下文中一共展示了RubyHash.put方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: map2hash
import org.jruby.RubyHash; //导入方法依赖的package包/类
@SuppressWarnings("unchecked") private static RubyHash map2hash(Ruby ruby, Map<String, Object> ourCaps) {
RubyHash hash = new RubyHash(ruby);
Set<String> keySet = ourCaps.keySet();
for (String key : keySet) {
RubySymbol keySym = RubySymbol.newSymbol(ruby, key);
Object v = ourCaps.get(key);
if (v instanceof String) {
hash.put(keySym, RubyString.newString(ruby, (String) v));
} else if(v instanceof Boolean) {
hash.put(keySym, RubyBoolean.newBoolean(ruby, (boolean) v));
} else if (v instanceof List) {
hash.put(keySym, map2list(ruby, (List<?>) v));
} else {
hash.put(keySym, map2hash(ruby, (Map<String, Object>) v));
}
}
return hash;
}
示例2: pigToRuby
import org.jruby.RubyHash; //导入方法依赖的package包/类
/**
* A type specific conversion routine for Pig Maps. This only deals with maps
* with String keys, which is all that Pig supports.
*
* @param ruby the Ruby runtime to create objects in
* @param object map to convert. In Pig, only maps with String keys are
* supported
* @return analogous Ruby type
* @throws ExecException object contains a key that can't be convert to a Ruby type
*/
public static <T> RubyHash pigToRuby(Ruby ruby, Map<T, ?> object) throws ExecException {
RubyHash newMap = RubyHash.newHash(ruby);
boolean checkType = false;
for (Map.Entry<T, ?> entry : object.entrySet()) {
T key = entry.getKey();
if (!checkType) {
if (!(key instanceof String))
throw new ExecException("pigToRuby only supports converting Maps with String keys");
checkType = true;
}
newMap.put(key, pigToRuby(ruby, entry.getValue()));
}
return newMap;
}
示例3: convertToRubyHash
import org.jruby.RubyHash; //导入方法依赖的package包/类
private RubyHash convertToRubyHash(Set<Map.Entry<String, Object>> entries) {
RubyHash hash = newHash(runtime);
for (Map.Entry<String, Object> entry : entries) {
String key = entry.getKey();
Object value = entry.getValue();
if (key.equals("rack.input")) {
value = new JRubyRackInput(runtime, (RackInput) value);
}
if (key.equals("rack.version")) {
value = convertToRubyArray((List<Integer>) value);
}
hash.put(key, value);
}
return hash;
}
示例4: convertJavaMapToRubyHash
import org.jruby.RubyHash; //导入方法依赖的package包/类
@SuppressWarnings("rawtypes")
public static RubyHash convertJavaMapToRubyHash(Ruby runtime, Map map) {
RubyHash rubyHash = RubyHash.newHash( runtime );
for (Object object : map.entrySet()) {
Entry entry = (Entry) object;
rubyHash.put( entry.getKey(), entry.getValue() );
}
return rubyHash;
}
示例5: convertMapToRubyHashWithSymbolsIfNecessary
import org.jruby.RubyHash; //导入方法依赖的package包/类
public static RubyHash convertMapToRubyHashWithSymbolsIfNecessary(Ruby rubyRuntime, Map<Object, Object> options) {
RubyHash rubyHash = new RubyHash(rubyRuntime);
Set<Entry<Object, Object>> optionsSet = options.entrySet();
for (Entry<Object, Object> entry : optionsSet) {
Object keyType = entry.getKey();
if (isNotARubySymbol(keyType)) {
String key = (String) keyType;
Object value = entry.getValue();
RubySymbol newSymbol = RubyUtils.toSymbol(rubyRuntime, key);
IRubyObject iRubyValue = toRubyObject(rubyRuntime, value);
rubyHash.put(newSymbol, iRubyValue);
}
}
return rubyHash;
}
示例6: convertMapToRubyHashWithSymbols
import org.jruby.RubyHash; //导入方法依赖的package包/类
public static RubyHash convertMapToRubyHashWithSymbols(Ruby rubyRuntime, Map<String, Object> options) {
RubyHash rubyHash = new RubyHash(rubyRuntime);
Set<Entry<String, Object>> optionsSet = options.entrySet();
for (Entry<String, Object> entry : optionsSet) {
String key = entry.getKey();
Object value = entry.getValue();
RubySymbol newSymbol = RubyUtils.toSymbol(rubyRuntime, key);
IRubyObject iRubyValue = toRubyObject(rubyRuntime, value);
rubyHash.put(newSymbol, iRubyValue);
}
return rubyHash;
}
示例7: toNoneSymbolsRubyHash
import org.jruby.RubyHash; //导入方法依赖的package包/类
public static RubyHash toNoneSymbolsRubyHash(Ruby rubyRuntime, Map<String, Object> map) {
RubyHash rubyHash = new RubyHash(rubyRuntime);
Set<Entry<String, Object>> entrySet = map.entrySet();
for (Entry<String, Object> entry : entrySet) {
rubyHash.put(toJavaObject(entry.getKey()), toJavaObject(entry.getValue()));
}
return rubyHash;
}