Package com.hp.hpl.jena.rdf.model

Examples of com.hp.hpl.jena.rdf.model.Literal


  @Test
  public void typedLiterals() {
    MGraph mGraph = new SimpleMGraph();
    com.hp.hpl.jena.graph.Graph graph = new JenaGraph(mGraph);
    Model model = ModelFactory.createModelForGraph(graph);
    Literal typedLiteral = model.createTypedLiteral("<elem>foo</elem>", XMLLiteralType.theXMLLiteralType);
    model.add(RDFS.Class, RDFS.label, typedLiteral);
    Assert.assertEquals(1, mGraph.size());
    StmtIterator iter = model.listStatements(RDFS.Class, RDFS.label, (Resource)null);
    Assert.assertTrue(iter.hasNext());
    RDFNode gotObject = iter.nextStatement().getObject();
View Full Code Here


    super.tearDown();
  }

  public void testAddContainLiteralByStatement()
  {
    final Literal L = model.createTypedLiteral(210);
    final Statement s = model.createStatement(S, RDF.value, L);
    Assert.assertTrue(model.add(s).contains(s));
    Assert.assertTrue(model.contains(S, RDF.value));
  }
View Full Code Here

    Assert.assertFalse(model.createTypedLiteral(false).getBoolean());
  }

  protected void testByte( final Model model, final byte tv )
  {
    final Literal l = model.createTypedLiteral(tv);
    Assert.assertEquals(tv, l.getByte());
    Assert.assertEquals(tv, l.getShort());
    Assert.assertEquals(tv, l.getInt());
    Assert.assertEquals(tv, l.getLong());
  }
View Full Code Here

  // // testLiteralObject( model, -67890 );
  // }

  protected void testInt( final Model model, final int tv )
  {
    final Literal l = model.createTypedLiteral(tv);
    try
    {
      Assert.assertEquals(tv, l.getByte());
      assertInRange(Byte.MIN_VALUE, tv, Byte.MAX_VALUE);
    }
    catch (final NumberFormatException e)
    {
      assertOutsideRange(Byte.MIN_VALUE, tv, Byte.MAX_VALUE);
    }
    catch (final IllegalArgumentException e)
    {
      assertOutsideRange(Byte.MIN_VALUE, tv, Byte.MAX_VALUE);
    }
    try
    {
      Assert.assertEquals(tv, l.getShort());
      assertInRange(Short.MIN_VALUE, tv, Short.MAX_VALUE);
    }
    catch (final NumberFormatException e)
    {
      assertOutsideRange(Short.MIN_VALUE, tv, Short.MAX_VALUE);
    }
    catch (final IllegalArgumentException e)
    {
      assertOutsideRange(Short.MIN_VALUE, tv, Short.MAX_VALUE);
    }
    Assert.assertEquals(tv, l.getInt());
    Assert.assertEquals(tv, l.getLong());
  }
View Full Code Here

  }

  protected void testLanguagedString( final Model model, final String tv,
      final String lang )
  {
    final Literal l = model.createLiteral(tv, lang);
    Assert.assertEquals(tv, l.getString());
    Assert.assertEquals(tv, l.getLexicalForm());
    Assert.assertEquals(lang, l.getLanguage());
  }
View Full Code Here

    testLanguagedString(model, "chat", "fr");
  }

  protected void testLong( final Model model, final long tv )
  {
    final Literal l = model.createTypedLiteral(tv);
    try
    {
      Assert.assertEquals(tv, l.getByte());
      assertInRange(Byte.MIN_VALUE, tv, Byte.MAX_VALUE);
    }
    catch (final NumberFormatException e)
    {
      assertOutsideRange(Byte.MIN_VALUE, tv, Byte.MAX_VALUE);
    }
    catch (final IllegalArgumentException e)
    {
      assertOutsideRange(Byte.MIN_VALUE, tv, Byte.MAX_VALUE);
    }
    try
    {
      Assert.assertEquals(tv, l.getShort());
      assertInRange(Short.MIN_VALUE, tv, Short.MAX_VALUE);
    }
    catch (final NumberFormatException e)
    {
      assertOutsideRange(Short.MIN_VALUE, tv, Short.MAX_VALUE);
    }
    catch (final IllegalArgumentException e)
    {
      assertOutsideRange(Short.MIN_VALUE, tv, Short.MAX_VALUE);
    }
    try
    {
      Assert.assertEquals(tv, l.getInt());
      assertInRange(Integer.MIN_VALUE, tv, Integer.MAX_VALUE);
    }
    catch (final NumberFormatException e)
    {
      assertOutsideRange(Integer.MIN_VALUE, tv, Integer.MAX_VALUE);
    }
    catch (final IllegalArgumentException e)
    {
      assertOutsideRange(Integer.MIN_VALUE, tv, Integer.MAX_VALUE);
    }
    Assert.assertEquals(tv, l.getLong());
  }
View Full Code Here

    testLong(model, Long.MAX_VALUE);
  }

  protected void testPlainString( final Model model, final String tv )
  {
    final Literal l = model.createLiteral(tv);
    Assert.assertEquals(tv, l.getString());
    Assert.assertEquals(tv, l.getLexicalForm());
    Assert.assertEquals("", l.getLanguage());
  }
View Full Code Here

    testPlainString(model, "Another test string");
  }

  protected void testShort( final Model model, final short tv )
  {
    final Literal l = model.createTypedLiteral(tv);
    try
    {
      Assert.assertEquals(tv, l.getByte());
      assertInRange(Byte.MIN_VALUE, tv, Byte.MAX_VALUE);
    }
    catch (final NumberFormatException e)
    {
      assertOutsideRange(Byte.MIN_VALUE, tv, Byte.MAX_VALUE);
    }
    catch (final IllegalArgumentException e)
    {
      assertOutsideRange(Byte.MIN_VALUE, tv, Byte.MAX_VALUE);
    }
    Assert.assertEquals(tv, l.getShort());
    Assert.assertEquals(tv, l.getInt());
    Assert.assertEquals(tv, l.getLong());
  }
View Full Code Here

      object[i] = false;
    }
    iter = model.listObjectsOfProperty(predicate[0]);
    while (iter.hasNext())
    {
      final Literal l = (Literal) iter.nextNode();
      final int i = l.getInt();
      object[i] = true;
    }
    for (int i = 0; i < (num * num); i++)
    {
      if ((i % num) == 0)
View Full Code Here

  }

  public void testDefaults()
  {
    final Alt a = model.createAlt();
    final Literal tvLiteral = model.createLiteral("test 12 string 2");
    // Resource tvResObj = model.createResource( new ResTestObjF() );
    final Bag tvBag = model.createBag();
    final Alt tvAlt = model.createAlt();
    final Seq tvSeq = model.createSeq();
    //
View Full Code Here

TOP

Related Classes of com.hp.hpl.jena.rdf.model.Literal

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.