protected CommandEvaluator<Criterion, Object> compileIdentifierToValueCMP(
     IdentifierToValueCMP node) {
   Identifier id = node.getIdentifier();
   if (id instanceof Field) {
     String name = id.getName();
     Value value = node.getValue();
     if (INSTANCE_ID_FIELD.equals(name)) {
       value.setValue(Long.valueOf((String) value.getValue()));
     } else if (INSTANCE_STARTED_FIELD.equals(name) || INSTANCE_LAST_ACTIVE_FIELD.equals(name)) {
       try {
         value.setValue(ISO8601DateParser.parse((String) value.getValue()));
       } catch (ParseException ex) {
         throw new RuntimeException(ex);
       }
     }
   }
   if (node instanceof Equality) {
     return compileEqual((Equality) node);
   } else if (node instanceof Less) {
     return compileLess((Less) node);
   } else if (node instanceof Greater) {
     return compileGreater((Greater) node);
   } else if (node instanceof GE) {
     return compileGE((GE) node);
   } else if (node instanceof LE) {
     return compileLE((LE) node);
   } else if (node instanceof Like) {
     return compileLike((Like) node);
   } else {
     throw new IllegalArgumentException("Unsupported node " + node.getClass());
   }
 }
Ejemplo n.º 2
0
  protected Advisory evaluateVital(Vital vital) {

    Advisory a = null;

    if (vital.isNoValueWarning() && vital.isEmpty()) {
      a = new Advisory(State.Warning, vital, null, "no source of");
    } else {
      for (Value val : vital) {
        if (val.isAtOrBelowLow()) {
          a =
              new Advisory(
                  val.isAtOrBelowCriticalLow() ? State.Alarm : State.Warning,
                  vital,
                  val.getValue(),
                  "low");
        }
        if (val.isAtOrAboveHigh()) {
          a =
              new Advisory(
                  val.isAtOrAboveCriticalHigh() ? State.Alarm : State.Warning,
                  vital,
                  val.getValue(),
                  "high");
        }
        if (a != null && a.state == State.Alarm) break;
      }
    }
    return a;
  }
Ejemplo n.º 3
0
 /** multiplicative ::= unary MUL unary multiplicative ::= unary DIV unary */
 private Value mulpiplicative() {
   Value res = unary();
   while (token.getType() == TokenType.MUL || token.getType() == TokenType.DIV) {
     if (token.getType() == TokenType.MUL) {
       res.setValue(res.getValue() * unary().getValue());
     } else if (token.getType() == TokenType.DIV) {
       res.setValue(res.getValue() / unary().getValue());
     }
   }
   return res;
 }
Ejemplo n.º 4
0
 /**
  * additive ::= multiplicative ADD multiplicative additive ::= multiplicative SUB multiplicative
  */
 private Value additive() {
   Value res = mulpiplicative();
   while (token.getType() == TokenType.ADD || token.getType() == TokenType.SUB) {
     if (token.getType() == TokenType.ADD) {
       res.setValue(res.getValue() + mulpiplicative().getValue());
     } else if (token.getType() == TokenType.SUB) {
       res.setValue(res.getValue() - mulpiplicative().getValue());
     }
   }
   return res;
 }
Ejemplo n.º 5
0
 /**
  * Create a new node (element or attribute) to be inserted into the target node as a child or
  * attribute.
  *
  * @param doc DOM document
  * @param target the target ode
  * @param value the value for creating the new node.
  */
 public void createNewNode(Document doc, Node target, Value value) {
   if (value.getLocation().startsWith("@")) {
     Attr newAttribute = doc.createAttribute(value.getLocation().substring(1));
     newAttribute.setValue(value.getValue());
     target.getAttributes().setNamedItem(newAttribute);
   } else {
     Element newElement = doc.createElement(value.getLocation());
     newElement.setTextContent(value.getValue());
     target.appendChild(newElement);
   }
 }
Ejemplo n.º 6
0
 /** equality ::= relational EQ relational equality ::= relational NEQ relational */
 private Value equality() {
   Value res = relational();
   while (token.getType() == TokenType.EQ || token.getType() == TokenType.NEQ) {
     if (token.getType() == TokenType.EQ) {
       res.setBooleanValue(res.getValue() == relational().getValue());
     } else if (token.getType() == TokenType.NEQ) {
       res.setBooleanValue(res.getValue() != relational().getValue());
     }
   }
   return res;
 }
