/** * Evaluates the arithmetic comparison on its two numeric arguments. * * @param firstNumber The first argument. * @param secondNumber The second argument. * * @return The result of performing the arithmetic comparison on its arguments. */ protected boolean 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 firstNumber.intValue() > secondNumber.intValue(); } else { return firstNumber.doubleValue() > secondNumber.doubleValue(); } } }
/** * Determines if this number is equal to another. * * @param comparator The object to compare to. * * @return <tt>true</tt> if the comparator is a number equal in value to this one, <tt>false</tt> otherwise. */ public boolean equals(Object comparator) { if (this == comparator) { return true; } if ((comparator == null) || !(comparator instanceof NumericType)) { return false; } NumericType comparatorNumber = (NumericType) comparator; return value == comparatorNumber.floatValue(); }
/** * Determines if this number is equal to another. * * @param comparator The object to compare to. * * @return <tt>true</tt> if the comparator is a number equal in value to this one, <tt>false</tt> otherwise. */ public boolean equals(Object comparator) { if (this == comparator) { return true; } if ((comparator == null) || !(comparator instanceof NumericType)) { return false; } NumericType comparatorNumber = (NumericType) comparator; return value == comparatorNumber.longValue(); }
/** * Extracts all restricted real types from the type checked model and caches them in the 'catalogueTypes' parameter * by name. * * @param catalogueTypes The map to build up the catalogue types in. */ private void initializeAllRestrictedRealTypes(Map<String, Type> catalogueTypes) { String queryString = "?-normal_type(real_range, MN, JT, _MP), member(from(From), _MP), member(to(To), _MP)."; Iterable<Map<String, Variable>> bindingsIterable = runQuery(queryString); for (Map<String, Variable> bindings : bindingsIterable) { String typeName = engine.getFunctorName((Functor) bindings.get("MN").getValue()); String javaTypeName = engine.getFunctorName((Functor) bindings.get("JT").getValue()); NumericType fromTerm = (NumericType) bindings.get("From").getValue(); NumericType toTerm = (NumericType) bindings.get("To").getValue(); if ("float".equals(javaTypeName)) { catalogueTypes.put(typeName, FloatRangeType.createInstance(typeName, fromTerm.floatValue(), toTerm.floatValue())); } else if ("double".equals(javaTypeName)) { catalogueTypes.put(typeName, DoubleRangeType.createInstance(typeName, fromTerm.doubleValue(), toTerm.doubleValue())); } } }
/** * Determines if this number is equal to another. * * @param comparator The object to compare to. * * @return <tt>true</tt> if the comparator is a number equal in value to this one, <tt>false</tt> otherwise. */ public boolean equals(Object comparator) { if (this == comparator) { return true; } if ((comparator == null) || !(comparator instanceof NumericType)) { return false; } NumericType comparatorNumber = (NumericType) comparator; return value == comparatorNumber.intValue(); }
/** * Determines if this number is equal to another. * * @param comparator The object to compare to. * * @return <tt>true</tt> if the comparator is a number equal in value to this one, <tt>false</tt> otherwise. */ public boolean equals(Object comparator) { if (this == comparator) { return true; } if ((comparator == null) || !(comparator instanceof NumericType)) { return false; } NumericType comparatorNumber = (NumericType) comparator; return value == comparatorNumber.doubleValue(); }
/** * 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; }
/** {@inheritDoc} */ public void accept(TermVisitor visitor) { if (visitor instanceof IntegerTypeVisitor) { ((IntegerTypeVisitor) visitor).visit(this); } else { super.accept(visitor); } } }
/** {@inheritDoc} */ public boolean proofStep(ResolutionState state) { Functor goalTerm = state.getGoalStack().poll().getFunctor(); Term argument = goalTerm.getArgument(0).getValue(); // Check that the argument is not a free variable. return argument.isNumber() && ((NumericType) argument.getValue()).isInteger(); } }
/** * Determines if this number is equal to another. * * @param comparator The object to compare to. * * @return <tt>true</tt> if the comparator is a number equal in value to this one, <tt>false</tt> otherwise. */ public boolean equals(Object comparator) { if (this == comparator) { return true; } if ((comparator == null) || !(comparator instanceof NumericType)) { return false; } NumericType comparatorNumber = (NumericType) comparator; return value == comparatorNumber.intValue(); }
/** * Determines if this number is equal to another. * * @param comparator The object to compare to. * * @return <tt>true</tt> if the comparator is a number equal in value to this one, <tt>false</tt> otherwise. */ public boolean equals(Object comparator) { if (this == comparator) { return true; } if ((comparator == null) || !(comparator instanceof NumericType)) { return false; } NumericType comparatorNumber = (NumericType) comparator; return value == comparatorNumber.doubleValue(); }
/** * 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; }
/** {@inheritDoc} */ public void accept(TermVisitor visitor) { if (visitor instanceof IntegerTypeVisitor) { ((IntegerTypeVisitor) visitor).visit(this); } else { super.accept(visitor); } } }
/** * Evaluates the arithmetic comparison on its two numeric arguments. * * @param firstNumber The first argument. * @param secondNumber The second argument. * * @return The result of performing the arithmetic comparison on its arguments. */ protected boolean 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 firstNumber.intValue() >= secondNumber.intValue(); } else { return firstNumber.doubleValue() >= secondNumber.doubleValue(); } } }
/** * Extracts all restricted int types from the type checked model and caches them in 'catalogueTypes' parameter by * name. * * @param catalogueTypes The map to build up the catalogue types in. */ private void initializeAllRestrictedIntTypes(Map<String, Type> catalogueTypes) { String queryString = "?-normal_type(integer_range, MN, JT, _MP), member(from(From), _MP), member(to(To), _MP)."; Iterable<Map<String, Variable>> bindingsIterable = runQuery(queryString); for (Map<String, Variable> bindings : bindingsIterable) { String typeName = engine.getFunctorName((Functor) bindings.get("MN").getValue()); String javaTypeName = engine.getFunctorName((Functor) bindings.get("JT").getValue()); NumericType fromTerm = (NumericType) bindings.get("From").getValue(); NumericType toTerm = (NumericType) bindings.get("To").getValue(); if ("int".equals(javaTypeName)) { catalogueTypes.put(typeName, IntRangeType.createInstance(typeName, fromTerm.intValue(), toTerm.intValue())); } else if ("long".equals(javaTypeName)) { } } }
/** * Determines if this number is equal to another. * * @param comparator The object to compare to. * * @return <tt>true</tt> if the comparator is a number equal in value to this one, <tt>false</tt> otherwise. */ public boolean equals(Object comparator) { if (this == comparator) { return true; } if ((comparator == null) || !(comparator instanceof NumericType)) { return false; } NumericType comparatorNumber = (NumericType) comparator; return value == comparatorNumber.floatValue(); }
/** * Parses a real number literal. * * @return A real number literal. * * @throws SourceCodeException If the next token in the sequence is not a real number literal. */ public NumericType doubleLiteral() throws SourceCodeException { Token valToken = consumeToken(FLOATING_POINT_LITERAL); NumericType result = new DoubleLiteral(Double.parseDouble(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; }
/** * Determines if this number is equal to another. * * @param comparator The object to compare to. * * @return <tt>true</tt> if the comparator is a number equal in value to this one, <tt>false</tt> otherwise. */ public boolean equals(Object comparator) { if (this == comparator) { return true; } if ((comparator == null) || !(comparator instanceof NumericType)) { return false; } NumericType comparatorNumber = (NumericType) comparator; return value == comparatorNumber.longValue(); }
/** * Evaluates the arithmetic comparison on its two numeric arguments. * * @param firstNumber The first argument. * @param secondNumber The second argument. * * @return The result of performing the arithmetic comparison on its arguments. */ protected boolean 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 firstNumber.intValue() < secondNumber.intValue(); } else { return firstNumber.doubleValue() < secondNumber.doubleValue(); } } }