• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java JRubyMethod类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.jruby.anno.JRubyMethod的典型用法代码示例。如果您正苦于以下问题:Java JRubyMethod类的具体用法?Java JRubyMethod怎么用?Java JRubyMethod使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



JRubyMethod类属于org.jruby.anno包,在下文中一共展示了JRubyMethod类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: fuzz

import org.jruby.anno.JRubyMethod; //导入依赖的package包/类
@JRubyMethod(name = "fuzz", required = 1, module = true)
public static IRubyObject fuzz(IRubyObject self, IRubyObject length) {
    final Random rnd = new Random();
    final long llen = length.convertToInteger().getLongValue();
    final int len = (int) llen;
    final byte[] bytes = new byte[len];
    for (int i = 0; i < len; i++) {
        switch (rnd.nextInt(4)) {
            case 0:
                bytes[i] = '\'';
                break;
            case 1:
                bytes[i] = '\"';
                break;
            case 2:
                bytes[i] = '\\';
                break;
            case 3:
                bytes[i] = ' ';
                break;
        }
    }
    return RubyString.newString(self.getRuntime(), bytes);
}
 
开发者ID:airbnb,项目名称:collapstring,代码行数:25,代码来源:CollapstringService.java


示例2: set

import org.jruby.anno.JRubyMethod; //导入依赖的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();
}
 
开发者ID:Who828,项目名称:persistent_data_structures,代码行数:18,代码来源:PersistentVectorLibrary.java


示例3: add

import org.jruby.anno.JRubyMethod; //导入依赖的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);
}
 
开发者ID:Who828,项目名称:persistent_data_structures,代码行数:27,代码来源:PersistentVectorLibrary.java


示例4: eql

import org.jruby.anno.JRubyMethod; //导入依赖的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();
}
 
开发者ID:Who828,项目名称:persistent_data_structures,代码行数:18,代码来源:PersistentVectorLibrary.java


示例5: compare

import org.jruby.anno.JRubyMethod; //导入依赖的package包/类
/**
 * This calls to the static method compare of DataByteArray. Given two DataByteArrays, it will call it
 * on the underlying bytes.
 *
 * @param context the context the method is being executed in
 * @param self    an class which contains metadata on the calling class (required for static Ruby methods)
 * @param arg1    a RubyDataByteArray or byte array to compare
 * @param arg2    a RubyDataByteArray or byte array to compare
 * @return        the Fixnum result of comparing arg1 and arg2's bytes
 */
@JRubyMethod
public static RubyFixnum compare(ThreadContext context, IRubyObject self, IRubyObject arg1, IRubyObject arg2) {
    byte[] buf1, buf2;
    if (arg1 instanceof RubyDataByteArray) {
        buf1 = ((RubyDataByteArray)arg1).getDBA().get();
    } else {
        buf1 = (byte[])arg1.toJava(byte[].class);
    }
    if (arg2 instanceof RubyDataByteArray) {
        buf2 = ((RubyDataByteArray)arg2).getDBA().get();
    } else {
        buf2 = (byte[])arg2.toJava(byte[].class);
    }
    return RubyFixnum.newFixnum(context.getRuntime(), DataByteArray.compare(buf1, buf2));
}
 
开发者ID:sigmoidanalytics,项目名称:spork,代码行数:26,代码来源:RubyDataByteArray.java


示例6: setName

import org.jruby.anno.JRubyMethod; //导入依赖的package包/类
/**
 * This method allows the user to set the name of the alias of the FieldSchema of the encapsulated
 * Schema. This method only works if the Schema has one FieldSchema.
 *
 * @param arg a RubyString to set the name to
 * @return    the new name
 */
@JRubyMethod(name = "name=")
public RubyString setName(IRubyObject arg) {
    if (arg instanceof RubyString) {
         if (internalSchema.size() != 1)
             throw new RuntimeException("Can only set name if there is one schema present");
         try {
             internalSchema.getField(0).alias = arg.toString();
             return (RubyString)arg;
         } catch (FrontendException e) {
             throw new RuntimeException("Unable to get field from Schema", e);
         }
    } else {
         throw new RuntimeException("Improper argument passed to 'name=':" + arg);
    }
}
 
开发者ID:sigmoidanalytics,项目名称:spork-streaming,代码行数:23,代码来源:RubySchema.java


示例7: each

import org.jruby.anno.JRubyMethod; //导入依赖的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


示例8: flatten

import org.jruby.anno.JRubyMethod; //导入依赖的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


示例9: add

import org.jruby.anno.JRubyMethod; //导入依赖的package包/类
/**
 * A ruby method that adds two numbers. In practice we would do some more 
 * complex operation in java possibly using a library method, or a pure java
 * method of our own creation (possible private).
 * @param context ThreadContext
 * @param recv the receiver
 * @param args array of input arguments
 * @return The outcome of doing a plus b.
 */