Ejemplo n.º 7
0
  public void printValues() {

    if (isMagicSquare) {
      System.out.println("Printing magic square:");
      int totalValues = values.size();
      int n = (int) Math.sqrt(totalValues);

      int count = 0;

      for (Value v : values) {
        ++count;
        System.out.print(v.getValue() + "\t");
        if (count >= n) {
          count = 0;
          System.out.println("");
        }
      }
    } else {
      int n = values.size();
      int[] heights = new int[n];

      String toPrint = "\n";

      for (int i = 0; i < n; i++) {
        heights[i] = Integer.valueOf(values.get(i).getValue());
      }

      for (int i = 0; i < n; i++) {
        int maxValueIndex = getMax(heights);
        for (int j = 0; j < maxValueIndex; j++) {
          toPrint += " O ";
        }
        int xToAdd = n - maxValueIndex - 1;
        toPrint += " X ";
        for (int j = 0; j < xToAdd; j++) {
          toPrint += " O ";
        }
        toPrint += "\n";
        heights[maxValueIndex] = -1;
      }

      System.out.println(toPrint);
      for (Value v : values) {
        System.out.print(v.getContent() + ": " + v.getValue() + " ");
      }
      System.out.println("");
    }
  }
 /**
  * Returns the values owned by this {@link PropertyRepresentation}, represented by a string
  *
  * @return the values owned by this {@link PropertyRepresentation}, represented by a string
  */
 public ArrayList<String> getStringValue() {
   ArrayList<String> stringValues = new ArrayList<String>();
   for (Value val : values) {
     stringValues.add(val.getValue());
   }
   return stringValues;
 }
Ejemplo n.º 9
0
 public Value findValue(String stringValue) {
   for (Value value : this) {
     if (value.getValue().equals(stringValue)) {
       return value;
     }
   }
   return null;
 }
Ejemplo n.º 10
0
  // Update several Positions for the given SilverObjectId
  // only if the value is invariant
  // add by SAN
  public String buildUpdateByObjectIdStatement(Value value, int nSilverObjectId) {

    String sSQLStatement = "UPDATE " + CLASSIFICATION_TABLE;
    sSQLStatement += " SET " + AXIS_COLUMN + value.getAxisId() + " = '" + value.getValue() + "' ";
    sSQLStatement += " WHERE " + SILVEROBJECT_ID_COLUMN + " =  " + nSilverObjectId;
    sSQLStatement += " AND " + AXIS_COLUMN + value.getAxisId() + " IS NOT NULL";

    return sSQLStatement;
  }
Ejemplo n.º 11
0
 public void write(DataOutput out) throws IOException {
   out.writeInt(valueSize);
   out.writeInt(valueCount);
   Value<V> value = firstValue;
   while (value != null) {
     btree.writeValue(out, value.getValue());
     value = value.getNext();
   }
 }
Ejemplo n.º 12
0
 /**
  * relational ::= additive LT additive relational ::= additive GT additive relational ::= additive
  * LTE additive relational ::= additive GTE additive
  */
 private Value relational() {
   Value res = additive();
   while (token.getType() == TokenType.LT
       || token.getType() == TokenType.GT
       || token.getType() == TokenType.LTE
       || token.getType() == TokenType.GTE) {
     if (token.getType() == TokenType.LT) {
       res.setBooleanValue(res.getValue() < additive().getValue());
     } else if (token.getType() == TokenType.GT) {
       res.setBooleanValue(res.getValue() > additive().getValue());
     } else if (token.getType() == TokenType.LTE) {
       res.setBooleanValue(res.getValue() <= additive().getValue());
     } else if (token.getType() == TokenType.GTE) {
       res.setBooleanValue(res.getValue() >= additive().getValue());
     }
   }
   return res;
 }
Ejemplo n.º 13
0
 /**
  * Transform the DOM tree using the configuration.
  *
  * @param configuration the transformation configuration.
  * @param doc the DOM tree to be updated.
  */
 protected void applyTransformation(XmlConfiguration configuration, Document doc) {
   List<Parameter> parameters = configuration.getParameters();
   for (Parameter parameter : parameters) {
     displayMessageln("\t" + parameter.getKey() + " (mode:" + parameter.getMode() + ")");
     Node rootXpathNode = getMatchingNode(parameter.getKey(), doc);
     if (rootXpathNode != null) {
       for (Value value : parameter.getValues()) {
         switch (value.getMode()) {
           case XmlTreeHandler.MODE_INSERT:
             {
               createNewNode(doc, rootXpathNode, value);
             }
             break;
           case XmlTreeHandler.MODE_DELETE:
             {
               Node deletedNode = getMatchingNode(value.getLocation(), rootXpathNode);
               rootXpathNode.removeChild(deletedNode);
             }
             break;
           case XmlTreeHandler.MODE_UPDATE:
             {
               Node oldNode = getMatchingNode(value.getLocation(), rootXpathNode);
               if (oldNode == null) {
                 createNewNode(doc, rootXpathNode, value);
               } else {
                 if (rootXpathNode.equals(oldNode)) {
                   rootXpathNode = rootXpathNode.getParentNode();
                 }
                 Node newNode = oldNode.cloneNode(true);
                 if (oldNode instanceof Element) {
                   ((Element) newNode).setTextContent(value.getValue());
                   rootXpathNode.replaceChild(newNode, oldNode);
                 } else {
                   ((Attr) newNode).setValue(value.getValue());
                   rootXpathNode.getAttributes().setNamedItem(newNode);
                 }
               }
               break;
             }
         }
       }
     }
   }
 }
