Author: andy
Date: Wed Nov 27 11:11:02 2013
New Revision: 1545994

URL: http://svn.apache.org/r1545994
Log:
Tidy up

Modified:
    
jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/expr/nodevalue/NodeFunctions.java
    
jena/trunk/jena-arq/src/test/java/com/hp/hpl/jena/sparql/expr/TestNodeFunctions.java

Modified: 
jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/expr/nodevalue/NodeFunctions.java
URL: 
http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/expr/nodevalue/NodeFunctions.java?rev=1545994&r1=1545993&r2=1545994&view=diff
==============================================================================
--- 
jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/expr/nodevalue/NodeFunctions.java
 (original)
+++ 
jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/expr/nodevalue/NodeFunctions.java
 Wed Nov 27 11:11:02 2013
@@ -16,11 +16,11 @@
  * limitations under the License.
  */
 
-package com.hp.hpl.jena.sparql.expr.nodevalue;
+package com.hp.hpl.jena.sparql.expr.nodevalue ;
+
 import java.util.Iterator ;
 import java.util.UUID ;
 
-
 import com.hp.hpl.jena.datatypes.RDFDatatype ;
 import com.hp.hpl.jena.datatypes.xsd.XSDDatatype ;
 import com.hp.hpl.jena.graph.Node ;
@@ -38,74 +38,75 @@ import com.hp.hpl.jena.sparql.util.FmtUt
 import com.hp.hpl.jena.vocabulary.XSD ;
 
 /**
- * Implementation of node-centric functions.  
+ * Implementation of node-centric functions.
  */
