Package spark.spi.rdf

Examples of spark.spi.rdf.TypedLiteralImpl


 
  @Test
  public void testData() {
    NamedNodeImpl uri1 = new NamedNodeImpl(URI.create("http://example.org/foo"));
    NamedNodeImpl uri2 = new NamedNodeImpl(URI.create("http://example.org/bar"));
    TypedLiteralImpl lit1 = new TypedLiteralImpl("10", XsdTypes.INT);
    TypedLiteralImpl lit2 = new TypedLiteralImpl("20", XsdTypes.INT);
    List<List<Object>> data = toList(
        new Object[][] {
            new Object[] { iri(uri1), iri(uri2), toInt(lit1) },
            new Object[] { iri(uri2), iri(uri1), toInt(lit2) }
        });
View Full Code Here


  public void testDatatypes() {
    Date d = new Date();
    NamedNodeImpl uri = new NamedNodeImpl(URI.create("http://example.org/foo"));
    PlainLiteralImpl lit1 = new PlainLiteralImpl("bar");
    PlainLiteralImpl lit2 = new PlainLiteralImpl("baz", "en");
    TypedLiteralImpl lit3 = new TypedLiteralImpl(DateTime.format(d, TimeZone.getDefault()), XsdTypes.DATE_TIME);
    TypedLiteralImpl aInt = new TypedLiteralImpl("20", XsdTypes.INT);
    TypedLiteralImpl aLong = new TypedLiteralImpl("54687323427654", XsdTypes.LONG);
    TypedLiteralImpl aBool = new TypedLiteralImpl("true", XsdTypes.BOOLEAN);
    TypedLiteralImpl aFloat = new TypedLiteralImpl("3.14", XsdTypes.FLOAT);
    TypedLiteralImpl aDouble = new TypedLiteralImpl("98.6", XsdTypes.DOUBLE);
    TypedLiteralImpl aString = new TypedLiteralImpl("abcd", XsdTypes.STRING);
    BlankNodeImpl bn = new BlankNodeImpl("node0");
   
    List<List<Object>> data = toList(
        new Object[][] {
            new Object[] { iri(uri) },
            new Object[] { plainLit(lit1) },
            new Object[] { plainLit(lit2) },
            new Object[] { typedLit(lit3) },
            new Object[] { Integer.valueOf(aInt.getLexical()) },
            new Object[] { Long.valueOf(aLong.getLexical()) },
            new Object[] { Boolean.valueOf(aBool.getLexical()) },
            new Object[] { Float.valueOf(aFloat.getLexical()) },
            new Object[] { Double.valueOf(aDouble.getLexical()) },
            new Object[] { aString.getLexical() },
            new Object[] { bNode(bn) },
            new Object[] { null },
        });
   
    DummySherpaServer server = new DummySherpaServer(data);
View Full Code Here

      PlainLiteral pl = (PlainLiteral)value;
      String lang = pl.language != null ? pl.language.toString() : null;
      return new PlainLiteralImpl(pl.lexical.toString(), lang);
    } else if (value instanceof TypedLiteral) {
      TypedLiteral tl = (TypedLiteral)value;
      return new TypedLiteralImpl(tl.lexical.toString(), URI.create(tl.datatype.toString()));
    } else if (value instanceof BNode) {
      return new BlankNodeImpl(((BNode)value).label.toString());
    } else {
      // Sherpa passes strings as something other than java.lang.String, so convert.
      if (value instanceof CharSequence) {
View Full Code Here

  private static final Logger logger = LoggerFactory.getLogger(TestConversions.class);
 
  public void testInt() {
    String s = "1234";
    int i = 1234;
    TypedLiteralImpl l = new TypedLiteralImpl(s, XsdTypes.INT);
    assertEquals(i, Conversions.toInteger(s));
    assertEquals(l, Conversions.toLiteral(i));
    roundTrip(Integer.valueOf(i), l);
    invalid("abc", XsdTypes.INT);
    invalid("156432418974561566571", XsdTypes.INT);
View Full Code Here

  }
 
  public void testInteger() {
    String s = "156432418974561566571";
    BigInteger i = new BigInteger(s);
    TypedLiteralImpl l = new TypedLiteralImpl(s, XsdTypes.INTEGER);
    assertEquals(i, Conversions.toBigInteger(s));
    assertEquals(l, Conversions.toLiteral(i));
    roundTrip(i, l);
    invalid("NaN", XsdTypes.INTEGER);
  }
View Full Code Here

  }
 
  public void testBoolean() {
    String s = "true";
    boolean b = true;
    TypedLiteralImpl l = new TypedLiteralImpl(s, XsdTypes.BOOLEAN);
    assertEquals(b, Conversions.toBoolean(s));
    assertEquals(l, Conversions.toLiteral(b));
    roundTrip(Boolean.valueOf(b), l);
  }
View Full Code Here

  }
 
  public void testByte() {
    String s = "99";
    byte b = 99;
    TypedLiteralImpl l = new TypedLiteralImpl(s, XsdTypes.BYTE);
    assertEquals(b, Conversions.toByte(s));
    assertEquals(l, Conversions.toLiteral(b));
    roundTrip(Byte.valueOf(b), l);
    invalid("256", XsdTypes.BYTE);
  }
View Full Code Here

  }
 
  public void testShort() {
    String s = "25943";
    short i = 25943;
    TypedLiteralImpl l = new TypedLiteralImpl(s, XsdTypes.SHORT);
    assertEquals(i, Conversions.toShort(s));
    assertEquals(l, Conversions.toLiteral(i));
    roundTrip(Short.valueOf(i), l);
    invalid("45256", XsdTypes.SHORT);
  }
View Full Code Here

  }
 
  public void testLong() {
    String s = "126476513274";
    long i = 126476513274L;
    TypedLiteralImpl l = new TypedLiteralImpl(s, XsdTypes.LONG);
    assertEquals(i, Conversions.toLong(s));
    assertEquals(l, Conversions.toLiteral(i));
    roundTrip(Long.valueOf(i), l);
    invalid("156432418974561566571", XsdTypes.LONG);
  }
View Full Code Here

  }
 
  public void testFloat() {
    String s = "5643.475";
    float f = 5643.475f;
    TypedLiteralImpl l = new TypedLiteralImpl(s, XsdTypes.FLOAT);
    assertEquals(f, Conversions.toFloat(s));
    assertEquals(l, Conversions.toLiteral(f));
    roundTrip(Float.valueOf(f), l);
    invalid("86nd", XsdTypes.FLOAT);
  }
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.