Ejemplo n.º 14
0
  // Replace the oldValue with the newValue
  public String buildReplaceValuesStatement(Value oldValue, Value newValue) {
    StringBuilder sSQLStatement = new StringBuilder(1000);

    // Build the SQL statement to remove the values
    if (newValue.getValue() != null) {
      sSQLStatement
          .append("UPDATE ")
          .append(CLASSIFICATION_TABLE)
          .append(" SET ")
          .append(AXIS_COLUMN)
          .append(newValue.getAxisId())
          .append(" = '")
          .append(newValue.getValue())
          .append("'");
    } else {
      sSQLStatement
          .append("UPDATE ")
          .append(CLASSIFICATION_TABLE)
          .append(" SET ")
          .append(AXIS_COLUMN)
          .append(newValue.getAxisId())
          .append(" = ")
          .append(newValue.getValue());
    }

    if (oldValue.getValue() != null) {
      sSQLStatement
          .append(" WHERE (")
          .append(AXIS_COLUMN)
          .append(oldValue.getAxisId())
          .append(" = '")
          .append(oldValue.getValue())
          .append("')");
    } else {
      sSQLStatement
          .append(" WHERE (")
          .append(AXIS_COLUMN)
          .append(oldValue.getAxisId())
          .append(" IS NULL)");
    }

    return sSQLStatement.toString();
  }
Ejemplo n.º 15
0
 public Value addUnique(String stringValue) {
   for (Value value : this) {
     if (value.getValue().equals(stringValue)) {
       return value;
     }
   }
   Value value = new Value();
   value.setValue(stringValue);
   add(value);
   return value;
 }
  /**
   * @param name Value name
   * @return Value for specified name
   */
  public String getValue(String name) {

    String value = null;

    for (Value v : recordValues) {
      if (v.getName().equalsIgnoreCase(name)) {
        value = v.getValue();
        break;
      }
    }

    return value;
  }
Ejemplo n.º 17
0
    @Override
    public R operate(R target) throws MappingException {
      AbstractRecord source = AbstractRecord.this;

      try {

        // [#1522] [#2989] If possible the complete state of this record should be copied onto the
        // other record
        if (target instanceof AbstractRecord) {
          AbstractRecord t = (AbstractRecord) target;

          // Iterate over target fields, to avoid ambiguities when two source fields share the same
          // name.
          for (int targetIndex = 0; targetIndex < t.size(); targetIndex++) {
            Field<?> targetField = t.field(targetIndex);
            int sourceIndex = fields.indexOf(targetField);

            if (sourceIndex >= 0) {
              DataType<?> targetType = targetField.getDataType();
              Value<?> sourceValue = values[sourceIndex];

              t.values[targetIndex] =
                  new Value<Object>(
                      targetType.convert(sourceValue.getValue()),
                      targetType.convert(sourceValue.getOriginal()),
                      sourceValue.isChanged());
            }
          }
        } else {
          for (Field<?> targetField : target.fields()) {
            Field<?> sourceField = field(targetField);

            if (sourceField != null) {
              Utils.setValue(target, targetField, source, sourceField);
            }
          }
        }

        return target;
      }

      // All reflection exceptions are intercepted
      catch (Exception e) {
        throw new MappingException("An error ocurred when mapping record to " + target, e);
      }
    }
Ejemplo n.º 18
0
  // Update a Position with the given one for the given SilverObjectId
  public String buildUpdateByPositionIdStatement(Position<Value> newPosition) {
    StringBuilder sSQLStatement = new StringBuilder(1000);
    sSQLStatement
        .append("UPDATE ")
        .append(CLASSIFICATION_TABLE)
        .append(" SET ")
        .append(POSITION_ID_COLUMN)
        .append(" = ")
        .append(newPosition.getPositionId())
        .append(", ");
    List<Value> allValues = newPosition.getValues();
    int valuesTakenInCharge = 0;
    for (int axisId = 0; axisId < axisMaxNumber; axisId++) {
      String value = null;
      if (valuesTakenInCharge < allValues.size()) {
        for (Value aValue : allValues) {
          if (aValue.getPhysicalAxisId() == axisId) {
            value = aValue.getValue();
            valuesTakenInCharge++;
            break;
          }
        }
      }
      sSQLStatement.append(AXIS_COLUMN).append(axisId);
      if (value == null || value.equals("-")) {
        sSQLStatement.append(" = ").append(value);
      } else {
        sSQLStatement.append(" = '").append(value).append("'");
      }

      if (axisId < axisMaxNumber - 1) {
        sSQLStatement.append(", ");
      }
    }

    sSQLStatement
        .append(" WHERE ")
        .append(POSITION_ID_COLUMN)
        .append(" = ")
        .append(newPosition.getPositionId());

    return sSQLStatement.toString();
  }
