Skip to content

Commit

Permalink
Add some not-null checking.
Browse files Browse the repository at this point in the history
  • Loading branch information
afs committed Jan 29, 2016
1 parent 61d13b5 commit f25c0f0
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion jena-core/src/main/java/org/apache/jena/graph/NodeFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

package org.apache.jena.graph ;

import java.util.Objects ;

import org.apache.jena.datatypes.DatatypeFormatException ;
import org.apache.jena.datatypes.RDFDatatype ;
import org.apache.jena.datatypes.TypeMapper ;
Expand All @@ -27,6 +29,7 @@
public class NodeFactory {

public static RDFDatatype getType(String s) {
Objects.requireNonNull(s, "Argument to NodeFactory.getFactory is null") ;
return TypeMapper.getInstance().getSafeTypeByName(s) ;
}

Expand All @@ -38,6 +41,7 @@ public static Node createBlankNode() {
/** make a blank node with the specified label
*/
public static Node createBlankNode(BlankNodeId id) {
Objects.requireNonNull(id, "Argument to NodeFactory.createBlankNode is null") ;
return new Node_Blank(id) ;
}

Expand All @@ -60,6 +64,7 @@ public static Node createAnon() {
*/
@Deprecated
public static Node createAnon(BlankNodeId id) {
Objects.requireNonNull(id, "Argument to NodeFactory.createAnon is null") ;
return new Node_Blank(id) ;
}

Expand All @@ -68,26 +73,31 @@ public static Node createAnon(BlankNodeId id) {
*/
@Deprecated
public static Node createAnon(String string) {
Objects.requireNonNull(string, "Argument to NodeFactory.createAnon is null") ;
BlankNodeId id = BlankNodeId.create(string) ;
return new Node_Blank(id) ;
}

/** make a literal node with the specified literal value */
public static Node createLiteral(LiteralLabel lit) {
Objects.requireNonNull(lit, "Argument to NodeFactory.createLiteral is null") ;
return new Node_Literal( lit ) ;
}

/** make a URI node with the specified URIref string */
public static Node createURI(String uri) {
Objects.requireNonNull(uri, "Argument to NodeFactory.createURI is null") ;
return new Node_URI(uri) ;
}

/** make a variable node with a given name */
public static Node createVariable(String name) {
Objects.requireNonNull(name, "Argument to NodeFactory.createVariable is null") ;
return new Node_Variable(name) ;
}

public static Node createLiteral(String value) {
Objects.requireNonNull(value, "Argument to NodeFactory.createLiteral is null") ;
return createLiteral(value, "", false) ;
}

Expand Down Expand Up @@ -168,12 +178,13 @@ public static Node createLiteral(String lex, RDFDatatype dtype) throws DatatypeF
* @throws DatatypeFormatException
*/
public static Node createLiteralByValue(Object value, RDFDatatype dtype) throws DatatypeFormatException {
Objects.requireNonNull(value, "Argument 'value' to NodeFactory.createLiteralByValue is null") ;
return new Node_Literal(LiteralLabelFactory.createByValue(value, "", dtype)) ;
}

/** Create a Node based on the value
* If the value is a string we
* assume this is inteded to be a lexical form after all.
* assume this is intended to be a lexical form after all.
* @param value
* The value, mapped according to registered types.
* @param lang
Expand All @@ -184,18 +195,21 @@ public static Node createLiteralByValue(Object value, RDFDatatype dtype) throws
* @throws DatatypeFormatException
*/
public static Node createLiteralByValue(Object value, String lang, RDFDatatype dtype) throws DatatypeFormatException {
Objects.requireNonNull(value, "Argument 'value' to NodeFactory.createLiteralByValue is null") ;
return new Node_Literal(LiteralLabelFactory.createByValue(value, lang, dtype)) ;
}

/** @deprecated To be removed: Use {@link #createLiteralByValue(Object, RDFDatatype)} */
@Deprecated
public static Node createUncachedLiteral(Object value, RDFDatatype dtype) throws DatatypeFormatException {
Objects.requireNonNull(value, "Argument 'value' to NodeFactory.createLiteralByValue is null") ;
return createLiteralByValue(value, dtype) ;
}

/** @deprecated To be removed: Use {@link #createLiteralByValue(Object, String, RDFDatatype)} */
@Deprecated
public static Node createUncachedLiteral(Object value, String lang, RDFDatatype dtype) throws DatatypeFormatException {
Objects.requireNonNull(value, "Argument 'value' to NodeFactory.createLiteralByValue is null") ;
return createLiteralByValue(value, lang, dtype) ;
}
}

0 comments on commit f25c0f0

Please sign in to comment.