Example #1
0
 @Override
 protected <U extends IValue> Result<U> compareTuple(TupleResult that) {
   // Note reversed args
   ITuple left = that.getValue();
   ITuple right = this.getValue();
   int compare = Integer.valueOf(left.arity()).compareTo(Integer.valueOf(right.arity()));
   if (compare != 0) {
     return makeIntegerResult(compare);
   }
   for (int i = 0; i < left.arity(); i++) {
     compare = compareIValues(left.get(i), right.get(i), ctx);
     if (compare != 0) {
       return makeIntegerResult(compare);
     }
   }
   return makeIntegerResult(0);
 }
Example #2
0
  @Override
  protected <U extends IValue> Result<U> addTuple(TupleResult that) {
    // Note reversed args
    TupleResult left = that;
    TupleResult right = this;
    Type leftType = left.getType();
    Type rightType = right.getType();

    int leftArity = leftType.getArity();
    int rightArity = rightType.getArity();
    int newArity = leftArity + rightArity;

    Type fieldTypes[] = new Type[newArity];
    String fieldNames[] = new String[newArity];
    IValue fieldValues[] = new IValue[newArity];

    boolean consistentLabels = true;
    for (int i = 0; i < leftArity; i++) {
      fieldTypes[i] = leftType.getFieldType(i);
      fieldNames[i] = leftType.getFieldName(i);
      fieldValues[i] = left.getValue().get(i);
      consistentLabels = fieldNames[i] != null;
    }

    for (int i = 0; i < rightArity; i++) {
      fieldTypes[leftArity + i] = rightType.getFieldType(i);
      fieldNames[leftArity + i] = rightType.getFieldName(i);
      fieldValues[leftArity + i] = right.getValue().get(i);
      consistentLabels = fieldNames[i] != null;
      if (consistentLabels) {
        for (int j = 0; j < leftArity; j++) {
          if (fieldNames[j].equals(fieldNames[i])) {
            // duplicate field name, so degenerate to unlabeled tuple
            consistentLabels = false;
          }
        }
      }
    }

    Type newTupleType;
    if (consistentLabels) {
      newTupleType = getTypeFactory().tupleType(fieldTypes, fieldNames);
    } else {
      newTupleType = getTypeFactory().tupleType(fieldTypes);
    }
    return makeResult(newTupleType, getValueFactory().tuple(fieldValues), ctx);
  }
Example #3
0
 @Override
 protected <U extends IValue> Result<U> greaterThanOrEqualTuple(TupleResult that) {
   // note reversed args: we need that >= this
   return bool((that.comparisonInts(this) >= 0), ctx);
 }
Example #4
0
 @Override
 protected <U extends IValue> Result<U> lessThanTuple(TupleResult that) {
   // note reversed args: we need that < this
   return bool((that.comparisonInts(this) < 0), ctx);
 }
Example #5
0
 @Override
 protected <U extends IValue> Result<U> nonEqualToTuple(TupleResult that) {
   return that.nonEqualityBoolean(this);
 }