-public class NodeFunctions
-{
+public class NodeFunctions {
     private static final NodeValue xsdString = 
NodeValue.makeNode(XSD.xstring.asNode()) ;
 
     // Helper functions
-    /** check and get a string (may be a simple literal, literal with language 
tag or an XSD string). */
-    public static Node checkAndGetStringLiteral(String label, NodeValue nv)
-    {
+    /**
+     * check and get a string (may be a simple literal, literal with language
+     * tag or an XSD string).
+     */
+    public static Node checkAndGetStringLiteral(String label, NodeValue nv) {
         Node n = nv.asNode() ;
-        if ( ! n.isLiteral() )
-            throw new ExprEvalException(label+": Not a literal: "+nv) ;
+        if ( !n.isLiteral() )
+            throw new ExprEvalException(label + ": Not a literal: " + nv) ;
         RDFDatatype dt = n.getLiteralDatatype() ;
         String lang = n.getLiteralLanguage() ;
-        
-        if ( dt != null && ! dt.equals(XSDDatatype.XSDstring) )
-            throw new ExprEvalException(label+": Not a string literal: "+nv) ;
+
+        if ( dt != null && !dt.equals(XSDDatatype.XSDstring) )
+            throw new ExprEvalException(label + ": Not a string literal: " + 
nv) ;
         return n ;
     }
-    
-    
-    /** Check for string operations with primary first arg and second second 
arg (e.g. CONTAINS) */
-    public static void checkTwoArgumentStringLiterals(String label, NodeValue 
arg1, NodeValue arg2) 
-    {
+
+    /**
+     * Check for string operations with primary first arg and second second arg
+     * (e.g. CONTAINS)
+     */
+    public static void checkTwoArgumentStringLiterals(String label, NodeValue 
arg1, NodeValue arg2) {
         Node n1 = checkAndGetStringLiteral(label, arg1) ;
         Node n2 = checkAndGetStringLiteral(label, arg2) ;
         String lang1 = n1.getLiteralLanguage() ;
         String lang2 = n2.getLiteralLanguage() ;
-        if (lang1 == null ) lang1 = "" ;
-        if (lang2 == null ) lang2 = "" ;
-        
-        if ( n1.getLiteralDatatype() != null )
-        {
+        if ( lang1 == null )
+            lang1 = "" ;
+        if ( lang2 == null )
+            lang2 = "" ;
+
+        if ( n1.getLiteralDatatype() != null ) {
             // n1 is an xsd string by checkAndGetString
-            if ( XSDDatatype.XSDstring.equals(n2.getLiteralDatatypeURI()) ) 
return ; 
-            if ( n2.getLiteralLanguage().equals("") ) return ;
-            throw new ExprEvalException(label+": Incompatible: "+arg1+" and 
"+arg2) ;
+            if ( XSDDatatype.XSDstring.equals(n2.getLiteralDatatypeURI()) )
+                return ;
+            if ( n2.getLiteralLanguage().equals("") )
+                return ;
+            throw new ExprEvalException(label + ": Incompatible: " + arg1 + " 
and " + arg2) ;
         }
-        
+
         // Incompatible?
         // arg1 simple or xsd:string, arg2 has a lang.
-        if ( lang1.equals("") && ! lang2.equals("") )
-            throw new ExprEvalException(label+": Incompatible: "+arg1+" and 
"+arg2) ;
+        if ( lang1.equals("") && !lang2.equals("") )
+            throw new ExprEvalException(label + ": Incompatible: " + arg1 + " 
and " + arg2) ;
         // arg1 with lang, arg2 has a different lang.
-        if ( ! lang1.equals("") && (!lang2.equals("") && ! lang1.equals(lang2) 
) )  
-            throw new ExprEvalException(label+": Incompatible: "+arg1+" and 
"+arg2) ;
+        if ( !lang1.equals("") && (!lang2.equals("") && !lang1.equals(lang2)) )
+            throw new ExprEvalException(label + ": Incompatible: " + arg1 + " 
and " + arg2) ;
     }
-   
- 
-    
+
     // -------- sameTerm
-    
-    public static NodeValue sameTerm(NodeValue nv1, NodeValue nv2)
-    { return NodeValue.booleanReturn(sameTerm(nv1.asNode(), nv2.asNode())) ; }
-    
-    public static boolean sameTerm(Node n1, Node n2)
-    { 
+
+    public static NodeValue sameTerm(NodeValue nv1, NodeValue nv2) {
+        return NodeValue.booleanReturn(sameTerm(nv1.asNode(), nv2.asNode())) ;
+    }
+
+    public static boolean sameTerm(Node n1, Node n2) {
         if ( n1.equals(n2) )
             return true ;
-        if ( n1.isLiteral() && n2.isLiteral() )
-        {
+        if ( n1.isLiteral() && n2.isLiteral() ) {
             // But language tags are case insensitive.
-            String lang1 =  n1.getLiteralLanguage() ;
-            String lang2 =  n2.getLiteralLanguage() ;
-            
-            if ( ! lang1.equals("") && lang1.equalsIgnoreCase(lang2) )
-            {
+            String lang1 = n1.getLiteralLanguage() ;
+            String lang2 = n2.getLiteralLanguage() ;
+
+            if ( !lang1.equals("") && lang1.equalsIgnoreCase(lang2) ) {
                 // Two language tags, equal by case insensitivity.
                 boolean b = 
n1.getLiteralLexicalForm().equals(n2.getLiteralLexicalForm()) ;
                 if ( b )
@@ -116,155 +117,152 @@ public class NodeFunctions
     }
 
     // -------- RDFterm-equals
-    
-    public static NodeValue rdfTermEquals(NodeValue nv1, NodeValue nv2)
-    { return NodeValue.booleanReturn(rdfTermEquals(nv1.asNode(), 
nv2.asNode())) ; }
-    
+
+    public static NodeValue rdfTermEquals(NodeValue nv1, NodeValue nv2) {
+        return NodeValue.booleanReturn(rdfTermEquals(nv1.asNode(), 
nv2.asNode())) ;
+    }
+
     // Exact as defined by SPARQL spec.
-    public static boolean rdfTermEquals(Node n1, Node n2)
-    { 
+    public static boolean rdfTermEquals(Node n1, Node n2) {
         if ( n1.equals(n2) )
             return true ;
-        
-        if ( n1.isLiteral() && n2.isLiteral() )
-        {
+
+        if ( n1.isLiteral() && n2.isLiteral() ) {
             // Two literals, may be sameTerm by language tag case 
insensitivity.
             String lang1 = n1.getLiteralLanguage() ;
             String lang2 = n2.getLiteralLanguage() ;
-                
-            if ( ! lang1.equals("") && lang1.equalsIgnoreCase(lang2) )
-            {
+
+            if ( !lang1.equals("") && lang1.equalsIgnoreCase(lang2) ) {
                 // Two language tags, equal by case insensitivity.
                 boolean b = 
n1.getLiteralLexicalForm().equals(n2.getLiteralLexicalForm()) ;
                 if ( b )
                     return true ;
             }
-            // Two literals, different terms, different language tags. 
-            NodeValue.raise(new ExprEvalException("Mismatch in RDFterm-equals: 
"+n1+", "+n2)) ;
+            // Two literals, different terms, different language tags.
+            NodeValue.raise(new ExprEvalException("Mismatch in RDFterm-equals: 
" + n1 + ", " + n2)) ;
         }
         // One or both not a literal.
         return false ;
     }
-    
+
     // -------- str
-    public static NodeValue str(NodeValue nv) { return 
NodeValue.makeString(str(nv.asNode())) ; }
-    public static String str(Node node)
-    { 
-        if ( node.isLiteral() ) return node.getLiteral().getLexicalForm() ;
-        if ( node.isURI() )     return node.getURI() ;
-//        if ( node.isBlank() )   return 
node.getBlankNodeId().getLabelString() ;
-//        if ( node.isBlank() )   return "" ;
+    public static NodeValue str(NodeValue nv) {
+        return NodeValue.makeString(str(nv.asNode())) ;
+    }
+
+    public static String str(Node node) {
+        if ( node.isLiteral() )
+            return node.getLiteral().getLexicalForm() ;
+        if ( node.isURI() )
+            return node.getURI() ;
+        // if ( node.isBlank() ) return node.getBlankNodeId().getLabelString() 
;
+        // if ( node.isBlank() ) return "" ;
         if ( node.isBlank() )
-            NodeValue.raise(new ExprTypeException("Blank node: "+node)) ;
-        
-        NodeValue.raise(new ExprEvalException("Not a string: "+node)) ;
+            NodeValue.raise(new ExprTypeException("Blank node: " + node)) ;
+
+        NodeValue.raise(new ExprEvalException("Not a string: " + node)) ;
         return "[undef]" ;
     }
-    
+
     // -------- datatype
-    public static NodeValue datatype(NodeValue nv) { return 
NodeValue.makeNode(datatype(nv.asNode())) ; }
-    public static Node datatype(Node node)
-    {
-        if ( ! node.isLiteral() )
-        {
-            NodeValue.raise(new ExprTypeException("datatype: Not a literal: 
"+node) );
+    public static NodeValue datatype(NodeValue nv) {
+        return NodeValue.makeNode(datatype(nv.asNode())) ;
+    }
+
+    public static Node datatype(Node node) {
+        if ( !node.isLiteral() ) {
+            NodeValue.raise(new ExprTypeException("datatype: Not a literal: " 
+ node)) ;
             return null ;
         }
 
         String s = node.getLiteralDatatypeURI() ;
-        boolean plainLiteral = (s == null || s.equals("") ) ;
-        
-        if ( plainLiteral )
-        {
-            boolean simpleLiteral = (node.getLiteralLanguage() == null || 
node.getLiteralLanguage().equals("") ) ;
-            if ( ! simpleLiteral )
+        boolean plainLiteral = (s == null || s.equals("")) ;
+
+        if ( plainLiteral ) {
+            boolean simpleLiteral = (node.getLiteralLanguage() == null || 
node.getLiteralLanguage().equals("")) ;
+            if ( !simpleLiteral )
                 return NodeConst.dtRDFlangString ;
             return XSD.xstring.asNode() ;
         }
         return NodeFactory.createURI(s) ;
     }
-    
+
     // -------- lang
-    
-    public static NodeValue lang(NodeValue nv)
-    { return NodeValue.makeString(lang(nv.asNode())) ; }
-    
-    public static String lang(Node node)
-    {
-        if ( ! node.isLiteral() )
-            NodeValue.raise(new ExprTypeException("lang: Not a literal: 
"+FmtUtils.stringForNode(node))) ;
+
+    public static NodeValue lang(NodeValue nv) {
+        return NodeValue.makeString(lang(nv.asNode())) ;
+    }
+
+    public static String lang(Node node) {
+        if ( !node.isLiteral() )
+            NodeValue.raise(new ExprTypeException("lang: Not a literal: " + 
FmtUtils.stringForNode(node))) ;
 
         String s = node.getLiteralLanguage() ;
         if ( s == null )
             s = "" ;
         return s ;
     }
-    
+
     // -------- langMatches
-    public static NodeValue langMatches(NodeValue nv, NodeValue nvPattern)
-    { return langMatches(nv, nvPattern.getString()) ; }
-    
-    public static NodeValue langMatches(NodeValue nv, String langPattern)
-    {
+    public static NodeValue langMatches(NodeValue nv, NodeValue nvPattern) {
+        return langMatches(nv, nvPattern.getString()) ;
+    }
+
+    public static NodeValue langMatches(NodeValue nv, String langPattern) {
         Node node = nv.asNode() ;
-        if ( ! node.isLiteral() )
-        {
-            NodeValue.raise(new ExprTypeException("langMatches: not a literal: 
"+node)) ;
+        if ( !node.isLiteral() ) {
+            NodeValue.raise(new ExprTypeException("langMatches: not a literal: 
" + node)) ;
             return null ;
         }
 
         String nodeLang = node.getLiteralLexicalForm() ;
-        
-        if ( langPattern .equals("*") )
-        {
-            if ( nodeLang == null || nodeLang.equals("") ) 
+
+        if ( langPattern.equals("*") ) {
+            if ( nodeLang == null || nodeLang.equals("") )
                 return NodeValue.FALSE ;
             return NodeValue.TRUE ;
         }
-        
+
         // See RFC 3066 (it's "tag (-tag)*)"
 
         String[] langElts = nodeLang.split("-") ;
         String[] langRangeElts = langPattern.split("-") ;
-        
 
         /*
-         * Here is the logic to compare language code.
-         * There is a match if the language matches the
-         * parts of the pattern - the language may be longer than
-         * the pattern.
+         * Here is the logic to compare language code. There is a match if the
+         * language matches the parts of the pattern - the language may be
+         * longer than the pattern.
          */
-        
-        /* RFC 4647 basic filtering.
+
+        /*
+         * RFC 4647 basic filtering.
          * 
-         * To do extended:
-         * 1. Remove any -*- (but not *-)
-         * 2. Compare primary tags.
-         * 3. Is the remaining range a subsequence of the remaining language 
tag? 
+         * To do extended: 1. Remove any -*- (but not *-) 2. Compare primary
+         * tags. 3. Is the remaining range a subsequence of the remaining
+         * language tag?
          */
-        
-//        // Step one: remove "-*-" (but not "*-")
-//        int j = 1 ;
-//        for ( int i = 1 ; i < langRangeElts.length ; i++ )
-//        {
-//            String range = langRangeElts[i] ;
-//            if ( range.equals("*") ) 
-//                continue ;
-//            langRangeElts[j] = range ;
-//            j++ ;
-//        }
-//
-//        // Null fill any free space.
-//        for ( int i = j ; i < langRangeElts.length ; i++ )
-//            langRangeElts[i] = null ;
-        
+
+        // // Step one: remove "-*-" (but not "*-")
+        // int j = 1 ;
+        // for ( int i = 1 ; i < langRangeElts.length ; i++ )
+        // {
+        // String range = langRangeElts[i] ;
+        // if ( range.equals("*") )
+        // continue ;
+        // langRangeElts[j] = range ;
+        // j++ ;
+        // }
+        //
+        // // Null fill any free space.
+        // for ( int i = j ; i < langRangeElts.length ; i++ )
+        // langRangeElts[i] = null ;
+
         // This is basic specific.
-        
+
         if ( langRangeElts.length > langElts.length )
             // Lang tag longer than pattern tag => can't match
             return NodeValue.FALSE ;
-        for ( int i = 0 ; i < langRangeElts.length ; i++ )
-        {
+        for ( int i = 0 ; i < langRangeElts.length ; i++ ) {
             String range = langRangeElts[i] ;
             if ( range == null )
                 break ;
@@ -274,163 +272,169 @@ public class NodeFunctions
             String lang = langElts[i] ;
             if ( range.equals("*") )
                 continue ;
-            if ( ! range.equalsIgnoreCase(lang) )
+            if ( !range.equalsIgnoreCase(lang) )
                 return NodeValue.FALSE ;
         }
         return NodeValue.TRUE ;
     }
-    
+
     // -------- isURI/isIRI
-    
-    public static NodeValue isIRI(NodeValue nv) { return 
NodeValue.booleanReturn(isIRI(nv.asNode())) ; }   
-        
-    public static boolean isIRI(Node node)
-    {
+
+    public static NodeValue isIRI(NodeValue nv) {
+        return NodeValue.booleanReturn(isIRI(nv.asNode())) ;
+    }
+
+    public static boolean isIRI(Node node) {
         if ( node.isURI() )
             return true ;
         return false ;
     }
 
-    public static NodeValue isURI(NodeValue nv) { return 
NodeValue.booleanReturn(isIRI(nv.asNode())) ; }   
-    public static boolean isURI(Node node) { return isIRI(node) ; }
-    
+    public static NodeValue isURI(NodeValue nv) {
+        return NodeValue.booleanReturn(isIRI(nv.asNode())) ;
+    }
+
+    public static boolean isURI(Node node) {
+        return isIRI(node) ;
+    }
+
     // -------- isBlank
-    public static NodeValue isBlank(NodeValue nv) { return 
NodeValue.booleanReturn(isBlank(nv.asNode())) ; }
-    public static boolean isBlank(Node node) { return node.isBlank() ; }
-    
+    public static NodeValue isBlank(NodeValue nv) {
+        return NodeValue.booleanReturn(isBlank(nv.asNode())) ;
+    }
+
+    public static boolean isBlank(Node node) {
+        return node.isBlank() ;
+    }
+
     // -------- isLiteral
-    public static NodeValue isLiteral(NodeValue nv) { return 
NodeValue.booleanReturn(isLiteral(nv.asNode())) ; }
-    public static boolean isLiteral(Node node) { return node.isLiteral() ; }
-    
-    private static final IRIFactory iriFactory = 
IRIFactory.iriImplementation() ;
-    public  static boolean warningsForIRIs = false ;
-    
+    public static NodeValue isLiteral(NodeValue nv) {
+        return NodeValue.booleanReturn(isLiteral(nv.asNode())) ;
+    }
+
+    public static boolean isLiteral(Node node) {
+        return node.isLiteral() ;
+    }
+
+    private static final IRIFactory iriFactory      = 
IRIFactory.iriImplementation() ;
+    public static boolean           warningsForIRIs = false ;
+
     // -------- IRI
-    public static NodeValue iri(NodeValue nv, String baseIRI)
-    {
+    public static NodeValue iri(NodeValue nv, String baseIRI) {
         if ( isIRI(nv.asNode()) )
             return nv ;
         Node n2 = iri(nv.asNode(), baseIRI) ;
         return NodeValue.makeNode(n2) ;
     }
-    
-    public static Node iri(Node nv, String baseIRI)
-    {
+
+    public static Node iri(Node nv, String baseIRI) {
         if ( nv.isURI() )
             return nv ;
-        
-        if ( nv.isBlank() )
-        {
+
+        if ( nv.isBlank() ) {
             // Skolemization of blank nodes to IRIs : Don't ask, just don't 
ask.
             String x = nv.getBlankNodeLabel() ;
-            return NodeFactory.createURI("_:"+x) ;
+            return NodeFactory.createURI("_:" + x) ;
         }
-        
+
         // Simple literal or xsd:string
         String str = simpleLiteralOrXSDString(nv) ;
-        if  (str == null )
-            throw new ExprEvalException("Can't make an IRI from "+nv) ;
+        if ( str == null )
+            throw new ExprEvalException("Can't make an IRI from " + nv) ;
 
         IRI iri = null ;
         String iriStr = nv.getLiteralLexicalForm() ;
-            
+
         // Level of checking?
-        if ( baseIRI != null )
-        {
-            IRI base = iriFactory.create(baseIRI);
-            iri = base.create(iriStr);
-        }
-        else
-            iri = iriFactory.create(iriStr);
+        if ( baseIRI != null ) {
+            IRI base = iriFactory.create(baseIRI) ;
+            iri = base.create(iriStr) ;
+        } else
+            iri = iriFactory.create(iriStr) ;
 
-        if ( ! iri.isAbsolute() )
-            throw new ExprEvalException("Relative IRI string: "+iriStr) ;
-        if ( warningsForIRIs && iri.hasViolation(false) )
-        {
-            String msg = "unknown violation from IRI library" ; 
+        if ( !iri.isAbsolute() )
+            throw new ExprEvalException("Relative IRI string: " + iriStr) ;
+        if ( warningsForIRIs && iri.hasViolation(false) ) {
+            String msg = "unknown violation from IRI library" ;
             Iterator<Violation> iter = iri.violations(false) ;
-            if ( iter.hasNext() )
-            {
+            if ( iter.hasNext() ) {
                 Violation viol = iter.next() ;
                 msg = viol.getShortMessage() ;
             }
-            Log.warn(NodeFunctions.class, "Bad IRI: "+msg+": "+iri) ;
+            Log.warn(NodeFunctions.class, "Bad IRI: " + msg + ": " + iri) ;
         }
         return NodeFactory.createURI(iri.toString()) ;
     }
-    
+
     // The Jena version can vbe slow to inityailise (but is pure java)
-    
-    //private static UUIDFactory factory = new UUID_V4_Gen() ;
-//    private static UUIDFactory factory = new UUID_V1_Gen() ;
-//    public static NodeValue uuid()
-//    {
-//        JenaUUID uuid = factory.generate() ;
-//        Node n = Node.createURI(uuid.asURN()) ;
-//        return NodeValue.makeNode(n) ;
-//    }
-//    
-//    public static NodeValue struuid()
-//    {
-//        JenaUUID uuid = factory.generate() ;
-//        return NodeValue.makeString(uuid.asString()) ;
-//    }
 
-    public static NodeValue struuid()
-    {
+    // private static UUIDFactory factory = new UUID_V4_Gen() ;
+    // private static UUIDFactory factory = new UUID_V1_Gen() ;
+    // public static NodeValue uuid()
+    // {
+    // JenaUUID uuid = factory.generate() ;
+    // Node n = Node.createURI(uuid.asURN()) ;
+    // return NodeValue.makeNode(n) ;
+    // }
+    //
+    // public static NodeValue struuid()
+    // {
+    // JenaUUID uuid = factory.generate() ;
+    // return NodeValue.makeString(uuid.asString()) ;
+    // }
+
+    public static NodeValue struuid() {
         return NodeValue.makeString(uuidString()) ;
     }
-    
-    public static NodeValue uuid()
-    {
-        String str = "urn:uuid:"+uuidString() ;
+
+    public static NodeValue uuid() {
+        String str = "urn:uuid:" + uuidString() ;
         Node n = NodeFactory.createURI(str) ;
         return NodeValue.makeNode(n) ;
     }
 
-    private static String uuidString()
-    {
+    private static String uuidString() {
         return UUID.randomUUID().toString() ;
     }
-    
-    private static String simpleLiteralOrXSDString(Node n)
-    {
-        if ( ! n.isLiteral() ) return null ;
-        
-        if ( n.getLiteralDatatype() == null )
-        {
+
+    private static String simpleLiteralOrXSDString(Node n) {
+        if ( !n.isLiteral() )
+            return null ;
+
+        if ( n.getLiteralDatatype() == null ) {
             if ( n.getLiteralLanguage().equals("") )
                 return n.getLiteralLexicalForm() ;
-        } else
-            if ( n.getLiteralDatatype().equals(XSDDatatype.XSDstring ))
-                return n.getLiteralLexicalForm() ;
+        } else if ( n.getLiteralDatatype().equals(XSDDatatype.XSDstring) )
+            return n.getLiteralLexicalForm() ;
         return null ;
     }
-    
-    public static NodeValue strDatatype(NodeValue v1, NodeValue v2)
-    {
-        if ( ! v1.isString() ) throw new ExprEvalException("Not a string (arg 
1): "+v1) ;
-        if ( ! v2.isIRI() ) throw new ExprEvalException("Not an IRI (arg 2): 
"+v2) ;
-        
+
+    public static NodeValue strDatatype(NodeValue v1, NodeValue v2) {
+        if ( !v1.isString() )
+            throw new ExprEvalException("Not a string (arg 1): " + v1) ;
+        if ( !v2.isIRI() )
+            throw new ExprEvalException("Not an IRI (arg 2): " + v2) ;
+
         String lex = v1.asString() ;
         Node dt = v2.asNode() ;
         // Check?
-        
+
         Node n = NodeFactory.createLiteral(lex, null, 
NodeFactory.getType(dt.getURI())) ;
-        return NodeValue.makeNode(n) ; 
+        return NodeValue.makeNode(n) ;
     }
-    
-    public static NodeValue strLang(NodeValue v1, NodeValue v2)
-    {
-        if ( ! v1.isString() ) throw new ExprEvalException("Not a string (arg 
1): "+v1) ;
-        if ( ! v2.isString() ) throw new ExprEvalException("Not a string (arg 
2): "+v2) ;
-        
+
+    public static NodeValue strLang(NodeValue v1, NodeValue v2) {
+        if ( !v1.isString() )
+            throw new ExprEvalException("Not a string (arg 1): " + v1) ;
+        if ( !v2.isString() )
+            throw new ExprEvalException("Not a string (arg 2): " + v2) ;
+
         String lex = v1.asString() ;
         String lang = v2.asString() ;
         // Check?
-        
+
         Node n = NodeFactory.createLiteral(lex, lang, null) ;
-        return NodeValue.makeNode(n) ; 
+        return NodeValue.makeNode(n) ;
     }
 
 }

Modified: 
jena/trunk/jena-arq/src/test/java/com/hp/hpl/jena/sparql/expr/TestNodeFunctions.java
URL: 
http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/test/java/com/hp/hpl/jena/sparql/expr/TestNodeFunctions.java?rev=1545994&r1=1545993&r2=1545994&view=diff
==============================================================================
--- 
jena/trunk/jena-arq/src/test/java/com/hp/hpl/jena/sparql/expr/TestNodeFunctions.java
 (original)
+++ 
jena/trunk/jena-arq/src/test/java/com/hp/hpl/jena/sparql/expr/TestNodeFunctions.java
 Wed Nov 27 11:11:02 2013
@@ -16,7 +16,7 @@
  * limitations under the License.
  */
 
-package com.hp.hpl.jena.sparql.expr;
+package com.hp.hpl.jena.sparql.expr ;
 
 import org.apache.jena.atlas.junit.BaseTest ;
 import org.junit.Test ;
@@ -28,219 +28,177 @@ import com.hp.hpl.jena.sparql.expr.nodev
 import com.hp.hpl.jena.sparql.graph.NodeConst ;
 import com.hp.hpl.jena.vocabulary.XSD ;
 
-public class TestNodeFunctions extends BaseTest
-{
+public class TestNodeFunctions extends BaseTest {
     private static final double accuracyExact = 0.0d ;
     private static final double accuracyClose = 0.000001d ;
-    
-//    public static TestSuite suite()
-//    {
-//        TestSuite ts = new TestSuite(TestNodeFunctions.class) ;
-//        ts.setName(Utils.classShortName(TestNodeFunctions.class)) ;
-//        return ts ;
-//    }
 
+    // public static TestSuite suite()
+    // {
+    // TestSuite ts = new TestSuite(TestNodeFunctions.class) ;
+    // ts.setName(Utils.classShortName(TestNodeFunctions.class)) ;
+    // return ts ;
+    // }
 
-    @Test public void testSameTerm1()
-    {
+    @Test public void testSameTerm1() {
         Node n1 = NodeFactory.createLiteral("xyz") ;
         Node n2 = NodeFactory.createLiteral("xyz") ;
         assertTrue(NodeFunctions.sameTerm(n1, n2)) ;
     }
-    
-    @Test public void testSameTerm2()
-    {
+
+    @Test public void testSameTerm2() {
         Node n1 = NodeFactory.createLiteral("xyz") ;
         Node n2 = NodeFactory.createLiteral("abc") ;
         assertFalse(NodeFunctions.sameTerm(n1, n2)) ;
     }
-    
-    @Test public void testSameTerm3()
-    {
+
+    @Test public void testSameTerm3() {
         Node n1 = NodeFactory.createLiteral("xyz") ;
         Node n2 = NodeFactory.createURI("xyz") ;
         assertFalse(NodeFunctions.sameTerm(n1, n2)) ;
     }
-    
-    @Test public void testSameTerm4()
-    {
+
+    @Test public void testSameTerm4() {
         Node n1 = NodeFactory.createLiteral("xyz") ;
         Node n2 = NodeFactory.createLiteral("xyz", null, 
XSDDatatype.XSDstring) ;
         assertFalse(NodeFunctions.sameTerm(n1, n2)) ;
     }
-    
-    @Test public void testSameTerm5()
-    {
+
+    @Test public void testSameTerm5() {
         Node n1 = NodeFactory.createLiteral("xyz", "en", null) ;
         Node n2 = NodeFactory.createLiteral("xyz", null, null) ;
         assertFalse(NodeFunctions.sameTerm(n1, n2)) ;
     }
-    
-    @Test public void testSameTerm6()
-    {
+
+    @Test public void testSameTerm6() {
         Node n1 = NodeFactory.createLiteral("xyz", "en", null) ;
         Node n2 = NodeFactory.createLiteral("xyz", "EN", null) ;
         assertTrue(NodeFunctions.sameTerm(n1, n2)) ;
     }
-    
-    @Test public void testRDFtermEquals1()
-    {
+
+    @Test public void testRDFtermEquals1() {
         Node n1 = NodeFactory.createURI("xyz") ;
         Node n2 = NodeFactory.createLiteral("xyz", null, null) ;
         assertFalse(NodeFunctions.rdfTermEquals(n1, n2)) ;
     }
-    
-    @Test public void testRDFtermEquals3()
-    {
-        // Unextended - no language tag  
+
+    @Test(expected=ExprEvalException.class)
+    public void testRDFtermEquals3() {
+        // Unextended - no language tag
         Node n1 = NodeFactory.createLiteral("xyz") ;
         Node n2 = NodeFactory.createLiteral("xyz", "en", null) ;
-        try {
-            NodeFunctions.rdfTermEquals(n1, n2) ;
-            fail("Expected an exception from rdfTermEquals") ;
-        } catch (ExprEvalException ex) {}
+        NodeFunctions.rdfTermEquals(n1, n2) ;
     }
-    
 
-    @Test public void testRDFtermEquals2()
-    {
+    @Test public void testRDFtermEquals2() {
         Node n1 = NodeFactory.createLiteral("xyz", "en", null) ;
         Node n2 = NodeFactory.createLiteral("xyz", "EN", null) ;
         assertTrue(NodeFunctions.rdfTermEquals(n1, n2)) ;
     }
-    
-    @Test public void testStr1()
-    {
+
+    @Test public void testStr1() {
         NodeValue nv = NodeValue.makeNodeInteger(56) ;
         NodeValue s = NodeFunctions.str(nv) ;
         assertEquals("56", s.getString()) ;
     }
-    
-    @Test public void testStr2()
-    {
+
+    @Test public void testStr2() {
         NodeValue nv = NodeValue.makeInteger(56) ;
         NodeValue s = NodeFunctions.str(nv) ;
         assertEquals("56", s.getString()) ;
     }
 
-    @Test public void testStr3()
-    {
+    @Test public void testStr3() {
         NodeValue nv = NodeValue.makeNode("abc", "fr", (String)null) ;
         NodeValue s = NodeFunctions.str(nv) ;
         assertEquals("abc", s.getString()) ;
     }
 
-    @Test public void testStr4()
-    {
+    @Test(expected=ExprTypeException.class)
+    public void testStr4() {
         Node n = NodeFactory.createAnon() ;
-        try {
-            String s = NodeFunctions.str(n) ;
-            fail("Expect a type exception but call succeeded") ;
-        }
-        catch (ExprTypeException ex) {} 
+        String s = NodeFunctions.str(n) ;
     }
-    
-    @Test public void testDatatype1()
-    {
+
+    @Test public void testDatatype1() {
         NodeValue nv = NodeValue.makeInteger(5) ;
         Node n = nv.asNode() ;
         Node r = NodeFunctions.datatype(n) ;
         assertEquals(XSD.integer.asNode(), r) ;
     }
 
-    @Test public void testDatatype2()
-    {
+    @Test public void testDatatype2() {
         NodeValue nv = NodeValue.makeInteger(5) ;
         NodeValue r = NodeFunctions.datatype(nv) ;
         NodeValue e = NodeValue.makeNode(XSD.integer.asNode()) ;
         assertEquals(e, r) ;
     }
 
-    @Test public void testDatatype3()
-    {
+    @Test public void testDatatype3() {
         NodeValue nv = NodeValue.makeString("abc") ;
         NodeValue r = NodeFunctions.datatype(nv) ;
         NodeValue e = NodeValue.makeNode(XSD.xstring.asNode()) ;
         assertEquals(e, r) ;
     }
 
-    @Test public void testDatatype4()
-    {
+    @Test public void testDatatype4() {
         NodeValue nv = NodeValue.makeNode("abc", "fr", (String)null) ;
         // SPARQL 1.0
-//        try {
-//            NodeValue r = NodeFunctions.datatype(nv) ;
-//            fail("Expect a type exception but call succeeded") ;
-//        }
-//        catch (ExprTypeException ex) {}
+        // try {
+        // NodeValue r = NodeFunctions.datatype(nv) ;
+        // fail("Expect a type exception but call succeeded") ;
+        // }
+        // catch (ExprTypeException ex) {}
         // SPARQL 1.1 / RDF 1.1
         NodeValue r = NodeFunctions.datatype(nv) ;
         NodeValue e = NodeValue.makeNode(NodeConst.dtRDFlangString) ;
         assertEquals(e, r) ;
     }
 
-    @Test public void testDatatype5()
-    {
-        try {
-            NodeValue nv = 
NodeValue.makeNode(NodeFactory.createURI("http://example";)) ;
-            NodeValue r = NodeFunctions.datatype(nv) ;
-            fail("Expect a type exception but call succeeded") ;
-        }
-        catch (ExprTypeException ex) {} 
+    @Test(expected=ExprTypeException.class)
+    public void testDatatype5() {
+        NodeValue nv = 
NodeValue.makeNode(NodeFactory.createURI("http://example";)) ;
+        NodeValue r = NodeFunctions.datatype(nv) ;
     }
 
-    @Test public void testDatatype6()
-    {
+    @Test(expected=ExprTypeException.class)
+    public void testDatatype6() {
         NodeValue nv = NodeValue.makeNode(NodeFactory.createAnon()) ;
-        try {
-            NodeValue r = NodeFunctions.datatype(nv) ;
-            fail("Expect a type exception but call succeeded") ;
-        }
-        catch (ExprTypeException ex) {} 
+        NodeValue r = NodeFunctions.datatype(nv) ;
     }
 
-    @Test public void testLang1()
-    {
+    @Test public void testLang1() {
         Node n = NodeFactory.createLiteral("abc", "en-gb", null) ;
         assertEquals("en-gb", NodeFunctions.lang(n)) ;
     }
 
-    @Test public void testLang2()
-    {
+    @Test public void testLang2() {
         NodeValue nv = NodeValue.makeNode("abc", "en", (String)null) ;
         NodeValue r = NodeFunctions.lang(nv) ;
         NodeValue e = NodeValue.makeString("en") ;
         assertEquals(e, r) ;
     }
 
-    @Test public void testLang3()
-    {
+    @Test public void testLang3() {
         NodeValue nv = NodeValue.makeInteger(5) ;
         NodeValue r = NodeFunctions.lang(nv) ;
         NodeValue e = NodeValue.makeString("") ;
         assertEquals(e, r) ;
     }
-    
-    @Test public void testLang4()
-    {
+
+    @Test public void testLang4() {
         NodeValue nv = NodeValue.makeNode(NodeFactory.createLiteral("simple")) 
;
         NodeValue r = NodeFunctions.lang(nv) ;
         NodeValue e = NodeValue.makeString("") ;
         assertEquals(e, r) ;
     }
-    
-    @Test public void testLang5()
-    {
+
+    @Test(expected=ExprTypeException.class)
+    public void testLang5() {
         NodeValue nv = 
NodeValue.makeNode(NodeFactory.createURI("http://example/";)) ;
-        try {
-            NodeValue r = NodeFunctions.lang(nv) ;
-            fail("Expect a type exception but call succeeded") ;
-        }
-        catch (ExprTypeException ex) {} 
+        NodeValue r = NodeFunctions.lang(nv) ;
     }
-    
-    @Test public void testLangMatches1()
-    {
+
+    @Test public void testLangMatches1() {
         NodeValue nv = NodeValue.makeString("en") ;
         NodeValue pat = NodeValue.makeString("en") ;
         NodeValue r = NodeFunctions.langMatches(nv, pat) ;
@@ -248,8 +206,7 @@ public class TestNodeFunctions extends B
         assertFalse(NodeValue.FALSE.equals(r)) ;
     }
 
-    @Test public void testLangMatches2()
-    {
+    @Test public void testLangMatches2() {
         NodeValue nv = NodeValue.makeString("en") ;
         NodeValue pat = NodeValue.makeString("fr") ;
         NodeValue r = NodeFunctions.langMatches(nv, pat) ;
@@ -257,48 +214,42 @@ public class TestNodeFunctions extends B
         assertFalse(NodeValue.TRUE.equals(r)) ;
     }
 
-    @Test public void testLangMatches3()
-    {
+    @Test public void testLangMatches3() {
         NodeValue nv = NodeValue.makeString("en-gb") ;
         NodeValue pat = NodeValue.makeString("en-gb") ;
         NodeValue r = NodeFunctions.langMatches(nv, pat) ;
         assertEquals(NodeValue.TRUE, r) ;
     }
 
-    @Test public void testLangMatches4()
-    {
+    @Test public void testLangMatches4() {
         NodeValue nv = NodeValue.makeString("en-gb") ;
         NodeValue pat = NodeValue.makeString("en") ;
         NodeValue r = NodeFunctions.langMatches(nv, pat) ;
         assertEquals(NodeValue.TRUE, r) ;
     }
 
-    @Test public void testLangMatches5()
-    {
+    @Test public void testLangMatches5() {
         NodeValue nv = NodeValue.makeString("abc") ;
         NodeValue pat = NodeValue.makeString("*") ;
         NodeValue r = NodeFunctions.langMatches(nv, pat) ;
         assertEquals(NodeValue.TRUE, r) ;
     }
 
-    @Test public void testLangMatches6()
-    {
+    @Test public void testLangMatches6() {
         NodeValue nv = NodeValue.makeString("x-y-z") ;
         NodeValue pat = NodeValue.makeString("x") ;
         NodeValue r = NodeFunctions.langMatches(nv, pat) ;
         assertEquals(NodeValue.TRUE, r) ;
     }
 
-    @Test public void testLangMatches7()
-    {
+    @Test public void testLangMatches7() {
         NodeValue nv = NodeValue.makeString("x") ;
         NodeValue pat = NodeValue.makeString("x-y-z") ;
         NodeValue r = NodeFunctions.langMatches(nv, pat) ;
         assertEquals(NodeValue.FALSE, r) ;
     }
 
-    @Test public void testLangMatches8()
-    {
+    @Test public void testLangMatches8() {
         // The language tag of a plain literal is ""
         // A language tag is not allowed to be the empty string (by RFC 3066)
         NodeValue nv = NodeValue.makeString("") ;
@@ -307,52 +258,63 @@ public class TestNodeFunctions extends B
         assertEquals(NodeValue.FALSE, r) ;
     }
 
-    @Test public void testIsIRI_1()
-    {
+    @Test
+    public void testLangMatches9() {
+        // The language-match of "" is not a legal by RFC 4647 but useful for 
language tags of "" 
+        NodeValue nv = NodeValue.makeString("") ;
+        NodeValue pat = NodeValue.makeString("") ;
+        NodeValue r = NodeFunctions.langMatches(nv, pat) ;
+        assertEquals(NodeValue.TRUE, r) ;
+    }
+
+    @Test
+    public void testLangMatches10() {
+        // The language-match of "" is not a legal by RFC 4647 but useful for 
language tags of "" 
+        NodeValue nv = NodeValue.makeString("en") ;
+        NodeValue pat = NodeValue.makeString("") ;
+        NodeValue r = NodeFunctions.langMatches(nv, pat) ;
+        assertEquals(NodeValue.FALSE, r) ;
+    }
+    
+    @Test public void testIsIRI_1() {
         NodeValue nv = 
NodeValue.makeNode(NodeFactory.createURI("http://example/";)) ;
         NodeValue r = NodeFunctions.isIRI(nv) ;
         assertEquals(NodeValue.TRUE, r) ;
     }
-    
-    @Test public void testIsIRI_2()
-    {
+
+    @Test public void testIsIRI_2() {
         NodeValue nv = 
NodeValue.makeNode(NodeFactory.createLiteral("http://example/";)) ;
         NodeValue r = NodeFunctions.isIRI(nv) ;
         assertEquals(NodeValue.FALSE, r) ;
     }
-    
-    @Test public void testIsBlank1()
-    {
-        NodeValue nv = NodeValue.makeNode(NodeFactory.createAnon());
+
+    @Test public void testIsBlank1() {
+        NodeValue nv = NodeValue.makeNode(NodeFactory.createAnon()) ;
         NodeValue r = NodeFunctions.isBlank(nv) ;
         assertEquals(NodeValue.TRUE, r) ;
-        
+
     }
 
-    @Test public void testIsBlank2()
-    {
+    @Test public void testIsBlank2() {
         NodeValue nv = NodeValue.makeNode(NodeFactory.createLiteral("xyz")) ;
         NodeValue r = NodeFunctions.isBlank(nv) ;
         assertEquals(NodeValue.FALSE, r) ;
     }
 
-    @Test public void testIsBlank3()
-    {
+    @Test public void testIsBlank3() {
         NodeValue nv = 
NodeValue.makeNode(NodeFactory.createURI("http://example/";)) ;
         NodeValue r = NodeFunctions.isBlank(nv) ;
         assertEquals(NodeValue.FALSE, r) ;
-        
+
     }
-    
-    @Test public void testIsLiteral1()
-    {
+
+    @Test public void testIsLiteral1() {
         NodeValue nv = NodeValue.makeNode(NodeFactory.createLiteral("xyz")) ;
         NodeValue r = NodeFunctions.isLiteral(nv) ;
         assertEquals(NodeValue.TRUE, r) ;
     }
 
-    @Test public void testIsLiteral2()
-    {
+    @Test public void testIsLiteral2() {
         NodeValue nv = 
NodeValue.makeNode(NodeFactory.createURI("http://example/";)) ;
         NodeValue r = NodeFunctions.isLiteral(nv) ;
         assertEquals(NodeValue.FALSE, r) ;


Reply via email to