本文整理汇总了Java中org.jruby.RubyHash.newHash方法的典型用法代码示例。如果您正苦于以下问题:Java RubyHash.newHash方法的具体用法?Java RubyHash.newHash怎么用?Java RubyHash.newHash使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jruby.RubyHash
的用法示例。
在下文中一共展示了RubyHash.newHash方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: getAttributes
import org.jruby.RubyHash; //导入方法依赖的package包/类
public IRubyObject getAttributes(ThreadContext context) {
if(attributeList == null) return context.getRuntime().getNil();
RubyHash hash = RubyHash.newHash(context.getRuntime());
for (int i=0; i<attributeList.length; i++) {
IRubyObject k = stringOrBlank(context.getRuntime(), attributeList.names.get(i));
IRubyObject v = stringOrBlank(context.getRuntime(), attributeList.values.get(i));
if (context.getRuntime().is1_9()) hash.op_aset19(context, k, v);
else hash.op_aset(context, k, v);
}
return hash;
}
示例4: getNamespaces
import org.jruby.RubyHash; //导入方法依赖的package包/类
public IRubyObject getNamespaces(ThreadContext context) {
if(namespaces == null) return ruby.getNil();
RubyHash hash = RubyHash.newHash(ruby);
Set<String> keys = namespaces.keySet();
for (String key : keys) {
String stringValue = namespaces.get(key);
IRubyObject k = stringOrBlank(context.getRuntime(), key);
IRubyObject v = stringOrBlank(context.getRuntime(), stringValue);
if (context.getRuntime().is1_9()) hash.op_aset19(context, k, v);
else hash.op_aset(context, k, v);
}
return hash;
}
示例5: extractDecls
import org.jruby.RubyHash; //导入方法依赖的package包/类
/**
* Recursively extract various DTD declarations and store them in
* the various collections.
*/
protected void extractDecls(ThreadContext context) {
Ruby runtime = context.getRuntime();
// initialize data structures
allDecls = RubyArray.newArray(runtime);
attributes = RubyHash.newHash(runtime);
elements = RubyHash.newHash(runtime);
entities = RubyHash.newHash(runtime);
notations = RubyHash.newHash(runtime);
contentModels = RubyHash.newHash(runtime);
children = runtime.getNil();
// recursively extract decls
if (node == null) return; // leave all the decl hash's empty
extractDecls(context, node.getFirstChild());
// convert allDecls to a NodeSet
children = XmlNodeSet.newXmlNodeSet(context, allDecls);
// add attribute decls as attributes to the matching element decl
RubyArray keys = attributes.keys();
for (int i = 0; i < keys.getLength(); ++i) {
IRubyObject akey = keys.entry(i);
IRubyObject val;
val = attributes.op_aref(context, akey);
if (val.isNil()) continue;
XmlAttributeDecl attrDecl = (XmlAttributeDecl) val;
IRubyObject ekey = attrDecl.element_name(context);
val = elements.op_aref(context, ekey);
if (val.isNil()) continue;
XmlElementDecl elemDecl = (XmlElementDecl) val;
elemDecl.appendAttrDecl(attrDecl);
}
// add content models to the matching element decl
keys = contentModels.keys();
for (int i = 0; i < keys.getLength(); ++i) {
IRubyObject key = keys.entry(i);
IRubyObject cm = contentModels.op_aref(context, key);
IRubyObject elem = elements.op_aref(context, key);
if (elem.isNil()) continue;
if (((XmlElementDecl)elem).isEmpty()) continue;
((XmlElementDecl) elem).setContentModel(cm);
}
}