Ejemplo n.º 19
0
 private void addORColsToFinalList(FilterList filterList) {
   for (Entry<Column, List<Value>> entry : colWithOperatorsOfOR.entrySet()) {
     List<Value> valueList = entry.getValue();
     for (Value value : valueList) {
       if (value.getOperator() == CompareOp.EQUAL) {
         filterList.addFilter(value.getFilter());
       } else {
         SingleColumnRangeFilter rangeFltr =
             new SingleColumnRangeFilter(
                 entry.getKey().getFamily(),
                 entry.getKey().getQualifier(),
                 entry.getKey().getValuePartition(),
                 value.getValue(),
                 value.getOperator(),
                 null,
                 null);
         filterList.addFilter(rangeFltr);
       }
     }
   }
 }
  /** @return TBD */
  @Override
  public String toString() {

    StringBuffer buffer = new StringBuffer();

    buffer.append(recordName);

    for (Value value : recordValues) {
      buffer.append(' ');
      buffer.append(value.getName());
      if (value.isArrayValue()) {
        buffer.append("=");
        buffer.append(stringArrayAsString(value.getArrayValue()));
      } else {
        buffer.append("=\"");
        buffer.append(value.getValue());
        buffer.append("\"");
      }
    }

    return buffer.toString();
  }
Ejemplo n.º 21
0
  // Build the SQL statement to get a position
  public String buildVerifyStatement(int nSilverObjectId, Position<Value> position) {
    StringBuilder sSQLStatement = new StringBuilder(1000);
    List<Value> alValues = position.getValues();

    // Build the SQL statement to classify the object
    sSQLStatement
        .append("SELECT ")
        .append(POSITION_ID_COLUMN)
        .append(" FROM ")
        .append(CLASSIFICATION_TABLE);

    // Put the values for the concerning axis, put null for the other non-valued axis
    sSQLStatement.append(" WHERE (");
    for (int axis = 0; axis <= axisMaxNumber; axis++) {
      Value foundValue = null;
      for (Value aValue : alValues) {
        if (aValue.getPhysicalAxisId() == axis) {
          foundValue = aValue;
          break;
        }
      }
      String axisValue = null;
      if (foundValue != null) {
        axisValue = "'" + foundValue.getValue() + "'";
      }
      sSQLStatement.append(AXIS_COLUMN).append(axis).append(" = ").append(axisValue);
      if (axis < axisMaxNumber) {
        sSQLStatement.append(" AND ");
      }
    }
    sSQLStatement.append(")");
    sSQLStatement
        .append(" AND ")
        .append(SILVEROBJECT_ID_COLUMN)
        .append(" = ")
        .append(nSilverObjectId);

    return sSQLStatement.toString();
  }
Ejemplo n.º 22
0
  // construct from types of an argument list
  public FuncInfo(final ArrayList args) {
    if (args == null) {
      // default to noarg, any return
      _paramNames = new String[0];
      _paramTypes = new TypeSpec[0];
      _paramDefaults = new Object[0];
      _paramHasDefault = new boolean[0];
      _returnType = TypeSpec.typeOf("any");
    } else {
      final int n = args.size();
      _paramNames = new String[n];
      _paramTypes = new TypeSpec[n];
      _paramDefaults = new Object[n];
      _paramHasDefault = new boolean[n];
      _returnType = TypeSpec.typeOf("any");
      for (int a = 0; a < n; a++) {
        _paramNames[a] = null;
        _paramTypes[a] = null;
        if (args.get(a) instanceof Value) {
          // if an arg is null and is an LValue, extract it's declared
          // type
          final Value v = (Value) args.get(a);
          final boolean isNull =
              (v.getValue() == null)
                  || ((v.getValue() instanceof Any) && (((Any) v.getValue()).value == null));
          if (isNull && v.isLValue()) {
            _paramTypes[a] = v.getLValue().getSymbol().getType();
          }
          // if we have an Any value, try to deduce the type from the
          // actual value within
          else if (v.getValue() instanceof Any) { // if we have an Any
            if (v.getValue() != null) {
              _paramTypes[a] = TypeSpec.typeOf(((Any) v.getValue()).value);
            }
          }
        }
        if (_paramTypes[a] == null) {
          _paramTypes[a] = TypeSpec.typeOf(args.get(a));
        }

        _paramDefaults[a] = null;
        _paramHasDefault[a] = false;
      }
    }
  }
