Пример #1
0
  @Override
  public Object compute(Object[] args, ExecutionContext ec) {
    if (ExecUtils.isNull(args[0])) {
      return null;
    }

    Integer index = DataType.IntegerType.convertFrom(args[0]);

    if (index < 1 || index > args.length - 1) {
      return null;
    }

    Object resEle = args[index];

    if (ExecUtils.isNull(resEle)) {
      return null;
    }

    return DataType.StringType.convertFrom(resEle);
  }
Пример #2
0
  @Override
  public Object compute(Object[] args, ExecutionContext ec) {
    for (Object arg : args) {
      if (ExecUtils.isNull(arg)) {
        return null;
      }
    }
    String str = DataType.StringType.convertFrom(args[0]);
    Integer len = DataType.IntegerType.convertFrom(args[1]);
    if (len < 0) {
      return "";
    }

    return str.substring(0, len);
  }
Пример #3
0
  @Override
  public Object compute(Object[] args, ExecutionContext ec) {
    for (Object arg : args) {
      if (ExecUtils.isNull(arg)) {
        return null;
      }
    }
    BigInteger bitsValue = DataType.BigIntegerType.convertFrom(args[0]);
    String bitsStringReverse = TStringUtil.reverse(bitsValue.toString(2));

    String on = DataType.StringType.convertFrom(args[1]);
    String off = DataType.StringType.convertFrom(args[2]);
    String sep = ",";
    if (args.length >= 4) {
      sep = DataType.StringType.convertFrom(args[3]);
    }

    Integer number_of_bits = 64;

    if (args.length >= 5) {
      number_of_bits = DataType.IntegerType.convertFrom(args[4]);
    }

    StringBuilder sb = new StringBuilder();

    for (int i = 0; i < number_of_bits; i++) {
      if (i != 0) {
        sb.append(sep);
      }

      if (i < bitsStringReverse.length()) {
        if (bitsStringReverse.charAt(i) == '0') {
          sb.append(off);
        } else {
          sb.append(on);
        }
      } else {
        sb.append(off);
      }
    }

    return sb.toString();
  }
Пример #4
0
  @Override
  public Object compute(Object[] args, ExecutionContext ec) {
    for (Object arg : args) {
      if (ExecUtils.isNull(arg)) {
        return null;
      }
    }
    String str = DataType.StringType.convertFrom(args[0]);
    Integer len = DataType.IntegerType.convertFrom(args[1]);
    String padStr = DataType.StringType.convertFrom(args[2]);

    if (len == str.length()) {
      return str;
    }

    if (len < 0) {
      return null;
    }
    if (len < str.length()) {
      return str.substring(0, len);
    }

    return TStringUtil.rightPad(str, len, padStr);
  }