本文整理汇总了Java中org.jruby.RubyArray.newArray方法的典型用法代码示例。如果您正苦于以下问题:Java RubyArray.newArray方法的具体用法?Java RubyArray.newArray怎么用?Java RubyArray.newArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jruby.RubyArray
的用法示例。
在下文中一共展示了RubyArray.newArray方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
示例2: 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;
}
示例3: 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;
}
示例4: testCISCOPattern
import org.jruby.RubyArray; //导入方法依赖的package包/类
@Test
public void testCISCOPattern() throws Exception {
// Adding configuration file
Path path = new Path(GrokIngestMapperTest.class.getClassLoader()
.getResource("grok" + File.separator + "CISCO.conf").getPath());
// Adding extra patterns file
Ruby runtime = Ruby.newInstance();
RubyArray rubyArray = RubyArray.newArray(runtime);
rubyArray.add(GrokIngestMapperTest.class.getClassLoader()
.getResource("grok" + File.separator + "extra_patterns.txt").getPath());
jobConf.set(GrokIngestMapper.GROK_URI, path.toString());
mapper.getFixture().init(jobConf);
mapDriver.withConfiguration(jobConf);
String splitFilePath = "/path/to/log";
mapDriver.setMapInputPath(new Path(splitFilePath));
LongWritable lineNumb = new LongWritable(10);
String message = "Mar 20 2014 20:10:45 key1=value1 key2=value2 key3=value3";
mapDriver.withInput(lineNumb, new Text(message));
List<Pair<Text, LWDocumentWritable>> run = mapDriver.run();
Assert.assertEquals(1, run.size());
Pair<Text, LWDocumentWritable> pair = run.get(0);
LWDocument doc = pair.getSecond().getLWDocument();
Assert.assertNotNull(doc);
// TODO: Check Fields
}
示例5: jruby
import org.jruby.RubyArray; //导入方法依赖的package包/类
@Benchmark
public Object jruby(JRubyState jRubyState, DataState dataState) {
if (jRubyState.array == null) {
IRubyObject[] objects = convertJavaArrayToRuby(jRubyState.context.container().getProvider().getRuntime(), dataState.data.toArray());
jRubyState.array = RubyArray.newArray(jRubyState.context.container().getProvider().getRuntime(), objects);
}
return jRubyState
.context
.container()
.callMethod(
jRubyState.context.receiver(),
"run",
jRubyState.array,
Object.class);
}
示例6: collectCurrent
import org.jruby.RubyArray; //导入方法依赖的package包/类
private RubyArray collectCurrent() {
RubyArray bindings = RubyArray.newArray(runtime);
while (iterator.hasNext()) {
bindings.append(((IRubyObject) RubyBinding.newBinding(runtime, iterator.next())));
}
return bindings;
}
示例7: conj
import org.jruby.RubyArray; //导入方法依赖的package包/类
public IRubyObject conj(ThreadContext context, IRubyObject val) {
ensureEditable();
int i = cnt;
if (i - tailoff() < 32) {
tail.store(i & 0x01f, val);
++cnt;
return this;
}
Node newroot;
Node tailnode = new Node(context.runtime, Node).initialize_params_arry(context, root.edit, tail);
tail = RubyArray.newArray(context.runtime, 32);
tail.store(0, val);
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);
root = newroot;
shift = newshift;
++cnt;
return this;
}
示例8: nodeArrayToRubyArray
import org.jruby.RubyArray; //导入方法依赖的package包/类
public static RubyArray nodeArrayToRubyArray(Ruby ruby, Node[] nodes) {
RubyArray n = RubyArray.newArray(ruby, nodes.length);
for(int i = 0; i < nodes.length; i++) {
n.append(NokogiriHelpers.getCachedNodeOrCreate(ruby, nodes[i]));
}
return n;
}
示例9: namedNodeMapToRubyArray
import org.jruby.RubyArray; //导入方法依赖的package包/类
public static RubyArray namedNodeMapToRubyArray(Ruby ruby, NamedNodeMap map) {
RubyArray n = RubyArray.newArray(ruby, map.getLength());
for(int i = 0; i < map.getLength(); i++) {
n.append(NokogiriHelpers.getCachedNodeOrCreate(ruby, map.item(i)));
}
return n;
}
示例10: getErrorArray
import org.jruby.RubyArray; //导入方法依赖的package包/类
private RubyArray getErrorArray(XmlDocument document) {
IRubyObject obj = document.getInstanceVariable("@errors");
if (obj != null && obj instanceof RubyArray) {
return (RubyArray)obj;
}
return RubyArray.newArray(document.getRuntime());
}
示例11: testAdditionalPattern
import org.jruby.RubyArray; //导入方法依赖的package包/类
@Ignore
@Test
public void testAdditionalPattern() throws Exception {
// Generate the HDFS hierarchy
FileSystem fs = FileSystem.getLocal(jobConf);
Path dir = new Path(fs.getWorkingDirectory(), "build");
Path sub = new Path(dir, "GHT");
Path tempDir = new Path(sub, "tmp-dir");
Path base = new Path(sub, "tmp-dir-2");
fs.mkdirs(tempDir);
// Copy extra patterns file to HDFS
Path dst = new Path(base, "extra_patterns.txt");
Path src = new Path(GrokIngestMapperTest.class.getClassLoader()
.getResource("grok" + File.separator + "extra_patterns.txt").getPath());
fs.copyFromLocalFile(src, dst);
// Adding configuration file
Path confPath = new Path(GrokIngestMapperTest.class.getClassLoader()
.getResource("grok" + File.separator + "customPattern.conf").toURI().getPath());
// Adding extra patterns file
Ruby runtime = Ruby.newInstance();
RubyArray rubyArray = RubyArray.newArray(runtime);
rubyArray.add(
base.toUri().getPath() + File.separator + "extra_patterns.txt");
GrokHelper.addPatternDirToDC(rubyArray, jobConf);
jobConf.set(GrokIngestMapper.GROK_URI, confPath.toString());
mapper.getFixture().init(jobConf);
mapDriver.withConfiguration(jobConf);
String splitFilePath = "/path/to/log";
mapDriver.setMapInputPath(new Path(splitFilePath));
LongWritable lineNumb = new LongWritable(10);
String message = "192.168.1.1 123456 rest of the message";
mapDriver.withInput(lineNumb, new Text(message));
List<Pair<Text, LWDocumentWritable>> run = mapDriver.run();
Assert.assertEquals(1, run.size());
Pair<Text, LWDocumentWritable> pair = run.get(0);
LWDocument doc = pair.getSecond().getLWDocument();
Assert.assertNotNull(doc);
// TODO: Check Fields
}
示例12: initialize_params
import org.jruby.RubyArray; //导入方法依赖的package包/类
public Node initialize_params(ThreadContext context, AtomicReference<Thread> edit) {
this.edit = edit;
this.array = RubyArray.newArray(context.runtime, 32);
return this;
}
示例13: init
import org.jruby.RubyArray; //导入方法依赖的package包/类
/**
* Called to initialize the load path with a set of optional prepended
* directories and then the standard set of dirs.
*
* This should only be called once, at load time, since it wipes out loaded
* features.
*
* @param prependDirectories
*/
public void init(List prependDirectories) {
loadPath = RubyArray.newArray(runtime);
String jrubyHome = runtime.getJRubyHome();
loadedFeatures = new StringArraySet(runtime);
// add all startup load paths to the list first
addPaths(prependDirectories);
// add $RUBYLIB paths
RubyHash env = (RubyHash) runtime.getObject().getConstant("ENV");
RubyString env_rubylib = runtime.newString("RUBYLIB");
if (env.has_key_p(env_rubylib).isTrue()) {
String rubylib = env.op_aref(runtime.getCurrentContext(), env_rubylib).toString();
String[] paths = rubylib.split(File.pathSeparator);
addPaths(paths);
}
// wrap in try/catch for security exceptions in an applet
try {
if (jrubyHome != null) {
// siteDir has to come first, because rubygems insert paths after it
// and we must to prefer Gems to rubyLibDir/rubySharedLibDir (same as MRI)
addPath(RbConfigLibrary.getSiteDir(runtime));
// if vendorDirGeneral is different than siteDirGeneral,
// add vendorDir, too
// adding {vendor,site}{Lib,Arch}Dir dirs is not necessary,
// since they should be the same as {vendor,site}Dir
if (!RbConfigLibrary.isSiteVendorSame(runtime)) {
addPath(RbConfigLibrary.getVendorDir(runtime));
}
String rubygemsDir = RbConfigLibrary.getRubygemsDir(runtime);
if (rubygemsDir != null) {
addPath(rubygemsDir);
}
addPath(RbConfigLibrary.getRubySharedLibDir(runtime));
// if 2.0, we append 1.9 libs; our copy of 2.0 only has diffs right now
if (runtime.is2_0()) {
addPath(RbConfigLibrary.getRubyLibDirFor(runtime, "2.0"));
}
addPath(RbConfigLibrary.getRubyLibDir(runtime));
}
} catch(SecurityException ignore) {}
// "." dir is used for relative path loads from a given file, as in require '../foo/bar'
if (!runtime.is1_9()) {
addPath(".");
}
}
示例14: startElement
import org.jruby.RubyArray; //导入方法依赖的package包/类
@Override
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
// for attributes other than namespace attrs
RubyArray rubyAttr = RubyArray.newArray(ruby);
// for namespace defining attributes
RubyArray rubyNSAttr = RubyArray.newArray(ruby);
ThreadContext context = ruby.getCurrentContext();
boolean fromFragmentHandler = false; // isFromFragmentHandler();
for (int i = 0; i < attrs.getLength(); i++) {
String u = attrs.getURI(i);
String qn = attrs.getQName(i);
String ln = attrs.getLocalName(i);
String val = attrs.getValue(i);
String pre;
pre = getPrefix(qn);
if (ln == null || ln.equals("")) ln = getLocalPart(qn);
if (isNamespace(qn) && !fromFragmentHandler) {
// I haven't figured the reason out yet, but, in somewhere,
// namespace is converted to array in array in array and cause
// TypeError at line 45 in fragment_handler.rb
RubyArray ns = RubyArray.newArray(ruby, 2);
if (ln.equals("xmlns")) ln = null;
ns.add(stringOrNil(ruby, ln));
ns.add(ruby.newString(val));
rubyNSAttr.add(ns);
} else {
IRubyObject[] args = null;
if (needEmptyAttrCheck) {
if (isEmptyAttr(ln)) {
args = new IRubyObject[3];
args[0] = stringOrNil(ruby, ln);
args[1] = stringOrNil(ruby, pre);
args[2] = stringOrNil(ruby, u);
}
}
if (args == null) {
args = new IRubyObject[4];
args[0] = stringOrNil(ruby, ln);
args[1] = stringOrNil(ruby, pre);
args[2] = stringOrNil(ruby, u);
args[3] = stringOrNil(ruby, val);
}
IRubyObject attr = RuntimeHelpers.invoke(context, attrClass, "new", args);
rubyAttr.add(attr);
}
}
if (localName == null || localName.equals("")) localName = getLocalPart(qName);
call("start_element_namespace",
stringOrNil(ruby, localName),
rubyAttr,
stringOrNil(ruby, getPrefix(qName)),
stringOrNil(ruby, uri),
rubyNSAttr);
}
示例15: nodeListToRubyArray
import org.jruby.RubyArray; //导入方法依赖的package包/类
public static RubyArray nodeListToRubyArray(Ruby ruby, NodeList nodes) {
RubyArray array = RubyArray.newArray(ruby, nodes.getLength());
return nodeListToRubyArray(ruby, nodes, array);
}