Ejemplo n.º 23
0
 /**
  * unary ::= NUMBER unary ::= OPEN logicalOr CLOSE unary ::= VARIABLE unary ::= NOT unary unary
  * ::= SUB unary unary ::= ADD unary
  */
 private Value unary() {
   final Value res;
   nextToken();
   if (token.getType() == TokenType.SUB) {
     res = unary();
     return res.setValue(-res.getValue());
   } else if (token.getType() == TokenType.ADD) {
     return unary();
   } else if (token.getType() == TokenType.NOT) {
     res = unary();
     return res.setBooleanValue(!res.getBooleanValue());
   } else if (token.getType() == TokenType.OPEN) {
     res = logicalOr();
     if (token.getType() != TokenType.CLOSE) {
       throw expected(TokenType.CLOSE);
     }
   } else if (token.getType() == TokenType.NUMBER) {
     res = token.getValue();
   } else if (token.getType() == TokenType.VARIABLE) {
     // resolve variable
     res = variables.get(token.getStr());
     if (res == null) {
       throw new IllegalStateException("Unexpected variable name");
     }
   } else {
     throw expected(
         TokenType.SUB,
         TokenType.ADD,
         TokenType.NOT,
         TokenType.OPEN,
         TokenType.NUMBER,
         TokenType.VARIABLE);
   }
   nextToken();
   return res;
 }
Ejemplo n.º 24
0
 @Override
 public int getValue(
     Expression receiver, ArrayList<Expression> actuals, ExpressionEvaluator expressionEvaluator) {
   return l.getValue(receiver, actuals, expressionEvaluator)
       + r.getValue(receiver, actuals, expressionEvaluator);
 }
