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


Java IRubyObject.toString方法代码示例

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


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

示例1: setName

import org.jruby.runtime.builtin.IRubyObject; //导入方法依赖的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

示例2: get

import org.jruby.runtime.builtin.IRubyObject; //导入方法依赖的package包/类
/**
 * This is a version of [] which allows the range to be specified as such: [1,2].
 *
 * @param context the context the method is being executed in
 * @param arg1    a Fixnum start index
 * @param arg2    a Fixnum end index
 * @return        the RubySchema object encapsulated the found Schema
 */
@JRubyMethod(name = {"[]", "slice"})
public RubySchema get(ThreadContext context, IRubyObject arg1, IRubyObject arg2) {
    if (arg1 instanceof RubyFixnum && arg2 instanceof RubyFixnum) {
        Ruby runtime = context.getRuntime();
        int min = (int)((RubyFixnum)arg1).getLongValue();
        int max = (int)((RubyFixnum)arg2).getLongValue() - 1;
        return new RubySchema(runtime, runtime.getClass("Schema"), new Schema(internalSchema.getFields().subList(min, max + 1)), false);
    } else {
        throw new RuntimeException("Bad arguments given to get function: ( " + arg1.toString() + " , " + arg2.toString()+ " )");
    }
}
 
开发者ID:sigmoidanalytics,项目名称:spork-streaming,代码行数:20,代码来源:RubySchema.java

示例3: set

import org.jruby.runtime.builtin.IRubyObject; //导入方法依赖的package包/类
/**
 * This allows the users to set an index or a range of values to
 * a specified RubySchema. The first argument must be a Fixnum or Range,
 * and the second argument may optionally be a Fixnum. The given index
 * (or range of indices) will be replaced by a RubySchema instantiated
 * based on the remaining arguments.
 *
 * @param context the contextthe method is being executed in
 * @param args    a varargs which has to be at least length two.
 * @return        the RubySchema that was added
 */
@JRubyMethod(name = {"[]=", "set"}, required = 2, rest = true)
public RubySchema set(ThreadContext context, IRubyObject[] args) {
    IRubyObject arg1 = args[0];
    IRubyObject arg2 = args[1];
    IRubyObject[] arg3 = Arrays.copyOfRange(args, 1, args.length);
    Schema s = internalSchema;
    Ruby runtime = context.getRuntime();
    List<Schema.FieldSchema> lfs = s.getFields();
    int min, max;
    if (arg1 instanceof RubyFixnum && arg2 instanceof RubyFixnum) {
        min = (int)((RubyFixnum)arg1).getLongValue();
        max = (int)((RubyFixnum)arg2).getLongValue();
        arg3 = Arrays.copyOfRange(args, 2, args.length);
    } else if (arg1 instanceof RubyFixnum) {
        min = (int)((RubyFixnum)arg1).getLongValue();
        max = min + 1;
    } else if (arg1 instanceof RubyRange) {
        min = (int)((RubyFixnum)((RubyRange)arg1).min(context, Block.NULL_BLOCK)).getLongValue();
        max = (int)((RubyFixnum)((RubyRange)arg1).max(context, Block.NULL_BLOCK)).getLongValue() + 1;
    } else {
        throw new RuntimeException("Bad arguments given to get function: ( " + arg1.toString() + " , " + arg2.toString()+ " )");
    }
    for (int i = min; i < max; i++)
        lfs.remove(min);
    if (arg3 == null || arg3.length == 0)
        throw new RuntimeException("Must have schema argument for []=");
    RubySchema rs = new RubySchema(runtime, runtime.getClass("Schema")).initialize(arg3);
    for (Schema.FieldSchema fs : rs.getInternalSchema().getFields())
        lfs.add(min++, fs);
    RubySchema.fixSchemaNames(internalSchema);
    return rs;
}
 
开发者ID:sigmoidanalytics,项目名称:spork-streaming,代码行数:44,代码来源:RubySchema.java


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