/** * Gets the int value of the supplied literal. The fallback value is returned in case * {@link Literal#intValue()} throws a {@link NumberFormatException}. * * @param l * The literal to get the int value for. * @param fallback * The value to fall back to in case no int value could gotten from the literal. * @return Either the literal's int value, or the fallback value. */ public static int getIntValue(Literal l, int fallback) { try { return l.intValue(); } catch (NumberFormatException e) { return fallback; } }
/** * Gets the int value of the supplied literal. The fallback value is returned in case * {@link Literal#intValue()} throws a {@link NumberFormatException}. * * @param l * The literal to get the int value for. * @param fallback * The value to fall back to in case no int value could gotten from the literal. * @return Either the literal's int value, or the fallback value. */ public static int getIntValue(Literal l, int fallback) { try { return l.intValue(); } catch (NumberFormatException e) { return fallback; } }
private int literalToInt(Value v) { if (!(v instanceof Literal)) { throw new IllegalArgumentException( "value [" + v + "] was not a literal, which is expected " + "for a parameter of type int or Integer." ); } Literal literal = (Literal) v; return literal.intValue(); }
private int getMaxIterationCount(Resource ruleProp, TripleSource store) throws RDF4JException { Value v = TripleSources.singleValue(ruleProp, SPIN.RULE_PROPERTY_MAX_ITERATION_COUNT_PROPERTY, store); if (v == null) { return -1; } else if (v instanceof Literal) { try { return ((Literal)v).intValue(); } catch (NumberFormatException e) { throw new MalformedSpinException( "Value for " + SPIN.RULE_PROPERTY_MAX_ITERATION_COUNT_PROPERTY + " must be of datatype " + XMLSchema.INTEGER + ": " + ruleProp); } } else { throw new MalformedSpinException("Non-literal value for " + SPIN.RULE_PROPERTY_MAX_ITERATION_COUNT_PROPERTY + ": " + ruleProp); } }
throw new ValueExprEvaluationException("Second list element must be a literal"); final int from = ((Literal)args[0]).intValue(); final int to = ((Literal)args[1]).intValue(); return new CloseableIteratorIteration<List<? extends Value>, QueryEvaluationException>( SingleValueToListTransformer.transform(new Iterator<Value>()
@Override public Value evaluate(ValueFactory valueFactory, Value... args) throws ValueExprEvaluationException { if (args.length < 2 || args.length > 3) { throw new ValueExprEvaluationException("Incorrect number of arguments"); } if (!(args[0] instanceof Literal)) { throw new ValueExprEvaluationException("First argument must be a string"); } if (!(args[1] instanceof Literal)) { throw new ValueExprEvaluationException("Second argument must be a string"); } if (args.length == 3 && !(args[2] instanceof Literal)) { throw new ValueExprEvaluationException("Third argument must be an integer"); } Literal s = (Literal)args[0]; Literal t = (Literal)args[1]; int pos = (args.length == 3) ? ((Literal)args[2]).intValue() : s.getLabel().length(); int index = s.getLabel().lastIndexOf(t.getLabel(), pos); if (index == -1) { throw new ValueExprEvaluationException("Substring not found"); } return valueFactory.createLiteral(index); } }
lit -> setMaxQueryTime(lit.intValue()));
lit -> setMaxQueryTime(lit.intValue()));
@Override public Value evaluate(ValueFactory valueFactory, Value... args) throws ValueExprEvaluationException { if (args.length < 2 || args.length > 3) { throw new ValueExprEvaluationException("Incorrect number of arguments"); } if (!(args[0] instanceof Literal)) { throw new ValueExprEvaluationException("First argument must be a string"); } if (!(args[1] instanceof Literal)) { throw new ValueExprEvaluationException("Second argument must be a string"); } if (args.length == 3 && !(args[2] instanceof Literal)) { throw new ValueExprEvaluationException("Third argument must be an integer"); } Literal s = (Literal)args[0]; Literal t = (Literal)args[1]; int pos = (args.length == 3) ? ((Literal)args[2]).intValue() : 0; int index = s.getLabel().indexOf(t.getLabel(), pos); if (index == -1) { throw new ValueExprEvaluationException("Substring not found"); } return valueFactory.createLiteral(index); } }
lit -> setMaxQueryTime(lit.intValue()));
Literal argLiteral = (Literal)arg; if (XMLSchema.INTEGER.equals(argLiteral.getDatatype())) { jsArg = argLiteral.intValue();
Literal minPath = (Literal)TripleSources.singleValue(path, SP.MOD_MIN_PROPERTY, store); Literal maxPath = (Literal)TripleSources.singleValue(path, SP.MOD_MAX_PROPERTY, store); if (maxPath == null || maxPath.intValue() != -2) { throw new UnsupportedOperationException("Unsupported mod path");
Literal l = (Literal) o; Assert.assertEquals(lit, l); int i = l.intValue(); Assert.assertEquals(42, i); IRI dt = l.getDatatype();