return new GroovyLiteral(object.toString(), XMLSchema.LONG); } else if (object instanceof Integer) { return new GroovyLiteral(object.toString(), XMLSchema.INT); } else if (object instanceof Short) { return new GroovyLiteral(object.toString(), XMLSchema.SHORT); } else if (object instanceof Byte) { return new GroovyLiteral(object.toString(), XMLSchema.BYTE); } else if (object instanceof Double) { return new GroovyLiteral(object.toString(), XMLSchema.DOUBLE); } else if (object instanceof Float) { return new GroovyLiteral(object.toString(), XMLSchema.FLOAT); } else if (object instanceof Boolean) { return new GroovyLiteral(object.toString(), XMLSchema.BOOLEAN); } else if (object instanceof XMLGregorianCalendar) { final XMLGregorianCalendar c = (XMLGregorianCalendar) object; return new GroovyLiteral(c.toXMLFormat(), XMLDatatypeUtil.qnameToURI(c .getXMLSchemaType())); } else if (object instanceof Date) { c.setTime((Date) object); final XMLGregorianCalendar xc = DATATYPE_FACTORY.newXMLGregorianCalendar(c); return new GroovyLiteral(xc.toXMLFormat(), XMLDatatypeUtil.qnameToURI(xc .getXMLSchemaType())); } else if (object instanceof CharSequence) { return new GroovyLiteral(object.toString(), XMLSchema.STRING); } else { return new GroovyLiteral(object.toString());
return (Value) object; } else if (object instanceof Long) { return new GroovyLiteral(object.toString(), XMLSchema.LONG); } else if (object instanceof Integer) { return new GroovyLiteral(object.toString(), XMLSchema.INT); } else if (object instanceof Short) { return new GroovyLiteral(object.toString(), XMLSchema.SHORT); } else if (object instanceof Byte) { return new GroovyLiteral(object.toString(), XMLSchema.BYTE); } else if (object instanceof Double) { return new GroovyLiteral(object.toString(), XMLSchema.DOUBLE); } else if (object instanceof Float) { return new GroovyLiteral(object.toString(), XMLSchema.FLOAT); } else if (object instanceof Boolean) { return new GroovyLiteral(object.toString(), XMLSchema.BOOLEAN); } else if (object instanceof XMLGregorianCalendar) { final XMLGregorianCalendar c = (XMLGregorianCalendar) object; return new GroovyLiteral(c.toXMLFormat(), XMLDatatypeUtil.qnameToURI(c .getXMLSchemaType())); } else if (object instanceof Date) { c.setTime((Date) object); final XMLGregorianCalendar xc = DATATYPE_FACTORY.newXMLGregorianCalendar(c); return new GroovyLiteral(xc.toXMLFormat(), XMLDatatypeUtil.qnameToURI(xc .getXMLSchemaType())); } else if (object instanceof CharSequence) { return new GroovyLiteral(object.toString(), XMLSchema.STRING); } else if (object != null) { return new GroovyLiteral(object.toString());
@Override public int compareTo(final Value other) { if (other instanceof Literal) { int result = 0; if (other != this) { final Literal l = (Literal) other; result = getLabel().compareTo(l.getLabel()); if (result == 0) { final String lang1 = getLanguage(); final String lang2 = l.getLanguage(); result = lang1 != null ? lang2 != null ? lang1.compareTo(lang2) : 1 : lang2 != null ? -1 : 0; if (result == 0) { final URI dt1 = getDatatype(); final URI dt2 = l.getDatatype(); result = dt1 != null ? dt2 != null ? dt1.stringValue().compareTo( dt2.stringValue()) : 1 : dt2 != null ? -1 : 0; } } } return result; } return 1; }
@Nullable private static Value normalize(@Nullable final Value v) { if (v instanceof URI) { return v instanceof GroovyURI ? v : new GroovyURI(v.stringValue()); } else if (v instanceof BNode) { return v instanceof GroovyBNode ? v : new GroovyBNode(v.stringValue()); } else if (v instanceof Literal) { if (v instanceof GroovyLiteral) { return v; } final Literal l = (Literal) v; if (l.getLanguage() != null) { return new GroovyLiteral(l.getLabel(), l.getLanguage()); } else if (l.getDatatype() != null) { return new GroovyLiteral(l.getLabel(), l.getDatatype()); } else { return new GroovyLiteral(l.getLabel()); } } return null; }
@Nullable private static Literal toLiteral(@Nullable final Object old, @Nullable final String label) { if (label == null) { return null; } String lang = null; URI dt = null; if (old instanceof Literal) { final Literal l = (Literal) old; lang = l.getLanguage(); dt = l.getDatatype(); } return lang != null ? new GroovyLiteral(label, lang) : dt != null ? new GroovyLiteral( label, dt) : new GroovyLiteral(label); }