@JRubyMethod(name = "add", module = true, rest = true)
public static IRubyObject add(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
    Ruby runtime = context.getRuntime();
    // Arity.checkArgumentCount(runtime, args, Arity.OPTIONAL.getValue(), 2);
    int a = (int) args[0].toJava(Integer.class);
    int b = (int) args[1].toJava(Integer.class);
    int result = a + b;
    return runtime.newFixnum(result);
}
 
开发者ID:jruby,项目名称:jruby-examples,代码行数:19,代码来源:RubyFoo.java


示例10: mult

import org.jruby.anno.JRubyMethod; //导入依赖的package包/类
/**
 * Multiplies two numbers (in practice you would implement some method in java, 
 * probably using an external library)
 * @param context ThreadContext
 * @param args the ruby way of coping with more than two arguments
 * @return result probably RubyFixnum
 */
@JRubyMethod(name = "multiply", rest = true)
public IRubyObject mult(ThreadContext context, IRubyObject[] args) {
    Ruby runtime = context.getRuntime();
    // Arity.checkArgumentCount(runtime, args, Arity.OPTIONAL.getValue(), 2);
    int a = (int) args[0].toJava(Integer.class);
    int b = (int) args[1].toJava(Integer.class);
    int result = a * b;
    return runtime.newFixnum(result);
}
 
开发者ID:jruby,项目名称:jruby-examples,代码行数:17,代码来源:RubyBar.java


示例11: initialize

import org.jruby.anno.JRubyMethod; //导入依赖的package包/类
@JRubyMethod(required = 1, optional = 2)
public IRubyObject initialize(ThreadContext context, IRubyObject[] args) {
    Ruby runtime = context.runtime;
    this.storage = runtime.newArray();
    IRubyObject ary = null;
    if (!(args[0] instanceof RubySymbol)) {
        throw runtime.newArgumentError("Expected Symbol for type name");
    }
    this.fieldType = Utils.rubyToFieldType(args[0]);
    if (fieldType == Descriptors.FieldDescriptor.Type.MESSAGE
            || fieldType == Descriptors.FieldDescriptor.Type.ENUM) {
        if (args.length < 2)
            throw runtime.newArgumentError("Expected at least 2 arguments for message/enum");
        typeClass = args[1];
        if (args.length > 2)
            ary = args[2];
        Utils.validateTypeClass(context, fieldType, typeClass);
    } else {
        if (args.length > 2)
            throw runtime.newArgumentError("Too many arguments: expected 1 or 2");
        if (args.length > 1)
            ary = args[1];
    }
    if (ary != null) {
        RubyArray arr = ary.convertToArray();
        for (int i = 0; i < arr.size(); i++) {
            this.storage.add(arr.eltInternal(i));
        }
    }
    return this;
}
 
开发者ID:bazelbuild,项目名称:bazel,代码行数:32,代码来源:RubyRepeatedField.java


示例12: set

import org.jruby.anno.JRubyMethod; //导入依赖的package包/类
/**
 * This method calls the set method of the underlying DataByteArray with one exception:
 * if given a RubyDataByteArray, it will set the encapsulated DataByteArray to be equal.
 *
 * @param arg an object to set the encapsulated DataByteArray's bits to. In the case of
 *            a RubyString or byte array, the underlying bytes will be sit directly. In
 *            the case of a RubyDataByteArray, the encapsulated DataByteArray will be set
 *            equal to arg.
 */
@JRubyMethod
public void set(IRubyObject arg) {
    if (arg instanceof RubyDataByteArray) {
        internalDBA = ((RubyDataByteArray)arg).getDBA();
    } else if (arg instanceof RubyString) {
        internalDBA.set(arg.toString());
    } else {
        internalDBA.set((byte[])arg.toJava(byte[].class));
    }
}
 
开发者ID:sigmoidanalytics,项目名称:spork,代码行数:20,代码来源:RubyDataByteArray.java


示例13: oneof

import org.jruby.anno.JRubyMethod; //导入依赖的package包/类
@JRubyMethod
public IRubyObject oneof(ThreadContext context, IRubyObject name, Block block) {
    RubyOneofDescriptor oneofdef = (RubyOneofDescriptor)
            cOneofDescriptor.newInstance(context, Block.NULL_BLOCK);
    RubyOneofBuilderContext ctx = (RubyOneofBuilderContext)
            cOneofBuilderContext.newInstance(context, oneofdef, Block.NULL_BLOCK);
    oneofdef.setName(context, name);
    Binding binding = block.getBinding();
    binding.setSelf(ctx);
    block.yieldSpecific(context);
    descriptor.addOneof(context, oneofdef);
    return context.runtime.getNil();
}
 
