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


Java Block.isGiven方法代码示例

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


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

示例1: each

import org.jruby.runtime.Block; //导入方法依赖的package包/类
/**
 * This is an implementation of the each method which opens up the Enumerable interface,
 * and makes it very convenient to iterate over the elements of a DataBag. Note that currently,
 * due to a deficiency in JRuby, it is not possible to call each without a block given.
 *
 * @param context the context the method is being executed in
 * @param block   a block to call on the elements of the bag
 * @return        enumerator object if null block given, nil otherwise
 */
@JRubyMethod
public IRubyObject each(ThreadContext context, Block block) throws ExecException{
    Ruby runtime = context.getRuntime();

    if (!block.isGiven())
        return PigJrubyLibrary.enumeratorize(runtime, this, "each");
    /*  In a future release of JRuby when enumeratorize is made public (which is planned), should replace the above with the below
    if (!block.isGiven())
        return RubyEnumerator.enumeratorize(context.getRuntime(), this, "each");
    */

    for (Tuple t : this)
        block.yield(context, PigJrubyLibrary.pigToRuby(runtime, t));

    return context.nil;
}
 
开发者ID:sigmoidanalytics,项目名称:spork-streaming,代码行数:26,代码来源:RubyDataBag.java

示例2: flatten

import org.jruby.runtime.Block; //导入方法依赖的package包/类
/**
 * This is a convenience method which will run the given block on the first element
 * of each tuple contained.
 *
 * @param context the context the method is being executed in
 * @param block   a block to call on the elements of the bag
 * @return        enumerator object if null block given, nil otherwise
 */
@JRubyMethod(name = {"flat_each", "flatten"})
public IRubyObject flatten(ThreadContext context, Block block) throws ExecException {
    Ruby runtime = context.getRuntime();

    if (!block.isGiven())
        return PigJrubyLibrary.enumeratorize(runtime, this, "flatten");
    /*  In a future release of JRuby when enumeratorize is made public (which is planned), should replace the above with the below
    if (!block.isGiven())
        return RubyEnumerator.enumeratorize(context.getRuntime(), this, "flatten");
    */

    for (Tuple t : this)
        block.yield(context, PigJrubyLibrary.pigToRuby(runtime, t.get(0)));

    return context.nil;
}
 
开发者ID:sigmoidanalytics,项目名称:spork-streaming,代码行数:25,代码来源:RubyDataBag.java

示例3: each

import org.jruby.runtime.Block; //导入方法依赖的package包/类
@JRubyMethod
public IRubyObject each(ThreadContext context, Block block) {
    if (!block.isGiven()) return enumeratorize(context.runtime, this, "each");

    for(int i=0; i < cnt; i++) {
        block.yield(context, nth(context, RubyFixnum.newFixnum(context.runtime, i)));
    }
    return this;
}
 
开发者ID:Who828,项目名称:persistent_data_structures,代码行数:10,代码来源:PersistentVectorLibrary.java

示例4: collect

import org.jruby.runtime.Block; //导入方法依赖的package包/类
@JRubyMethod(name = {"collect", "map"})
public IRubyObject collect(ThreadContext context, Block block) {
    Ruby runtime = context.runtime;
    if (!block.isGiven()) return emptyVector(context, getMetaClass());

    TransientVector ret = emptyVector(context, getMetaClass()).asTransient(context);

    for (int i = 0; i < cnt; i++) {
       ret = (TransientVector) ret.conj(context, block.yield(context, get(context, i)));
    }

    return ret.persistent(context, getMetaClass());
}
 
开发者ID:Who828,项目名称:persistent_data_structures,代码行数:14,代码来源:PersistentVectorLibrary.java

示例5: getStartingNode

import org.jruby.runtime.Block; //导入方法依赖的package包/类
private XmlNode getStartingNode(Block block) {
    if (block.isGiven()) {
        if (block.getBinding().getSelf() instanceof XmlNode) {
            return (XmlNode)block.getBinding().getSelf();
        }
    }
    return this;
}
 
开发者ID:gocd,项目名称:gocd,代码行数:9,代码来源:XmlDocument.java

示例6: select

import org.jruby.runtime.Block; //导入方法依赖的package包/类
@JRubyMethod
public IRubyObject select(ThreadContext context, Block block) {
    return block.isGiven() ? selectCommon(context, block) : enumeratorize(context.runtime, this, "select");
}
 
开发者ID:Who828,项目名称:persistent_data_structures,代码行数:5,代码来源:PersistentVectorLibrary.java

示例7: reject

import org.jruby.runtime.Block; //导入方法依赖的package包/类
@JRubyMethod
public IRubyObject reject(ThreadContext context, Block block) {
    return block.isGiven() ? rejectCommon(context, block) : enumeratorize(context.runtime, this, "reject");
}
 
开发者ID:Who828,项目名称:persistent_data_structures,代码行数:5,代码来源:PersistentVectorLibrary.java

示例8: rbNew

import org.jruby.runtime.Block; //导入方法依赖的package包/类
/**
 * Allocate a new object, perform initialization, call that
 * object's initialize method, and call any block passing the
 * object as the only argument.  If <code>cls</code> is
 * Nokogiri::XML::Node, creates a new Nokogiri::XML::Element
 * instead.
 *
 * This static method seems to be inherited, strangely enough.
 * E.g. creating a new XmlAttr from Ruby code calls this method if
 * XmlAttr does not define its own 'new' method.
 *
 * Since there is some Java bookkeeping that always needs to
 * happen, we don't define the 'initialize' method in Java because
 * we'd have to count on subclasses calling 'super'.
 *
 * The main consequence of this is that every subclass needs to
 * define its own 'new' method.
 *
 * As a convenience, this method does the following:
 *
 * <ul>
 *
 * <li>allocates a new object using the allocator assigned to
 * <code>cls</code></li>
 *
 * <li>calls the Java method init(); subclasses can override this,
 * otherwise they should implement a specific 'new' method</li>
 *
 * <li>invokes the Ruby initializer</li>
 *
 * <li>if a block is given, calls the block with the new node as
 * the argument</li>
 *
 * </ul>
 *
 * -pmahoney
 */
@JRubyMethod(name = "new", meta = true, rest = true)
public static IRubyObject rbNew(ThreadContext context, IRubyObject cls,
                                IRubyObject[] args, Block block) {
    Ruby ruby = context.getRuntime();
    RubyClass klazz = (RubyClass) cls;

    if (cls.equals(getNokogiriClass(ruby, "Nokogiri::XML::Node"))) {
        klazz = getNokogiriClass(ruby, "Nokogiri::XML::Element");
    }

    XmlNode xmlNode = (XmlNode) klazz.allocate();
    xmlNode.init(context, args);
    xmlNode.callInit(args, block);
    if (xmlNode.node == null) context.getRuntime().newRuntimeError("NODE IS NULL");
    if (block.isGiven()) block.call(context, xmlNode);
    return xmlNode;
}
 
开发者ID:gocd,项目名称:gocd,代码行数:55,代码来源:XmlNode.java


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