当前位置: 首页>>代码示例>>Java>>正文


Java RubyArray.add方法代码示例

本文整理汇总了Java中org.jruby.RubyArray.add方法的典型用法代码示例。如果您正苦于以下问题:Java RubyArray.add方法的具体用法?Java RubyArray.add怎么用?Java RubyArray.add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.jruby.RubyArray的用法示例。


在下文中一共展示了RubyArray.add方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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
}
 
开发者ID:lucidworks,项目名称:hadoop-solr,代码行数:31,代码来源:GrokIngestMapperTest.java

示例2: pigToRuby

import org.jruby.RubyArray; //导入方法依赖的package包/类
/**
 * A type specific conversion routine.
 *
 * @param  ruby          the Ruby runtime to create objects in
 * @param  object        object to convert
 * @return               analogous Ruby type
 * @throws ExecException object contained an object that could not convert
 */
public static RubyArray pigToRuby(Ruby ruby, Tuple object) throws ExecException{
    RubyArray rubyArray = ruby.newArray();

    for (Object o : object.getAll())
        rubyArray.add(pigToRuby(ruby, o));

    return rubyArray;
}
 
开发者ID:sigmoidanalytics,项目名称:spork-streaming,代码行数:17,代码来源:PigJrubyLibrary.java

示例3: libsToShip

import org.jruby.RubyArray; //导入方法依赖的package包/类
/**
 * Consults the scripting container, after the script has been evaluated, to
 * determine what dependencies to ship.
 * <p>
 * FIXME: Corner cases like the following: "def foobar; require 'json'; end"
 * are NOT dealt with using this method
 */
private HashSet<String> libsToShip() {
    RubyArray loadedLibs = (RubyArray)rubyEngine.get("$\"");
    RubyArray loadPaths = (RubyArray)rubyEngine.get("$LOAD_PATH");
    // Current directory first
    loadPaths.add(0, "");

    HashSet<String> toShip = new HashSet<String>();
    HashSet<Object> shippedLib = new HashSet<Object>();

    for (Object loadPath : loadPaths) {
        for (Object lib : loadedLibs) {
            if (lib.toString().equals("pigudf.rb"))
                continue;
            if (shippedLib.contains(lib))
                continue;
            String possiblePath = (loadPath.toString().isEmpty()?"":loadPath.toString() +
                    File.separator) + lib.toString();
            if ((new File(possiblePath)).exists()) {
                // remove prefix ./
                toShip.add(possiblePath.startsWith("./")?possiblePath.substring(2):
                    possiblePath);
                shippedLib.add(lib);
            }
        }
    }
    return toShip;
}
 
开发者ID:sigmoidanalytics,项目名称:spork-streaming,代码行数:35,代码来源:JrubyScriptEngine.java

示例4: 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
}
 
开发者ID:lucidworks,项目名称:hadoop-solr,代码行数:48,代码来源:GrokIngestMapperTest.java

示例5: 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);
}
 
开发者ID:gocd,项目名称:gocd,代码行数:61,代码来源:NokogiriHandler.java

示例6: toRubyArray

import org.jruby.RubyArray; //导入方法依赖的package包/类
private static IRubyObject toRubyArray(Ruby rubyRuntime, List<Object> values) {

        RubyArray rubyArray = RubyArray.newArray(rubyRuntime, values.size());

        for (Object value : values) {
            rubyArray.add(toRubyObject(rubyRuntime, value));
        }

        return rubyArray;
    }
 
开发者ID:asciidoctor,项目名称:asciidoctorj,代码行数:11,代码来源:RubyHashUtil.java


注:本文中的org.jruby.RubyArray.add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。