public long longValue() { return lit.longValue(); }
/** * Gets the long value of the supplied literal. The fallback value is * returned in case {@link Literal#longValue()} throws a * {@link NumberFormatException}. * * @param l * The literal to get the long value for. * @param fallback * The value to fall back to in case no long value could gotten from * the literal. * @return Either the literal's long value, or the fallback value. */ public static long getLongValue(Literal l, long fallback) { try { return l.longValue(); } catch (NumberFormatException e) { return fallback; } }
public Long deserialize(Literal literal) { return Long.valueOf(literal.longValue()); }
public Long deserialize(Literal literal) { return Long.valueOf(literal.longValue()); }
public Long deserialize(Literal literal) { return Long.valueOf(literal.longValue()); }
/** * Helper. */ public Long getAsLong(final URI param, final Long defaultValue) { final Literal term = getAsLiteral(param, null); if (term != null) { return term.longValue(); } return defaultValue; }
/** * Helper. */ public Long getAsLong(final URI param, final Long defaultValue) { final Literal term = getAsLiteral(param, null); if (term != null) { return term.longValue(); } return defaultValue; }
/** * Implements {@link Literal#longValue()}. */ @Override public long longValue() { if (!isLiteral()) throw new ClassCastException(); return ((Literal) getValue()).longValue(); }
@Override public Long longValue(Value node) { try { return ((Literal)node).longValue(); } catch (ClassCastException e) { throw new IllegalArgumentException("Value "+node.stringValue()+" is not a literal" + "but of type "+debugType(node)); } }
/** * Implements {@link Literal#longValue()}. */ @Override public long longValue() { if (!isLiteral()) throw new ClassCastException(); return ((Literal) getValue()).longValue(); }
@Override public Long longValue(Value node) { try { return ((Literal)node).longValue(); } catch (ClassCastException e) { throw new IllegalArgumentException("Value "+node.stringValue()+" is not a literal" + "but of type "+debugType(node)); } }
@Override public Long longValue(Value node) { try { return ((Literal)node).longValue(); } catch (ClassCastException e) { throw new IllegalArgumentException("Value "+node.stringValue()+" is not a literal" + "but of type "+debugType(node)); } }
@Override public Long longValue(Value node) { try { return ((Literal)node).longValue(); } catch (ClassCastException e) { throw new IllegalArgumentException("Value "+node.stringValue()+" is not a literal" + "but of type "+debugType(node)); } }
public static long round(final Object arg) { return ((Literal) evaluate(new Round(), arg)).longValue(); }
public static long ceil(final Object arg) { return ((Literal) evaluate(new Ceil(), arg)).longValue(); }
public static long floor(final Object arg) { return ((Literal) evaluate(new Floor(), arg)).longValue(); }
@Override public Map<URI, Long> getReverseLinkProperties() { materialize(); final Map<URI, Long> ret = new HashMap<URI, Long>(); final String query = "SELECT ?p (COUNT(?o) AS ?count)\n" + "WHERE { ?o ?p <" + getId().toString() + "> }\n" + "GROUP BY ?p"; final ICloseableIterator<BindingSet> res = m_om.evaluate(query); while (res.hasNext()) { final BindingSet bs = res.next(); final URI pred = (URI) bs.getBinding("p").getValue(); final Long count = ((Literal) bs.getBinding("count") .getValue()).longValue(); ret.put(pred, count); } return ret; }
@Override public Map<URI, Long> getReverseLinkProperties() { materialize(); final Map<URI, Long> ret = new HashMap<URI, Long>(); final String query = "SELECT ?p (COUNT(?o) AS ?count)\n" + "WHERE { ?o ?p <" + getId().toString() + "> }\n" + "GROUP BY ?p"; final ICloseableIterator<BindingSet> res = m_om.evaluate(query); while (res.hasNext()) { final BindingSet bs = res.next(); final URI pred = (URI) bs.getBinding("p").getValue(); final Long count = ((Literal) bs.getBinding("count") .getValue()).longValue(); ret.put(pred, count); } return ret; }
private ValueExpression valueExpression(Value value) throws TransformBuildException { if (value instanceof Literal) { Literal literal = (Literal) value; URI type = literal.getDatatype(); if (type != null) { if (reasoner.isRealNumber(type)) { return new SignedNumericLiteral(new Double(literal.doubleValue())); } if (reasoner.isIntegerDatatype(type)) { return new SignedNumericLiteral(new Long(literal.longValue())); } return new StringLiteralExpression(literal.stringValue()); } } if (value instanceof URI) { URI uri = (URI) value; return new StringLiteralExpression(uri.getLocalName()); } throw new TransformBuildException("Cannot convert to ValueExpression: " + value.stringValue()); }
@Test public void testAll() throws Exception { Collection<RippleList> r = reduce("time."); assertEquals(1, r.size()); RippleList l = r.iterator().next(); assertEquals(1, l.length()); Object v = l.getFirst(); Value rv = modelConnection.toRDF(v); assertTrue(rv instanceof Literal); assertEquals(XMLSchema.LONG, ((Literal) rv).getDatatype()); long t = ((Literal) rv).longValue(); // April 10, 2011 will never come again. assertTrue(t > 1302390000000l); // If Ripple is still being compiled on April 10, 2111, it will be a great time for some spring cleaning :-) assertTrue(t < 4458063600000l); } }