private static int compareLiteralsBySyntax(Node node1, Node node2)
{
if ( node1 == null || ! node1.isLiteral() ||
node2 == null || ! node2.isLiteral() )
throw new ARQInternalErrorException("compareLiteralsBySyntax called with non-literal: ("+node1+","+node2+")") ;
if ( node1.equals(node2) )
return Expr.CMP_EQUAL ;
String lex1 = node1.getLiteralLexicalForm() ;
String lex2 = node2.getLiteralLexicalForm() ;
int x = StrUtils.strCompare(lex1, lex2) ;
if ( x != Expr.CMP_EQUAL )
return x ;
// Same lexical form. Not .equals()
String lang1 = node1.getLiteralLanguage() ;
String lang2 = node2.getLiteralLanguage() ;
String dt1 = node1.getLiteralDatatypeURI() ;
String dt2 = node2.getLiteralDatatypeURI() ;
if ( lang1 == null )
throw new ARQInternalErrorException("Language tag is null: "+node1) ;
if ( lang2 == null )
throw new ARQInternalErrorException("Language tag is null: "+node2) ;
if ( simpleLiteral(node1) )
// Node 2 can't be simple because they'd be the same
return Expr.CMP_LESS ;
if ( simpleLiteral(node2) )
return Expr.CMP_GREATER ;
// Neither simple.
// Language before datatypes.
// Can't both be no lang, no datatype
// because they are already same lexcial form
// so they'd be same simple literal.
if ( ! lang1.equals("") && dt2 != null )
return Expr.CMP_LESS ;
if ( dt1 != null && ! lang2.equals("") )
return Expr.CMP_GREATER ;
// Both language tags, or both datatypes
if ( dt1 == null && dt2 == null )
{
// Syntactic - lang tags case considered
// case sensitive if necessary
x = StrUtils.strCompareIgnoreCase(lang1, lang2) ;
if ( x != Expr.CMP_EQUAL )
return x ;
x = StrUtils.strCompare(lang1, lang2) ;
if ( x != Expr.CMP_EQUAL )
return x ;
throw new ARQInternalErrorException("compareLiteralsBySyntax: lexical form and languages tags identical on non.equals literals");
}
// Two datatypes.
return StrUtils.strCompare(dt1, dt2) ;
}