开发者ID:bazelbuild,项目名称:bazel,代码行数:14,代码来源:RubyMessageBuilderContext.java


示例14: finalizeToPool

import org.jruby.anno.JRubyMethod; //导入依赖的package包/类
@JRubyMethod(name = "finalize_to_pool")
public IRubyObject finalizeToPool(ThreadContext context, IRubyObject rbPool) {
    RubyDescriptorPool pool = (RubyDescriptorPool) rbPool;
    for (int i = 0; i < this.pendingList.size(); i++) {
        IRubyObject defRb = this.pendingList.entry(i);
        if (defRb instanceof RubyDescriptor) {
            pool.addToSymtab(context, (RubyDescriptor) defRb);
        } else {
            pool.addToSymtab(context, (RubyEnumDescriptor) defRb);
        }
    }
    this.pendingList = context.runtime.newArray();
    return context.runtime.getNil();
}
 
开发者ID:bazelbuild,项目名称:bazel,代码行数:15,代码来源:RubyBuilder.java


示例15: each

import org.jruby.anno.JRubyMethod; //导入依赖的package包/类
@JRubyMethod
public IRubyObject each(ThreadContext context, Block block) {
    Ruby runtime = context.runtime;
    for (Descriptors.EnumValueDescriptor enumValueDescriptor : descriptor.getValues()) {
        block.yield(context, runtime.newArray(runtime.newSymbol(enumValueDescriptor.getName()),
                runtime.newFixnum(enumValueDescriptor.getNumber())));
    }
    return runtime.getNil();
}
 
开发者ID:bazelbuild,项目名称:bazel,代码行数:10,代码来源:RubyEnumDescriptor.java


示例16: each

import org.jruby.anno.JRubyMethod; //导入依赖的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


示例17: collect

import org.jruby.anno.JRubyMethod; //导入依赖的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


示例18: optional

import org.jruby.anno.JRubyMethod; //导入依赖的package包/类
@JRubyMethod(required = 3, optional = 1)
public IRubyObject optional(ThreadContext context, IRubyObject[] args) {
    IRubyObject name = args[0];
    IRubyObject type = args[1];
    IRubyObject number = args[2];
    IRubyObject typeClass = args.length > 3 ? args[3] : context.runtime.getNil();
    RubyFieldDescriptor fieldDescriptor = Utils.msgdefCreateField(context, "optional",
            name, type, number, typeClass, cFieldDescriptor);
    descriptor.addField(context, fieldDescriptor);
    return this;
}
 
开发者ID:bazelbuild,项目名称:bazel,代码行数:12,代码来源:RubyOneofBuilderContext.java


示例19: initialize

import org.jruby.anno.JRubyMethod; //导入依赖的package包/类
/**
 * The ruby initializer accepts any number of arguments. With no arguments,
 * it will return an empty Schema object. It can accept any number of arguments.
 * To understand the valid arguments, see the documentation for {@link #rubyArgToSchema}.
 *
 * @param args a varargs which can take any number of valid arguments to
 *             {@link #rubyArgToSchema}
 * @return     the initialized RubySchema
 */
@JRubyMethod(rest = true)
public RubySchema initialize(IRubyObject[] args) {
    internalSchema = new Schema();
    for (IRubyObject arg : args) {
        Schema rs = rubyArgToSchema(arg);
        for (Schema.FieldSchema i : rs.getFields())
            internalSchema.add(i);
    }
    RubySchema.fixSchemaNames(internalSchema);
    return this;
}
 
开发者ID:sigmoidanalytics,项目名称:spork-streaming,代码行数:21,代码来源:RubySchema.java


示例20: lookup

import org.jruby.anno.JRubyMethod; //导入依赖的package包/类
@JRubyMethod(meta = true)
public static IRubyObject lookup(ThreadContext context, IRubyObject recv, IRubyObject number) {
    RubyEnumDescriptor rubyEnumDescriptorescriptor = (RubyEnumDescriptor) getDescriptor(context, recv);
    Descriptors.EnumDescriptor descriptor = rubyEnumDescriptorescriptor.getDescriptor();
    Descriptors.EnumValueDescriptor value = descriptor.findValueByNumber(RubyNumeric.num2int(number));
    if (value == null) return context.runtime.getNil();
    return context.runtime.newSymbol(value.getName());
}
 
开发者ID:bazelbuild,项目名称:bazel,代码行数:9,代码来源:RubyEnum.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java FsDatasetSpi类代码示例发布时间:2022-05-22
下一篇:
Java Row类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap