Package spark.spi.rdf

Examples of spark.spi.rdf.TypedLiteralImpl


  }
 
  public void testDouble() {
    String s = "8734539.39586345";
    double d = 8734539.39586345d;
    TypedLiteralImpl l = new TypedLiteralImpl(s, XsdTypes.DOUBLE);
    assertEquals(d, Conversions.toDouble(s));
    assertEquals(l, Conversions.toLiteral(d));
    roundTrip(Double.valueOf(d), l);
    invalid("86nd", XsdTypes.DOUBLE);
  }
View Full Code Here


  }
 
  public void testDecimal() {
    String s = "8734539.39586345";
    BigDecimal d = new BigDecimal(s);
    TypedLiteralImpl l = new TypedLiteralImpl(s, XsdTypes.DECIMAL);
    assertEquals(d, Conversions.toDecimal(s));
    roundTrip(d, l);
    invalid("86nd", XsdTypes.DECIMAL);
  }
View Full Code Here

  }
 
  public void testDate() {
    String s = "2011-07-27T22:25:16.812Z";
    Date d = new Date(1311805516812L);
    TypedLiteralImpl l = new TypedLiteralImpl(s, XsdTypes.DATE_TIME);
    assertEquals(d, Conversions.toDateTime(s));
    roundTrip(d, l);
    invalid("Wed Jul 27 18:25:16 EDT 2011", XsdTypes.DATE_TIME);
  }
View Full Code Here

    invalid("Wed Jul 27 18:25:16 EDT 2011", XsdTypes.DATE_TIME);
  }
 
  public void testString() {
    String s = "foo bar";
    TypedLiteralImpl l = new TypedLiteralImpl(s, XsdTypes.STRING);
    assertEquals(s, Conversions.toData(new PlainLiteralImpl(s)));
    roundTrip(s, l);
  }
View Full Code Here

    assertEquals(val, Conversions.toData(lit));
    assertEquals(lit, Conversions.toLiteral(val));
  }
 
  private static void invalid(String lexical, URI datatype) {
    TypedLiteralImpl l = new TypedLiteralImpl(lexical, datatype);
    try {
      Conversions.toData(l);
      fail("Should have thrown exception converting literal " + l);
    } catch (Exception e) {
      logger.debug("Conversion exception, message: {}", e.getMessage());
View Full Code Here

        String dt = reader.getAttributeValue(null, DATATYPE);
        URI datatype = (dt == null) ? null : new URI(dt);
        String lang = reader.getAttributeValue(XML_NS, LANG);
        if (reader.next() != CHARACTERS) throw new SparqlException("Unexpected data in Literal binding");
        String lex = reader.getText();
        return (datatype != null) ? new TypedLiteralImpl(lex, datatype) : new PlainLiteralImpl(lex, lang);
      default:
        throw new SparqlException("Unexpected binding value: " + reader.getLocalName());
      }
    } catch (URISyntaxException e) {
      e.printStackTrace();
View Full Code Here

   * Convert from byte to xsd:byte typed literal
   * @param b Byte value
   * @return Converted literal
   */
  public static TypedLiteral toLiteral(byte b) {
    return new TypedLiteralImpl(Byte.toString(b), BYTE.typeUri);
  }
View Full Code Here

   * Convert from short to xsd:short typed literal
   * @param s Short value
   * @return Converted literal
   */
  public static TypedLiteral toLiteral(short s) {
    return new TypedLiteralImpl(Short.toString(s), SHORT.typeUri);
  }
View Full Code Here

   * Convert from integer to xsd:int typed literal
   * @param i Integer value
   * @return Converted literal
   */
  public static TypedLiteral toLiteral(int i) {
    return new TypedLiteralImpl(Integer.toString(i), INT.typeUri);
  }
View Full Code Here

   * Convert from long to xsd:long typed literal
   * @param l Long value
   * @return Converted literal
   */
  public static TypedLiteral toLiteral(long l) {
    return new TypedLiteralImpl(Long.toString(l), LONG.typeUri);
  }
View Full Code Here

TOP

Related Classes of spark.spi.rdf.TypedLiteralImpl

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.