Ejemplo n.º 25
0
 private void handleScvfOfOR(SingleColumnValueFilter scvf) {
   ValuePartition vp = null;
   if (scvf instanceof SingleColumnValuePartitionFilter) {
     vp = ((SingleColumnValuePartitionFilter) scvf).getValuePartition();
   }
   Column key = new Column(scvf.getFamily(), scvf.getQualifier(), vp);
   if (colWithOperatorsOfOR.get(key) == null) {
     List<Value> valueList = new ArrayList<FilterGroupingWorker.Value>(1);
     valueList.add(new Value(scvf.getOperator(), scvf.getComparator().getValue(), scvf));
     colWithOperatorsOfOR.put(key, valueList);
   } else {
     List<Value> valueList = colWithOperatorsOfOR.get(key);
     Iterator<Value> valueListItr = valueList.iterator();
     CompareOp operator = scvf.getOperator();
     byte[] value = scvf.getComparator().getValue();
     Value prevValueObj = null;
     while (valueListItr.hasNext()) {
       prevValueObj = valueListItr.next();
       // TODO As Anoop said we may have to check the Value type also..
       // We can not compare and validate this way. btw "a" and "K".
       // Only in case of Numeric col type we can have this check.
       byte[] prevValue = prevValueObj.getValue();
       int result = Bytes.compareTo(prevValue, value);
       CompareOp prevOperator = prevValueObj.getOperator();
       switch (operator) {
         case GREATER:
           if (prevOperator == CompareOp.GREATER || prevOperator == CompareOp.GREATER_OR_EQUAL) {
             if (result > 0) {
               valueListItr.remove();
             } else {
               // Already you found less or equal value than present value means present filter
               // will
               // return subset of previous filter. No need to add it to list.
               return;
             }
           } else if (prevOperator == CompareOp.LESS || prevOperator == CompareOp.LESS_OR_EQUAL) {
             // Need to handle conditions like previous is c1<5 and current c1>2. In these cases we
             // can change this condition into three parts c1<2,c1>=2 AND C1=<5 ,c1>5 and add to
             // list.
           } else if (prevOperator == CompareOp.EQUAL) {
             if (result > 0) {
               valueListItr.remove();
             } else if (result == 0) {
               // remove this entry and convert GREATER to GREATER_OR_EQUAL
               valueListItr.remove();
               SingleColumnValueFilter newScvf = null;
               if (vp == null) {
                 newScvf =
                     new SingleColumnValueFilter(
                         scvf.getFamily(),
                         scvf.getQualifier(),
                         CompareOp.GREATER_OR_EQUAL,
                         scvf.getComparator());
               } else {
                 newScvf =
                     new SingleColumnValuePartitionFilter(
                         scvf.getFamily(),
                         scvf.getQualifier(),
                         CompareOp.GREATER_OR_EQUAL,
                         scvf.getComparator(),
                         vp);
               }
               Value newValue = new Value(CompareOp.GREATER_OR_EQUAL, prevValue, newScvf);
               valueList.add(newValue);
               return;
             }
           }
           break;
         case GREATER_OR_EQUAL:
           if (prevOperator == CompareOp.GREATER || prevOperator == CompareOp.GREATER_OR_EQUAL) {
             if (result >= 0) {
               valueListItr.remove();
             } else {
               // Already you found less value than present value means present filter will
               // return subset of previous filter. No need to add it to list.
               return;
             }
           } else if (prevOperator == CompareOp.LESS || prevOperator == CompareOp.LESS_OR_EQUAL) {
             // Need to handle conditions like previous is c1<5 and current c1>2. In these cases we
             // can change this condition into three parts c1<2,c1>=2 AND C1=<5 ,c1>5 and add to
             // list.
           } else if (prevOperator == CompareOp.EQUAL) {
             if (result >= 0) {
               valueListItr.remove();
             }
           }
           break;
         case LESS:
           if (prevOperator == CompareOp.LESS || prevOperator == CompareOp.LESS_OR_EQUAL) {
             if (result < 0) {
               valueListItr.remove();
             } else {
               // Already you found less or equal value than present value means present filter
               // will
               // return subset of previous filter. No need to add it to list.
               return;
             }
           } else if (prevOperator == CompareOp.GREATER
               || prevOperator == CompareOp.GREATER_OR_EQUAL) {
             // Need to handle conditions like previous is c1<5 and current c1>2. In these cases we
             // can change this condition into three parts c1<2,c1>=2 AND C1=<5 ,c1>5 and add to
             // list.
           } else if (prevOperator == CompareOp.EQUAL) {
             if (result < 0) {
               valueListItr.remove();
             } else if (result == 0) {
               // remove this entry and convert LESS to LESS_OR_EQUAL
               valueListItr.remove();
               SingleColumnValueFilter newScvf = null;
               if (vp == null) {
                 newScvf =
                     new SingleColumnValueFilter(
                         scvf.getFamily(),
                         scvf.getQualifier(),
                         CompareOp.LESS_OR_EQUAL,
                         scvf.getComparator());
               } else {
                 newScvf =
                     new SingleColumnValuePartitionFilter(
                         scvf.getFamily(),
                         scvf.getQualifier(),
                         CompareOp.LESS_OR_EQUAL,
                         scvf.getComparator(),
                         vp);
               }
               Value newValue = new Value(CompareOp.LESS_OR_EQUAL, prevValue, newScvf);
               valueList.add(newValue);
               return;
             }
           }
           break;
         case LESS_OR_EQUAL:
           if (prevOperator == CompareOp.LESS || prevOperator == CompareOp.LESS_OR_EQUAL) {
             if (result <= 0) {
               valueListItr.remove();
             } else {
               // Already you found less or equal value than present value means present filter
               // will
               // return subset of previous filter. No need to add it to list.
               return;
             }
           } else if (prevOperator == CompareOp.GREATER
               || prevOperator == CompareOp.GREATER_OR_EQUAL) {
             // Need to handle conditions like previous is c1<5 and current c1>2. In these cases we
             // can change this condition into three parts c1<2,c1>=2 AND C1=<5 ,c1>5 and add to
             // list.
           } else if (prevOperator == CompareOp.EQUAL) {
             // If we dont want to do conversion we can add into first if condition.
             if (result <= 0) {
               valueListItr.remove();
             } else if (result == 0) {
               // remove this entry and convert GREATER to GREATER_OR_EQUAL
             }
           }
           break;
         case EQUAL:
           if (prevOperator == CompareOp.GREATER) {
             if (result < 0) {
               return;
             } else if (result == 0) {
               valueListItr.remove();
               SingleColumnValueFilter newScvf = null;
               if (vp == null) {
                 newScvf =
                     new SingleColumnValueFilter(
                         scvf.getFamily(),
                         scvf.getQualifier(),
                         CompareOp.GREATER_OR_EQUAL,
                         scvf.getComparator());
               } else {
                 newScvf =
                     new SingleColumnValuePartitionFilter(
                         scvf.getFamily(),
                         scvf.getQualifier(),
                         CompareOp.GREATER_OR_EQUAL,
                         scvf.getComparator(),
                         vp);
               }
               Value newValue = new Value(CompareOp.GREATER_OR_EQUAL, prevValue, newScvf);
               valueList.add(newValue);
               return;
             }
           } else if (prevOperator == CompareOp.GREATER_OR_EQUAL) {
             if (result <= 0) {
               return;
             }
           } else if (prevOperator == CompareOp.LESS) {
             if (result > 0) {
               return;
             } else if (result == 0) {
               valueListItr.remove();
               SingleColumnValueFilter newScvf = null;
               if (vp == null) {
                 newScvf =
                     new SingleColumnValueFilter(
                         scvf.getFamily(),
                         scvf.getQualifier(),
                         CompareOp.LESS_OR_EQUAL,
                         scvf.getComparator());
               } else {
                 newScvf =
                     new SingleColumnValuePartitionFilter(
                         scvf.getFamily(),
                         scvf.getQualifier(),
                         CompareOp.LESS_OR_EQUAL,
                         scvf.getComparator(),
                         vp);
               }
               Value newValue = new Value(CompareOp.LESS_OR_EQUAL, prevValue, newScvf);
               valueList.add(newValue);
               return;
             }
           } else if (prevOperator == CompareOp.LESS_OR_EQUAL) {
             if (result >= 0) {
               return;
             }
           } else if (prevOperator == CompareOp.EQUAL) {
             if (result == 0) {
               // Already same filter exists with same condiftion.
               return;
             }
           }
           break;
         case NOT_EQUAL:
         case NO_OP:
           // Need to check this
           break;
       }
     }
     valueList.add(new Value(scvf.getOperator(), scvf.getComparator().getValue(), scvf));
   }
 }
