本文整理汇总了Java中org.jruby.RubyArray类的典型用法代码示例。如果您正苦于以下问题:Java RubyArray类的具体用法?Java RubyArray怎么用?Java RubyArray使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RubyArray类属于org.jruby包,在下文中一共展示了RubyArray类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: map2list
import org.jruby.RubyArray; //导入依赖的package包/类
@SuppressWarnings("unchecked") private static RubyArray map2list(Ruby ruby, List<?> list) {
RubyArray array = new RubyArray(ruby, list.size());
int index = 0;
for (Object v : list) {
if (v instanceof String) {
array.set(index++, RubyString.newString(ruby, (String) v));
} else if(v instanceof Boolean) {
array.set(index++, RubyBoolean.newBoolean(ruby, (boolean) v));
} else if (v instanceof List) {
array.set(index++, map2list(ruby, (List<?>) v));
} else {
array.set(index++, map2hash(ruby, (Map<String, Object>) v));
}
}
return array;
}
示例2: valueIsTruthy
import org.jruby.RubyArray; //导入依赖的package包/类
public boolean valueIsTruthy(Object value) {
if(value instanceof IRubyObject) {
IRubyObject o = (IRubyObject)value;
if(o == null) {
return false;
} else if(o instanceof RubyString) {
return !(((RubyString)o).isEmpty());
} else if(o instanceof RubyBoolean) {
return (o instanceof RubyBoolean.True);
} else if(o instanceof RubyArray) {
return !(((RubyArray)o).isEmpty());
} else if(value instanceof RubyNumeric) {
return ((RubyNumeric)value).getDoubleValue() != 0.0;
}
return false;
} else {
return super.valueIsTruthy(value);
}
}
示例3: applyLoadPaths
import org.jruby.RubyArray; //导入依赖的package包/类
/**
* applyLoadPaths
*
* @param container
*/
protected void applyLoadPaths(Ruby runtime)
{
if (this._loadPaths != null && this._loadPaths.size() > 0)
{
IRubyObject object = runtime.getLoadService().getLoadPath();
if (object instanceof RubyArray)
{
RubyArray loadPathArray = (RubyArray) object;
// save copy for later
this._originalLoadPaths = (RubyArray) loadPathArray.dup();
// Add our custom load paths
for (String loadPath : this._loadPaths)
{
RubyString toAdd = runtime.newString(loadPath.replace('\\', '/'));
loadPathArray.append(toAdd);
}
}
}
}
示例4: unapplyLoadPaths
import org.jruby.RubyArray; //导入依赖的package包/类
/**
* unapplyLoadPaths
*
* @param runtime
*/
protected void unapplyLoadPaths(Ruby runtime)
{
if (this._loadPaths != null && this._loadPaths.size() > 0)
{
IRubyObject object = runtime.getLoadService().getLoadPath();
if (object != null && object instanceof RubyArray)
{
RubyArray loadPathArray = (RubyArray) object;
// Restore original content
loadPathArray.replace(this._originalLoadPaths);
// lose reference
this._originalLoadPaths = null;
}
}
}
示例5: set
import org.jruby.RubyArray; //导入依赖的package包/类
@JRubyMethod(name = "set", required=2)
public IRubyObject set(ThreadContext context, IRubyObject i, IRubyObject val) {
int j = RubyNumeric.num2int(i);
if (j >=0 && j < cnt) {
if (j >= tailoff()) {
RubyArray newTail = tail.aryDup();
newTail.store(j & 0x01f, val);
return new PersistentVector(context.runtime, getMetaClass()).initialize(context, cnt, shift, root, newTail);
}
return new PersistentVector(context.runtime, getMetaClass()).initialize(context, cnt, shift, doSet(context, shift, root, j, val), tail);
}
if (j == cnt)
add(context, val);
throw new IndexOutOfBoundsException();
}
示例6: add
import org.jruby.RubyArray; //导入依赖的package包/类
@JRubyMethod(name = {"add", "append"}, required = 1)
public IRubyObject add(ThreadContext context, IRubyObject val) {
if (cnt - tailoff() < 32) {
PersistentVector ret = new PersistentVector(context.runtime, getMetaClass());
RubyArray newTail = tail.aryDup();
newTail.append(val);
return ret.initialize(context, this.cnt+1, this.shift, this.root, newTail);
}
Node newroot;
Node tailnode = new Node(context.runtime, Node).initialize_params_arry(context, root.edit, tail);
int newshift = shift;
if ((cnt >>> 5) > (1 << shift)) {
newroot = new Node(context.runtime, Node).initialize_params(context, root.edit);
newroot.array.store(0, root);
newroot.array.store(1, newPath(context, root.edit, shift, tailnode));
newshift += 5;
} else
newroot = pushTail(context, shift, root, tailnode);
RubyArray arry = RubyArray.newArray(context.runtime);
arry.store(0, val);
return new PersistentVector(context.runtime, getMetaClass()).initialize(context, cnt + 1, newshift, newroot, arry);
}
示例7: pop
import org.jruby.RubyArray; //导入依赖的package包/类
@JRubyMethod(name = "pop")
public IRubyObject pop(ThreadContext context){
if(cnt == 0)
throw new IllegalStateException("Can't pop empty vector");
if(cnt == 1)
return emptyVector(context, getMetaClass());
if(cnt-tailoff() > 1)
{
RubyArray newTail = (RubyArray) tail.subseq(0, tail.getLength()-1).dup();
return new PersistentVector(context.runtime, getMetaClass()).initialize(context, cnt - 1, shift, root, newTail);
}
RubyArray newtail = arrayFor(cnt - 2);
Node newroot = popTail(context, shift, root);
int newshift = shift;
if(newroot == null)
{
newroot = emptyNode(context);
}
if(shift > 5 && newroot.array.entry(1) == null)
{
newroot = (Node) newroot.array.entry(0);
newshift -= 5;
}
return new PersistentVector(context.runtime, getMetaClass()).initialize(context, cnt - 1, newshift, newroot, newtail);
}
示例8: eql
import org.jruby.RubyArray; //导入依赖的package包/类
@JRubyMethod(name = "eql?")
public IRubyObject eql(ThreadContext context, IRubyObject obj) {
Ruby runtime = context.runtime;
if (this == obj) {
return runtime.getTrue();
}
if (obj instanceof PersistentVector) {
Node otherRoot = ((PersistentVector)obj).root;
RubyArray otherTail = ((PersistentVector)obj).tail;
if (root.equals(otherRoot) && tail.equals(otherTail)) {
return runtime.getTrue();
}
}
return runtime.getFalse();
}
示例9: read
import org.jruby.RubyArray; //导入依赖的package包/类
@JRubyMethod
public IRubyObject read(ThreadContext context) {
position++;
while (nodeQueue.size() <= position && continueParsing) {
readMoreData(context);
}
if(currentNode() == null) {
return context.nil;
} else if(currentNode().isError()) {
RubyArray errors = (RubyArray) this.getInstanceVariable("@errors");
errors.append(currentNode().toSyntaxError());
this.setInstanceVariable("@errors", errors);
throw new RaiseException((XmlSyntaxError) currentNode().toSyntaxError());
} else {
return this;
}
}
示例10: getAttributesNodes
import org.jruby.RubyArray; //导入依赖的package包/类
public IRubyObject getAttributesNodes() {
RubyArray array = RubyArray.newArray(ruby);
if (attributeList != null && attributeList.length > 0) {
if (document == null) {
XmlDocument doc = (XmlDocument) XmlDocument.rbNew(ruby.getCurrentContext(), getNokogiriClass(ruby, "Nokogiri::XML::Document"), new IRubyObject[0]);
document = doc.getDocument();
}
for (int i=0; i<attributeList.length; i++) {
if (!isNamespace(attributeList.names.get(i))) {
Attr attr = document.createAttributeNS(attributeList.namespaces.get(i), attributeList.names.get(i));
attr.setValue(attributeList.values.get(i));
XmlAttr xmlAttr = (XmlAttr) NokogiriService.XML_ATTR_ALLOCATOR.allocate(ruby, getNokogiriClass(ruby, "Nokogiri::XML::Attr"));
xmlAttr.setNode(ruby.getCurrentContext(), attr);
array.append(xmlAttr);
}
}
}
return array;
}
示例11: fromRubyToObject
import org.jruby.RubyArray; //导入依赖的package包/类
private Object fromRubyToObject(IRubyObject o) {
Ruby runtime = this.handler.getRuntime();
if(o instanceof RubyString) {
return o.toJava(String.class);
} else if (o instanceof RubyFloat) {
return o.toJava(Double.class);
} else if (o instanceof RubyBoolean) {
return o.toJava(Boolean.class);
} else if (o instanceof XmlNodeSet) {
return (NodeList)o;
} else if (o instanceof RubyArray) {
XmlNodeSet xmlNodeSet = XmlNodeSet.newXmlNodeSet(runtime.getCurrentContext(), (RubyArray)o);
return (NodeList)xmlNodeSet;
} else /*if (o instanceof XmlNode)*/ {
return ((XmlNode) o).getNode();
}
}
示例12: add_child
import org.jruby.RubyArray; //导入依赖的package包/类
public void add_child(ThreadContext context, XmlNode child) {
// Some magic for DocumentFragment
Ruby ruby = context.getRuntime();
XmlNodeSet children = (XmlNodeSet) child.children(context);
long length = children.length();
RubyArray childrenArray = children.convertToArray();
if(length != 0) {
for(int i = 0; i < length; i++) {
XmlNode item = (XmlNode) ((XmlNode) childrenArray.aref(ruby.newFixnum(i))).dup_implementation(context, true);
add_child(context, item);
}
}
}
示例13: attribute_nodes
import org.jruby.RubyArray; //导入依赖的package包/类
@JRubyMethod
public IRubyObject attribute_nodes(ThreadContext context) {
NamedNodeMap nodeMap = this.node.getAttributes();
Ruby ruby = context.getRuntime();
if(nodeMap == null){
return ruby.newEmptyArray();
}
RubyArray attr = ruby.newArray();
for(int i = 0; i < nodeMap.getLength(); i++) {
if ((doc instanceof HtmlDocument) || !NokogiriHelpers.isNamespace(nodeMap.item(i))) {
attr.append(getCachedNodeOrCreate(context.getRuntime(), nodeMap.item(i)));
}
}
return attr;
}
示例14: findNamespaceHref
import org.jruby.RubyArray; //导入依赖的package包/类
private String findNamespaceHref(ThreadContext context, String prefix) {
XmlNode currentNode = this;
while(currentNode != document(context)) {
RubyArray namespaces = (RubyArray) currentNode.namespace_scopes(context);
Iterator iterator = namespaces.iterator();
while(iterator.hasNext()) {
XmlNamespace namespace = (XmlNamespace) iterator.next();
if (namespace.getPrefix().equals(prefix)) {
return namespace.getHref();
}
}
if (currentNode.parent(context).isNil()) {
break;
} else {
currentNode = (XmlNode) currentNode.parent(context);
}
}
return null;
}
示例15: enumeration
import org.jruby.RubyArray; //导入依赖的package包/类
/**
* FIXME: will enumerations all be of the simple (val1|val2|val3)
* type string?
*/
@JRubyMethod
public IRubyObject enumeration(ThreadContext context) {
RubyArray enumVals = RubyArray.newArray(context.getRuntime());
String atype = ((Element)node).getAttribute("atype");
if (atype != null && atype.length() != 0 && atype.charAt(0) == '(') {
// removed enclosing parens
String valueStr = atype.substring(1, atype.length() - 1);
String[] values = valueStr.split("\\|");
for (int i = 0; i < values.length; i++) {
enumVals.append(context.getRuntime().newString(values[i]));
}
}
return enumVals;
}