Literals { public static Literal createLiteral(ValueFactory valueFactory, Object object) { try { return createLiteral(valueFactory, object, false); } catch (LiteralUtilException e) { throw new IllegalStateException(e); } } protected  Literals(); static String getLabel(Literal l, String fallback); static String getLabel(Value v, String fallback); static String getLabel(Optional v, String fallback); static byte getByteValue(Literal l, byte fallback); static byte getByteValue(Value v, byte fallback); static short getShortValue(Literal l, short fallback); static short getShortValue(Value v, short fallback); static int getIntValue(Literal l, int fallback); static int getIntValue(Value v, int fallback); static long getLongValue(Literal l, long fallback); static long getLongValue(Value v, long fallback); static BigInteger getIntegerValue(Literal l, BigInteger fallback); static BigInteger getIntegerValue(Value v, BigInteger fallback); static BigDecimal getDecimalValue(Literal l, BigDecimal fallback); static BigDecimal getDecimalValue(Value v, BigDecimal fallback); static float getFloatValue(Literal l, float fallback); static float getFloatValue(Value v, float fallback); static double getDoubleValue(Literal l, double fallback); static double getDoubleValue(Value v, double fallback); static boolean getBooleanValue(Literal l, boolean fallback); static boolean getBooleanValue(Value v, boolean fallback); static XMLGregorianCalendar getCalendarValue(Literal l, XMLGregorianCalendar fallback); static Duration getDurationValue(Literal l, Duration fallback); static XMLGregorianCalendar getCalendarValue(Value v, XMLGregorianCalendar fallback); static Literal createLiteral(ValueFactory valueFactory, Object object); static Literal createLiteralOrFail(ValueFactory valueFactory, Object object); static boolean canCreateLiteral(Object object); static boolean isLanguageLiteral(Literal literal); static String normalizeLanguageTag(String languageTag); static boolean isValidLanguageTag(String languageTag); static boolean langMatches(String langTag, String langRange);  }
@Test public void testCreateLiteralObjectNull() throws Exception { Object obj = null; try { Literals.createLiteral(SimpleValueFactory.getInstance(), obj); fail("Did not find expected exception"); } catch (NullPointerException npe) { assertTrue(npe.getMessage().contains("Cannot create a literal from a null")); } }
@Test public void testCreateLiteralObjectBoolean() throws Exception { Object obj = Boolean.TRUE; Literal l = Literals.createLiteral(SimpleValueFactory.getInstance(), obj); assertNotNull(l); assertEquals(l.getDatatype(), XSD.BOOLEAN); assertTrue(l.booleanValue()); }
@Test public void testCreateLiteralObjectXMLGregorianCalendar() throws Exception { GregorianCalendar c = new GregorianCalendar(); c.setTime(new Date()); try { Object obj = DatatypeFactory.newInstance().newXMLGregorianCalendar(c); Literal l = Literals.createLiteral(SimpleValueFactory.getInstance(), obj); assertNotNull(l); assertEquals(l.getDatatype(), XSD.DATETIME); } catch (DatatypeConfigurationException e) { e.printStackTrace(); fail("Could not instantiate javax.xml.datatype.DatatypeFactory"); } }
@Test public void testCreateLiteralObjectDate() throws Exception { Object obj = new Date(); Literal l = Literals.createLiteral(SimpleValueFactory.getInstance(), obj); assertNotNull(l); assertEquals(l.getDatatype(), XSD.DATETIME); }
@Test public void testCreateLiteralObjectObject() throws Exception { Object obj = new Object(); Literal l = Literals.createLiteral(SimpleValueFactory.getInstance(), obj); assertNotNull(l); assertEquals(l.getDatatype(), XSD.STRING); }