Ejemplo n.º 26
0
 /**
  * performs basic arithmetic operations on Value objects
  *
  * @param left
  * @param right
  * @param op
  * @return
  */
 public static Value evaluateInfix(Value left, Value right, Token op) {
   int precision = 10;
   double newValue = evaluateOperands(left.getValue(), right.getValue(), op, precision);
   ValueType newType = evaluateUnits(left.getType(), right.getType(), op);
   return new Value(newValue, newType);
 }
  protected INEvaluator<String, Criterion, Object> compileIn(final In in) {
    if (in.getIdentifier() instanceof Property) {
      propertyInQuery = true;
      final Property property = (Property) in.getIdentifier();
      return new INEvaluator<String, Criterion, Object>() {
        public Criterion evaluate(Object paramValue) {
          Disjunction disj = Restrictions.disjunction();

          String propertyNS = property.getNamespace();
          String propertyName = property.getName();

          for (Value value : in.getValues()) {
            Conjunction conj = Restrictions.conjunction();
            if (!StringUtils.isEmpty(property.getNamespace())) {
              conj.add(Restrictions.gt(PROPERTY_NS_DB_FIELD, propertyNS));
            }
            conj.add(Restrictions.gt(PROPERTY_NAME_DB_FIELD, propertyName));
            conj.add(Restrictions.gt(PROPERTY_VALUE_DB_FIELD, value.getValue()));

            disj.add(conj);
          }
          return disj;
        };

        public String getIdentifier() {
          return property.toString();
        };
      };
    } else {
      final String fieldName = in.getIdentifier().getName();

      if (INSTANCE_STATUS_FIELD.equals(fieldName)) {
        short noState = 200; // TODO move to constants
        final Disjunction disj = Restrictions.disjunction();

        final Collection values = ValuesHelper.extract((Collection<Value>) in.getValues());

        if (values.contains(STATUS_ACTIVE)) {
          disj.add(Restrictions.eq(INSTANCE_STATUS_DB_FIELD, ProcessState.STATE_NEW));
          disj.add(Restrictions.eq(INSTANCE_STATUS_DB_FIELD, ProcessState.STATE_ACTIVE));
          disj.add(Restrictions.eq(INSTANCE_STATUS_DB_FIELD, ProcessState.STATE_READY));
        }
        if (values.contains(STATUS_SUSPENDED)) {
          disj.add(Restrictions.eq(INSTANCE_STATUS_DB_FIELD, ProcessState.STATE_SUSPENDED));
        }
        if (values.contains(STATUS_ERROR)) {
          disj.add(
              Restrictions.eq(
                  INSTANCE_STATUS_DB_FIELD, noState)); // Error instance state doesn't exist yet
        }
        if (values.contains(STATUS_COMPLETED)) {
          disj.add(Restrictions.eq(INSTANCE_STATUS_DB_FIELD, ProcessState.STATE_COMPLETED_OK));
        }
        if (values.contains(STATUS_TERMINATED)) {
          disj.add(Restrictions.eq(INSTANCE_STATUS_DB_FIELD, ProcessState.STATE_TERMINATED));
        }
        if (values.contains(STATUS_FAULTED)) {
          disj.add(
              Restrictions.eq(INSTANCE_STATUS_DB_FIELD, ProcessState.STATE_COMPLETED_WITH_FAULT));
        }
        return new INEvaluator<String, Criterion, Object>() {
          public Criterion evaluate(Object paramValue) {
            return disj;
          };

          public String getIdentifier() {
            return INSTANCE_STATUS_DB_FIELD;
          };
        };
      } else {
        final Collection objValues;
        final Collection<Value> values = in.getValues();
        if (INSTANCE_ID_FIELD.equals(fieldName)) {
          objValues = new ArrayList<Long>(values.size());
          for (Value value : values) {
            objValues.add(Long.valueOf((String) value.getValue()));
          }
        } else if (INSTANCE_STARTED_FIELD.equals(fieldName)
            || INSTANCE_LAST_ACTIVE_FIELD.equals(fieldName)) {
          objValues = new ArrayList<Date>(values.size());
          try {
            for (Value value : values) {
              objValues.add(ISO8601DateParser.parse((String) value.getValue()));
            }
          } catch (ParseException ex) {
            throw new RuntimeException(ex);
          }
        } else {
          objValues = ValuesHelper.extract((Collection<Value>) values);
        }
        final String dbField = getDBField(fieldName);
        return new INEvaluator<String, Criterion, Object>() {
          /** @see org.apache.ode.ql.eval.skel.CommandEvaluator#evaluate(java.lang.Object) */
          public Criterion evaluate(Object paramValue) {
            return Restrictions.in(dbField, objValues);
          }

          /** @see org.apache.ode.ql.eval.skel.Identified#getIdentifier() */
          public String getIdentifier() {
            return dbField;
          }
        };
      }
    }
  }
