/** * Creates an integer. * * @param value The value. * * @return An integer. */ public IntLiteral integer(int value) { return new IntLiteral(value); }
/** * @param name The name of the component type to get the unique groupings of. * * @return The unique groupings of a named component type. */ private Map<String, List<String>> getUniqueGroupings(String name) { String queryString = "?- unique_group_field(" + name + ", G, F)."; Iterable<Map<String, Variable>> uniqueFieldsIterable = runQuery(queryString); Map<String, List<String>> results = new LinkedHashMap<String, List<String>>(); for (Map<String, Variable> variables : uniqueFieldsIterable) { Variable var = variables.get("F"); Functor fieldFunctor = (Functor) var.getValue(); String fieldName = engine.getFunctorName(fieldFunctor); var = variables.get("G"); Term groupNoTerm = var.getValue(); int groupNo = ((IntLiteral) groupNoTerm).intValue(); System.out.println("UniqueGroups: " + groupNo + " : " + fieldName); String group = (groupNo == 0) ? "" : Integer.toString(groupNo); List<String> fieldList = results.get(group); if (fieldList == null) { fieldList = new LinkedList<String>(); results.put(group, fieldList); } fieldList.add(fieldName); } return results; }
/** * Creates an integer. * * @param value The value. * * @return An integer. */ public IntLiteral integer(int value) { return new IntLiteral(value); }
/** * Parses an integer literal. * * @return An integer literal. * * @throws SourceCodeException If the next token in the sequence is not an integer literal. */ public Term intLiteral() throws SourceCodeException { Token valToken = consumeToken(INTEGER_LITERAL); NumericType result = new IntLiteral(Integer.parseInt(valToken.image)); // Set the position that the literal was parsed from. SourceCodePosition position = new SourceCodePositionImpl(valToken.beginLine, valToken.beginColumn, valToken.endLine, valToken.endColumn); result.setSourceCodePosition(position); return result; }
/** * Parses an integer literal. * * @return An integer literal. * * @throws SourceCodeException If the next token in the sequence is not an integer literal. */ public NumericType intLiteral() throws SourceCodeException { Token valToken = consumeToken(INTEGER_LITERAL); NumericType result = new IntLiteral(Integer.parseInt(valToken.image)); // Set the position that the literal was parsed from. SourceCodePosition position = new SourceCodePositionImpl(valToken.beginLine, valToken.beginColumn, valToken.endLine, valToken.endColumn); result.setSourceCodePosition(position); return result; }
/** * Evaluates the arithmetic operator on its numeric argument. * * @param firstNumber The first argument. * * @return The result of performing the arithmetic operator on its argument. */ protected NumericType evaluate(NumericType firstNumber) { // If the argument is a real number, then use real number arithmetic, otherwise use integer arithmetic. if (firstNumber.isInteger()) { return new IntLiteral(-firstNumber.intValue()); } else { return new DoubleLiteral(-firstNumber.doubleValue()); } } }
return new IntLiteral(result);
/** * Evaluates the arithmetic operator on its two numeric arguments. * * @param firstNumber The first argument. * @param secondNumber The second argument. * * @return The result of performing the arithmetic operator on its arguments. */ protected NumericType evaluate(NumericType firstNumber, NumericType secondNumber) { // If either of the arguments is a real number, then use real number arithmetic, otherwise use integer arithmetic. if (firstNumber.isInteger() && secondNumber.isInteger()) { return new IntLiteral(firstNumber.intValue() * secondNumber.intValue()); } else { return new DoubleLiteral(firstNumber.doubleValue() * secondNumber.doubleValue()); } } }
/** * Evaluates the arithmetic operator on its two numeric arguments. * * @param firstNumber The first argument. * @param secondNumber The second argument. * * @return The result of performing the arithmetic operator on its arguments. */ protected NumericType evaluate(NumericType firstNumber, NumericType secondNumber) { // If either of the arguments is a real number, then use real number arithmetic, otherwise use integer arithmetic. if (firstNumber.isInteger() && secondNumber.isInteger()) { return new IntLiteral(firstNumber.intValue() / secondNumber.intValue()); } else { return new DoubleLiteral(firstNumber.doubleValue() / secondNumber.doubleValue()); } } }
/** * Evaluates the arithmetic operator on its two numeric arguments. * * @param firstNumber The first argument. * @param secondNumber The second argument. * * @return The result of performing the arithmetic operator on its arguments. */ protected NumericType evaluate(NumericType firstNumber, NumericType secondNumber) { // If either of the arguments is a real number, then use real number arithmetic, otherwise use integer arithmetic. if (firstNumber.isInteger() && secondNumber.isInteger()) { return new IntLiteral(firstNumber.intValue() + secondNumber.intValue()); } else { return new DoubleLiteral(firstNumber.doubleValue() + secondNumber.doubleValue()); } } }
/** * Evaluates the arithmetic operator on its two numeric arguments. * * @param firstNumber The first argument. * @param secondNumber The second argument. * * @return The result of performing the arithmetic operator on its arguments. */ protected NumericType evaluate(NumericType firstNumber, NumericType secondNumber) { // If either of the arguments is a real number, then use real number arithmetic, otherwise use integer arithmetic. if (firstNumber.isInteger() && secondNumber.isInteger()) { return new IntLiteral(firstNumber.intValue() - secondNumber.intValue()); } else { return new DoubleLiteral(firstNumber.doubleValue() - secondNumber.doubleValue()); } } }