Ejemplo n.º 28
0
  // convert the args for a call with signature callSig that is compatible
  // with this
  // to exactly the types this func expects (including filling in defaults if
  // possible)
  // throws on arg type or number mismatch
  public Object[] convertParameters(
      final FuncInfo callSig, Object[] args, final boolean externCall) {
    if (args == null) {
      args = new Object[0];
    }

    Debug.Assert(callSig != null);
    Debug.Assert(callSig.numArgs() == args.length, "supplied arg count must match callSig");

    // if (externCall) //!!!
    // Debug.WriteLine("Warning: FuncInfo.convertParameters() - externCall being ignored
    // (unimplemented)");

    if (numRequiredArgs() > callSig.numArgs()) {
      ScigolTreeParser.semanticError(
          callSig.getDefinitionLocation(),
          "not enough arguments for function " + this + " in call with signature " + callSig);
    }

    if (callSig.numArgs() > numArgs()) {
      ScigolTreeParser.semanticError(
          callSig.getDefinitionLocation(),
          "too many arguments for function " + this + " in call with signature " + callSig);
    }

    final Object[] convertedArgs = new Object[numArgs()];

    // for each formal param
    for (int a = 0; a < numArgs(); a++) {

      if (a < callSig.numArgs()) { // if param supplied
        Object arg =
            ((args[a] instanceof Value)
                ? (((Value) args[a]).getValue())
                : args[a]); // convert from Value if
        // necessary

        TypeSpec argType = TypeSpec.typeOf(arg);
        if (!argType.isAny()) { // implicit conversion from any always
          // exists
          // does an implicit conversion from the argType to the
          // parameter type exist?
          if (!TypeManager.existsImplicitConversion(argType, _paramTypes[a], new Value(arg))) {
            ScigolTreeParser.semanticError(
                callSig.getDefinitionLocation(),
                "argument "
                    + a
                    + " ("
                    + _paramNames[a]
                    + ") to func with signature "
                    + this
                    + " is of type '"
                    + argType
                    + "' which is incompatible with parameter type '"
                    + _paramTypes[a]
                    + "'");
          }
        } else {
          arg = TypeSpec.unwrapAny(arg);
          argType = TypeSpec.typeOf(arg);
        }

        // conversion
        final Value convertedArg =
            TypeManager.performImplicitConversion(argType, _paramTypes[a], new Value(arg));

        if (convertedArg == null) {
          ScigolTreeParser.semanticError(
              callSig.getDefinitionLocation(),
              "argument "
                  + a
                  + " ("
                  + _paramNames[a]
                  + ") to func with signature "
                  + this
                  + " is of type '"
                  + argType
                  + "' which cannot be converted into the required parameter type '"
                  + _paramTypes[a]
                  + "'");
        }

        convertedArgs[a] = convertedArg.getValue();
      } else { // not supplied
        // do we have a default value?
        if (!_paramHasDefault[a]) {
          ScigolTreeParser.semanticError(
              callSig.getDefinitionLocation(),
              "in call to function "
                  + this
                  + ", no argument was supplied for parameter "
                  + _paramNames[a]
                  + " (which has no default)");
        }

        // use default
        convertedArgs[a] = _paramDefaults[a];
      }
    } // for each param

    return convertedArgs;
  }
Ejemplo n.º 29
0
 public String getValue() {
   return value.getValue();
 }