Repository: incubator-commonsrdf Updated Branches: refs/heads/master 67db96f68 -> 5ee4c293c
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/5ee4c293/simple/src/main/java/org/apache/commons/rdf/simple/Types.java ---------------------------------------------------------------------- diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/Types.java b/simple/src/main/java/org/apache/commons/rdf/simple/Types.java index 12d37a2..d202b8b 100644 --- a/simple/src/main/java/org/apache/commons/rdf/simple/Types.java +++ b/simple/src/main/java/org/apache/commons/rdf/simple/Types.java @@ -17,296 +17,374 @@ */ package org.apache.commons.rdf.simple; +import org.apache.commons.rdf.api.IRI; + import java.util.Collections; import java.util.LinkedHashSet; import java.util.Optional; import java.util.Set; -import org.apache.commons.rdf.api.IRI; - /** * Types from the RDF and XML Schema vocabularies. - * */ public final class Types implements IRI { - /** <tt>http://www.w3.org/1999/02/22-rdf-syntax-ns#HTML</tt> */ - public static final Types RDF_HTML = new Types( - "http://www.w3.org/1999/02/22-rdf-syntax-ns#HTML"); - - /** <tt>http://www.w3.org/1999/02/22-rdf-syntax-ns#langString</tt> */ - public static final Types RDF_LANGSTRING = new Types( - "http://www.w3.org/1999/02/22-rdf-syntax-ns#langString"); - - /** - * <tt>http://www.w3.org/1999/02/22-rdf-syntax-ns#PlainLiteral</tt> - * - * @deprecated Not used in RDF-1.1 - */ - @Deprecated - public static final Types RDF_PLAINLITERAL = new Types( - "http://www.w3.org/1999/02/22-rdf-syntax-ns#PlainLiteral"); - - /** <tt>http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral</tt> */ - public static final Types RDF_XMLLITERAL = new Types( - "http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral"); - - /** <tt>http://www.w3.org/2001/XMLSchema#anyURI</tt> */ - public static final Types XSD_ANYURI = new Types( - "http://www.w3.org/2001/XMLSchema#anyURI"); - - /** <tt>http://www.w3.org/2001/XMLSchema#base64Binary</tt> */ - public static final Types XSD_BASE64BINARY = new Types( - "http://www.w3.org/2001/XMLSchema#base64Binary"); - - /** <tt>http://www.w3.org/2001/XMLSchema#boolean</tt> */ - public static final Types XSD_BOOLEAN = new Types( - "http://www.w3.org/2001/XMLSchema#boolean"); - - /** <tt>http://www.w3.org/2001/XMLSchema#byte</tt> */ - public static final Types XSD_BYTE = new Types( - "http://www.w3.org/2001/XMLSchema#byte"); - - /** <tt>http://www.w3.org/2001/XMLSchema#date</tt> */ - public static final Types XSD_DATE = new Types( - "http://www.w3.org/2001/XMLSchema#date"); - - /** <tt>http://www.w3.org/2001/XMLSchema#dateTime</tt> */ - public static final Types XSD_DATETIME = new Types( - "http://www.w3.org/2001/XMLSchema#dateTime"); - - /** <tt>http://www.w3.org/2001/XMLSchema#dayTimeDuration</tt> */ - public static final Types XSD_DAYTIMEDURATION = new Types( - "http://www.w3.org/2001/XMLSchema#dayTimeDuration"); - - /** <tt>http://www.w3.org/2001/XMLSchema#decimal</tt> */ - public static final Types XSD_DECIMAL = new Types( - "http://www.w3.org/2001/XMLSchema#decimal"); - - /** <tt>http://www.w3.org/2001/XMLSchema#double</tt> */ - public static final Types XSD_DOUBLE = new Types( - "http://www.w3.org/2001/XMLSchema#double"); - - /** <tt>http://www.w3.org/2001/XMLSchema#duration</tt> */ - public static final Types XSD_DURATION = new Types( - "http://www.w3.org/2001/XMLSchema#duration"); - - /** <tt>http://www.w3.org/2001/XMLSchema#float</tt> */ - public static final Types XSD_FLOAT = new Types( - "http://www.w3.org/2001/XMLSchema#float"); - - /** <tt>http://www.w3.org/2001/XMLSchema#gDay</tt> */ - public static final Types XSD_GDAY = new Types( - "http://www.w3.org/2001/XMLSchema#gDay"); - - /** <tt>http://www.w3.org/2001/XMLSchema#gMonth</tt> */ - public static final Types XSD_GMONTH = new Types( - "http://www.w3.org/2001/XMLSchema#gMonth"); - - /** <tt>http://www.w3.org/2001/XMLSchema#gMonthDay</tt> */ - public static final Types XSD_GMONTHDAY = new Types( - "http://www.w3.org/2001/XMLSchema#gMonthDay"); - - /** <tt>http://www.w3.org/2001/XMLSchema#gYear</tt> */ - public static final Types XSD_GYEAR = new Types( - "http://www.w3.org/2001/XMLSchema#gYear"); - - /** <tt>http://www.w3.org/2001/XMLSchema#gYearMonth</tt> */ - public static final Types XSD_GYEARMONTH = new Types( - "http://www.w3.org/2001/XMLSchema#gYearMonth"); - - /** <tt>http://www.w3.org/2001/XMLSchema#hexBinary</tt> */ - public static final Types XSD_HEXBINARY = new Types( - "http://www.w3.org/2001/XMLSchema#hexBinary"); - - /** <tt>http://www.w3.org/2001/XMLSchema#int</tt> */ - public static final Types XSD_INT = new Types( - "http://www.w3.org/2001/XMLSchema#int"); - - /** <tt>http://www.w3.org/2001/XMLSchema#integer</tt> */ - public static final Types XSD_INTEGER = new Types( - "http://www.w3.org/2001/XMLSchema#integer"); - - /** <tt>http://www.w3.org/2001/XMLSchema#language</tt> */ - public static final Types XSD_LANGUAGE = new Types( - "http://www.w3.org/2001/XMLSchema#language"); - - /** <tt>http://www.w3.org/2001/XMLSchema#long</tt> */ - public static final Types XSD_LONG = new Types( - "http://www.w3.org/2001/XMLSchema#long"); - - /** <tt>http://www.w3.org/2001/XMLSchema#Name</tt> */ - public static final Types XSD_NAME = new Types( - "http://www.w3.org/2001/XMLSchema#Name"); - - /** <tt>http://www.w3.org/2001/XMLSchema#NCName</tt> */ - public static final Types XSD_NCNAME = new Types( - "http://www.w3.org/2001/XMLSchema#NCName"); - - /** <tt>http://www.w3.org/2001/XMLSchema#negativeInteger</tt> */ - public static final Types XSD_NEGATIVEINTEGER = new Types( - "http://www.w3.org/2001/XMLSchema#negativeInteger"); - - /** <tt>http://www.w3.org/2001/XMLSchema#NMTOKEN</tt> */ - public static final Types XSD_NMTOKEN = new Types( - "http://www.w3.org/2001/XMLSchema#NMTOKEN"); - - /** <tt>http://www.w3.org/2001/XMLSchema#nonNegativeInteger</tt> */ - public static final Types XSD_NONNEGATIVEINTEGER = new Types( - "http://www.w3.org/2001/XMLSchema#nonNegativeInteger"); - - /** <tt>http://www.w3.org/2001/XMLSchema#nonPositiveInteger</tt> */ - public static final Types XSD_NONPOSITIVEINTEGER = new Types( - "http://www.w3.org/2001/XMLSchema#nonPositiveInteger"); - - /** <tt>http://www.w3.org/2001/XMLSchema#normalizedString</tt> */ - public static final Types XSD_NORMALIZEDSTRING = new Types( - "http://www.w3.org/2001/XMLSchema#normalizedString"); - - /** <tt>http://www.w3.org/2001/XMLSchema#positiveInteger</tt> */ - public static final Types XSD_POSITIVEINTEGER = new Types( - "http://www.w3.org/2001/XMLSchema#positiveInteger"); - - /** <tt>http://www.w3.org/2001/XMLSchema#short</tt> */ - public static final Types XSD_SHORT = new Types( - "http://www.w3.org/2001/XMLSchema#short"); - - /** <tt>http://www.w3.org/2001/XMLSchema#string</tt> */ - public static final Types XSD_STRING = new Types( - "http://www.w3.org/2001/XMLSchema#string"); - - /** <tt>http://www.w3.org/2001/XMLSchema#time</tt> */ - public static final Types XSD_TIME = new Types( - "http://www.w3.org/2001/XMLSchema#time"); - - /** <tt>http://www.w3.org/2001/XMLSchema#token</tt> */ - public static final Types XSD_TOKEN = new Types( - "http://www.w3.org/2001/XMLSchema#token"); - - /** <tt>http://www.w3.org/2001/XMLSchema#unsignedByte</tt> */ - public static final Types XSD_UNSIGNEDBYTE = new Types( - "http://www.w3.org/2001/XMLSchema#unsignedByte"); - - /** <tt>http://www.w3.org/2001/XMLSchema#unsignedInt</tt> */ - public static final Types XSD_UNSIGNEDINT = new Types( - "http://www.w3.org/2001/XMLSchema#unsignedInt"); - - /** <tt>http://www.w3.org/2001/XMLSchema#unsignedLong</tt> */ - public static final Types XSD_UNSIGNEDLONG = new Types( - "http://www.w3.org/2001/XMLSchema#unsignedLong"); - - /** <tt>http://www.w3.org/2001/XMLSchema#unsignedShort</tt> */ - public static final Types XSD_UNSIGNEDSHORT = new Types( - "http://www.w3.org/2001/XMLSchema#unsignedShort"); - - private static final Set<IRI> ALL_TYPES; - - static { - Set<IRI> tempTypes = new LinkedHashSet<>(); - tempTypes.add(RDF_HTML); - tempTypes.add(RDF_LANGSTRING); - tempTypes.add(RDF_PLAINLITERAL); - tempTypes.add(RDF_XMLLITERAL); - tempTypes.add(XSD_ANYURI); - tempTypes.add(XSD_BASE64BINARY); - tempTypes.add(XSD_BOOLEAN); - tempTypes.add(XSD_BYTE); - tempTypes.add(XSD_DATE); - tempTypes.add(XSD_DATETIME); - tempTypes.add(XSD_DAYTIMEDURATION); - tempTypes.add(XSD_DECIMAL); - tempTypes.add(XSD_DOUBLE); - tempTypes.add(XSD_DURATION); - tempTypes.add(XSD_FLOAT); - tempTypes.add(XSD_GDAY); - tempTypes.add(XSD_GMONTH); - tempTypes.add(XSD_GMONTHDAY); - tempTypes.add(XSD_GYEAR); - tempTypes.add(XSD_GYEARMONTH); - tempTypes.add(XSD_HEXBINARY); - tempTypes.add(XSD_INT); - tempTypes.add(XSD_INTEGER); - tempTypes.add(XSD_LANGUAGE); - tempTypes.add(XSD_LONG); - tempTypes.add(XSD_NAME); - tempTypes.add(XSD_NCNAME); - tempTypes.add(XSD_NEGATIVEINTEGER); - tempTypes.add(XSD_NMTOKEN); - tempTypes.add(XSD_NONNEGATIVEINTEGER); - tempTypes.add(XSD_NONPOSITIVEINTEGER); - tempTypes.add(XSD_NORMALIZEDSTRING); - tempTypes.add(XSD_POSITIVEINTEGER); - tempTypes.add(XSD_SHORT); - tempTypes.add(XSD_STRING); - tempTypes.add(XSD_TIME); - tempTypes.add(XSD_TOKEN); - tempTypes.add(XSD_UNSIGNEDBYTE); - tempTypes.add(XSD_UNSIGNEDINT); - tempTypes.add(XSD_UNSIGNEDLONG); - tempTypes.add(XSD_UNSIGNEDSHORT); - ALL_TYPES = Collections.unmodifiableSet(tempTypes); - } - - private final IRI field; - - private Types(String field) { - this.field = new IRIImpl(field); - } - - @Override - public String getIRIString() { - return this.field.getIRIString(); - } - - @Override - public String ntriplesString() { - return this.field.ntriplesString(); - } - - @Override - public boolean equals(Object other) { - return this.field.equals(other); - } - - @Override - public int hashCode() { - return this.field.hashCode(); - } - - @Override - public String toString() { - return this.field.toString(); - } - - /** - * Get an immutable set of the IRIs used by the RDF-1.1 specification to - * define types, from the RDF and XML Schema vocabularies. - * - * @return A {@link Set} containing all of the IRIs in this collection. - */ - public static Set<IRI> values() { - return ALL_TYPES; - } - - /** - * Get the IRI from this collection if it is present, or return - * {@link Optional#empty()} otherwise. - * - * @param nextIRI - * The IRI to look for. - * @return An {@link Optional} containing the IRI from this collection or - * {@link Optional#empty()} if it is not present here. - */ - public static Optional<IRI> get(IRI nextIRI) { - if (ALL_TYPES.contains(nextIRI)) { - // If we know about this IRI, then look through our set to find the - // object that matches and return it - for (IRI nextType : ALL_TYPES) { - if (nextType.equals(nextIRI)) { - return Optional.of(nextType); - } - } - } - return Optional.empty(); - } + /** + * <tt>http://www.w3.org/1999/02/22-rdf-syntax-ns#HTML</tt> + */ + public static final Types RDF_HTML = new Types( + "http://www.w3.org/1999/02/22-rdf-syntax-ns#HTML"); + + /** + * <tt>http://www.w3.org/1999/02/22-rdf-syntax-ns#langString</tt> + */ + public static final Types RDF_LANGSTRING = new Types( + "http://www.w3.org/1999/02/22-rdf-syntax-ns#langString"); + + /** + * <tt>http://www.w3.org/1999/02/22-rdf-syntax-ns#PlainLiteral</tt> + * + * @deprecated Not used in RDF-1.1 + */ + @Deprecated + public static final Types RDF_PLAINLITERAL = new Types( + "http://www.w3.org/1999/02/22-rdf-syntax-ns#PlainLiteral"); + + /** + * <tt>http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral</tt> + */ + public static final Types RDF_XMLLITERAL = new Types( + "http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral"); + + /** + * <tt>http://www.w3.org/2001/XMLSchema#anyURI</tt> + */ + public static final Types XSD_ANYURI = new Types( + "http://www.w3.org/2001/XMLSchema#anyURI"); + + /** + * <tt>http://www.w3.org/2001/XMLSchema#base64Binary</tt> + */ + public static final Types XSD_BASE64BINARY = new Types( + "http://www.w3.org/2001/XMLSchema#base64Binary"); + + /** + * <tt>http://www.w3.org/2001/XMLSchema#boolean</tt> + */ + public static final Types XSD_BOOLEAN = new Types( + "http://www.w3.org/2001/XMLSchema#boolean"); + + /** + * <tt>http://www.w3.org/2001/XMLSchema#byte</tt> + */ + public static final Types XSD_BYTE = new Types( + "http://www.w3.org/2001/XMLSchema#byte"); + + /** + * <tt>http://www.w3.org/2001/XMLSchema#date</tt> + */ + public static final Types XSD_DATE = new Types( + "http://www.w3.org/2001/XMLSchema#date"); + + /** + * <tt>http://www.w3.org/2001/XMLSchema#dateTime</tt> + */ + public static final Types XSD_DATETIME = new Types( + "http://www.w3.org/2001/XMLSchema#dateTime"); + + /** + * <tt>http://www.w3.org/2001/XMLSchema#dayTimeDuration</tt> + */ + public static final Types XSD_DAYTIMEDURATION = new Types( + "http://www.w3.org/2001/XMLSchema#dayTimeDuration"); + + /** + * <tt>http://www.w3.org/2001/XMLSchema#decimal</tt> + */ + public static final Types XSD_DECIMAL = new Types( + "http://www.w3.org/2001/XMLSchema#decimal"); + + /** + * <tt>http://www.w3.org/2001/XMLSchema#double</tt> + */ + public static final Types XSD_DOUBLE = new Types( + "http://www.w3.org/2001/XMLSchema#double"); + + /** + * <tt>http://www.w3.org/2001/XMLSchema#duration</tt> + */ + public static final Types XSD_DURATION = new Types( + "http://www.w3.org/2001/XMLSchema#duration"); + + /** + * <tt>http://www.w3.org/2001/XMLSchema#float</tt> + */ + public static final Types XSD_FLOAT = new Types( + "http://www.w3.org/2001/XMLSchema#float"); + + /** + * <tt>http://www.w3.org/2001/XMLSchema#gDay</tt> + */ + public static final Types XSD_GDAY = new Types( + "http://www.w3.org/2001/XMLSchema#gDay"); + + /** + * <tt>http://www.w3.org/2001/XMLSchema#gMonth</tt> + */ + public static final Types XSD_GMONTH = new Types( + "http://www.w3.org/2001/XMLSchema#gMonth"); + + /** + * <tt>http://www.w3.org/2001/XMLSchema#gMonthDay</tt> + */ + public static final Types XSD_GMONTHDAY = new Types( + "http://www.w3.org/2001/XMLSchema#gMonthDay"); + + /** + * <tt>http://www.w3.org/2001/XMLSchema#gYear</tt> + */ + public static final Types XSD_GYEAR = new Types( + "http://www.w3.org/2001/XMLSchema#gYear"); + + /** + * <tt>http://www.w3.org/2001/XMLSchema#gYearMonth</tt> + */ + public static final Types XSD_GYEARMONTH = new Types( + "http://www.w3.org/2001/XMLSchema#gYearMonth"); + + /** + * <tt>http://www.w3.org/2001/XMLSchema#hexBinary</tt> + */ + public static final Types XSD_HEXBINARY = new Types( + "http://www.w3.org/2001/XMLSchema#hexBinary"); + + /** + * <tt>http://www.w3.org/2001/XMLSchema#int</tt> + */ + public static final Types XSD_INT = new Types( + "http://www.w3.org/2001/XMLSchema#int"); + + /** + * <tt>http://www.w3.org/2001/XMLSchema#integer</tt> + */ + public static final Types XSD_INTEGER = new Types( + "http://www.w3.org/2001/XMLSchema#integer"); + + /** + * <tt>http://www.w3.org/2001/XMLSchema#language</tt> + */ + public static final Types XSD_LANGUAGE = new Types( + "http://www.w3.org/2001/XMLSchema#language"); + + /** + * <tt>http://www.w3.org/2001/XMLSchema#long</tt> + */ + public static final Types XSD_LONG = new Types( + "http://www.w3.org/2001/XMLSchema#long"); + + /** + * <tt>http://www.w3.org/2001/XMLSchema#Name</tt> + */ + public static final Types XSD_NAME = new Types( + "http://www.w3.org/2001/XMLSchema#Name"); + + /** + * <tt>http://www.w3.org/2001/XMLSchema#NCName</tt> + */ + public static final Types XSD_NCNAME = new Types( + "http://www.w3.org/2001/XMLSchema#NCName"); + + /** + * <tt>http://www.w3.org/2001/XMLSchema#negativeInteger</tt> + */ + public static final Types XSD_NEGATIVEINTEGER = new Types( + "http://www.w3.org/2001/XMLSchema#negativeInteger"); + + /** + * <tt>http://www.w3.org/2001/XMLSchema#NMTOKEN</tt> + */ + public static final Types XSD_NMTOKEN = new Types( + "http://www.w3.org/2001/XMLSchema#NMTOKEN"); + + /** + * <tt>http://www.w3.org/2001/XMLSchema#nonNegativeInteger</tt> + */ + public static final Types XSD_NONNEGATIVEINTEGER = new Types( + "http://www.w3.org/2001/XMLSchema#nonNegativeInteger"); + + /** + * <tt>http://www.w3.org/2001/XMLSchema#nonPositiveInteger</tt> + */ + public static final Types XSD_NONPOSITIVEINTEGER = new Types( + "http://www.w3.org/2001/XMLSchema#nonPositiveInteger"); + + /** + * <tt>http://www.w3.org/2001/XMLSchema#normalizedString</tt> + */ + public static final Types XSD_NORMALIZEDSTRING = new Types( + "http://www.w3.org/2001/XMLSchema#normalizedString"); + + /** + * <tt>http://www.w3.org/2001/XMLSchema#positiveInteger</tt> + */ + public static final Types XSD_POSITIVEINTEGER = new Types( + "http://www.w3.org/2001/XMLSchema#positiveInteger"); + + /** + * <tt>http://www.w3.org/2001/XMLSchema#short</tt> + */ + public static final Types XSD_SHORT = new Types( + "http://www.w3.org/2001/XMLSchema#short"); + + /** + * <tt>http://www.w3.org/2001/XMLSchema#string</tt> + */ + public static final Types XSD_STRING = new Types( + "http://www.w3.org/2001/XMLSchema#string"); + + /** + * <tt>http://www.w3.org/2001/XMLSchema#time</tt> + */ + public static final Types XSD_TIME = new Types( + "http://www.w3.org/2001/XMLSchema#time"); + + /** + * <tt>http://www.w3.org/2001/XMLSchema#token</tt> + */ + public static final Types XSD_TOKEN = new Types( + "http://www.w3.org/2001/XMLSchema#token"); + + /** + * <tt>http://www.w3.org/2001/XMLSchema#unsignedByte</tt> + */ + public static final Types XSD_UNSIGNEDBYTE = new Types( + "http://www.w3.org/2001/XMLSchema#unsignedByte"); + + /** + * <tt>http://www.w3.org/2001/XMLSchema#unsignedInt</tt> + */ + public static final Types XSD_UNSIGNEDINT = new Types( + "http://www.w3.org/2001/XMLSchema#unsignedInt"); + + /** + * <tt>http://www.w3.org/2001/XMLSchema#unsignedLong</tt> + */ + public static final Types XSD_UNSIGNEDLONG = new Types( + "http://www.w3.org/2001/XMLSchema#unsignedLong"); + + /** + * <tt>http://www.w3.org/2001/XMLSchema#unsignedShort</tt> + */ + public static final Types XSD_UNSIGNEDSHORT = new Types( + "http://www.w3.org/2001/XMLSchema#unsignedShort"); + + private static final Set<IRI> ALL_TYPES; + + static { + Set<IRI> tempTypes = new LinkedHashSet<>(); + tempTypes.add(RDF_HTML); + tempTypes.add(RDF_LANGSTRING); + tempTypes.add(RDF_PLAINLITERAL); + tempTypes.add(RDF_XMLLITERAL); + tempTypes.add(XSD_ANYURI); + tempTypes.add(XSD_BASE64BINARY); + tempTypes.add(XSD_BOOLEAN); + tempTypes.add(XSD_BYTE); + tempTypes.add(XSD_DATE); + tempTypes.add(XSD_DATETIME); + tempTypes.add(XSD_DAYTIMEDURATION); + tempTypes.add(XSD_DECIMAL); + tempTypes.add(XSD_DOUBLE); + tempTypes.add(XSD_DURATION); + tempTypes.add(XSD_FLOAT); + tempTypes.add(XSD_GDAY); + tempTypes.add(XSD_GMONTH); + tempTypes.add(XSD_GMONTHDAY); + tempTypes.add(XSD_GYEAR); + tempTypes.add(XSD_GYEARMONTH); + tempTypes.add(XSD_HEXBINARY); + tempTypes.add(XSD_INT); + tempTypes.add(XSD_INTEGER); + tempTypes.add(XSD_LANGUAGE); + tempTypes.add(XSD_LONG); + tempTypes.add(XSD_NAME); + tempTypes.add(XSD_NCNAME); + tempTypes.add(XSD_NEGATIVEINTEGER); + tempTypes.add(XSD_NMTOKEN); + tempTypes.add(XSD_NONNEGATIVEINTEGER); + tempTypes.add(XSD_NONPOSITIVEINTEGER); + tempTypes.add(XSD_NORMALIZEDSTRING); + tempTypes.add(XSD_POSITIVEINTEGER); + tempTypes.add(XSD_SHORT); + tempTypes.add(XSD_STRING); + tempTypes.add(XSD_TIME); + tempTypes.add(XSD_TOKEN); + tempTypes.add(XSD_UNSIGNEDBYTE); + tempTypes.add(XSD_UNSIGNEDINT); + tempTypes.add(XSD_UNSIGNEDLONG); + tempTypes.add(XSD_UNSIGNEDSHORT); + ALL_TYPES = Collections.unmodifiableSet(tempTypes); + } + + private final IRI field; + + private Types(String field) { + this.field = new IRIImpl(field); + } + + @Override + public String getIRIString() { + return this.field.getIRIString(); + } + + @Override + public String ntriplesString() { + return this.field.ntriplesString(); + } + + @Override + public boolean equals(Object other) { + return this.field.equals(other); + } + + @Override + public int hashCode() { + return this.field.hashCode(); + } + + @Override + public String toString() { + return this.field.toString(); + } + + /** + * Get an immutable set of the IRIs used by the RDF-1.1 specification to + * define types, from the RDF and XML Schema vocabularies. + * + * @return A {@link Set} containing all of the IRIs in this collection. + */ + public static Set<IRI> values() { + return ALL_TYPES; + } + + /** + * Get the IRI from this collection if it is present, or return + * {@link Optional#empty()} otherwise. + * + * @param nextIRI The IRI to look for. + * @return An {@link Optional} containing the IRI from this collection or + * {@link Optional#empty()} if it is not present here. + */ + public static Optional<IRI> get(IRI nextIRI) { + if (ALL_TYPES.contains(nextIRI)) { + // If we know about this IRI, then look through our set to find the + // object that matches and return it + for (IRI nextType : ALL_TYPES) { + if (nextType.equals(nextIRI)) { + return Optional.of(nextType); + } + } + } + return Optional.empty(); + } } http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/5ee4c293/simple/src/main/java/org/apache/commons/rdf/simple/package-info.java ---------------------------------------------------------------------- diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/package-info.java b/simple/src/main/java/org/apache/commons/rdf/simple/package-info.java index a806fe0..67ac732 100644 --- a/simple/src/main/java/org/apache/commons/rdf/simple/package-info.java +++ b/simple/src/main/java/org/apache/commons/rdf/simple/package-info.java @@ -29,7 +29,7 @@ * To use this implementation, create an instance of {@link SimpleRDFTermFactory} * and use methods like {@link SimpleRDFTermFactory#createGraph} and * {@link SimpleRDFTermFactory#createIRI(String)}. - * + * */ package org.apache.commons.rdf.simple; http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/5ee4c293/simple/src/test/java/org/apache/commons/rdf/simple/BlankNodeImplTest.java ---------------------------------------------------------------------- diff --git a/simple/src/test/java/org/apache/commons/rdf/simple/BlankNodeImplTest.java b/simple/src/test/java/org/apache/commons/rdf/simple/BlankNodeImplTest.java index 1c9c2a2..aa4c868 100644 --- a/simple/src/test/java/org/apache/commons/rdf/simple/BlankNodeImplTest.java +++ b/simple/src/test/java/org/apache/commons/rdf/simple/BlankNodeImplTest.java @@ -17,25 +17,24 @@ */ package org.apache.commons.rdf.simple; -import java.util.Optional; - import org.apache.commons.rdf.api.AbstractBlankNodeTest; import org.apache.commons.rdf.api.BlankNode; +import java.util.Optional; + /** * Concrete implementation of BlankNodeImpl test. - * */ public class BlankNodeImplTest extends AbstractBlankNodeTest { - @Override - protected BlankNode getBlankNode() { - return new BlankNodeImpl(); - } + @Override + protected BlankNode getBlankNode() { + return new BlankNodeImpl(); + } - @Override - protected BlankNode getBlankNode(String identifier) { - return new BlankNodeImpl(Optional.empty(), identifier); - } + @Override + protected BlankNode getBlankNode(String identifier) { + return new BlankNodeImpl(Optional.empty(), identifier); + } } http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/5ee4c293/simple/src/test/java/org/apache/commons/rdf/simple/DefaultGraphTest.java ---------------------------------------------------------------------- diff --git a/simple/src/test/java/org/apache/commons/rdf/simple/DefaultGraphTest.java b/simple/src/test/java/org/apache/commons/rdf/simple/DefaultGraphTest.java index 5cfcda6..57fec35 100644 --- a/simple/src/test/java/org/apache/commons/rdf/simple/DefaultGraphTest.java +++ b/simple/src/test/java/org/apache/commons/rdf/simple/DefaultGraphTest.java @@ -25,28 +25,27 @@ import org.apache.commons.rdf.api.RDFTermFactory; /** * Ensure AbstractGraphTest does not crash if the RDFTermFactory throws * UnsupportedOperationException - * */ public class DefaultGraphTest extends AbstractGraphTest { - @Override - public RDFTermFactory createFactory() { - // The most minimal RDFTermFactory that would still - // make sense with a Graph - return new RDFTermFactory() { - @Override - public Graph createGraph() throws UnsupportedOperationException { - return new GraphImpl(new SimpleRDFTermFactory()); - } + @Override + public RDFTermFactory createFactory() { + // The most minimal RDFTermFactory that would still + // make sense with a Graph + return new RDFTermFactory() { + @Override + public Graph createGraph() throws UnsupportedOperationException { + return new GraphImpl(new SimpleRDFTermFactory()); + } - @Override - public IRI createIRI(String iri) - throws UnsupportedOperationException, - IllegalArgumentException { - return new IRIImpl(iri); - } - }; - } + @Override + public IRI createIRI(String iri) + throws UnsupportedOperationException, + IllegalArgumentException { + return new IRIImpl(iri); + } + }; + } } http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/5ee4c293/simple/src/test/java/org/apache/commons/rdf/simple/SimpleGraphTest.java ---------------------------------------------------------------------- diff --git a/simple/src/test/java/org/apache/commons/rdf/simple/SimpleGraphTest.java b/simple/src/test/java/org/apache/commons/rdf/simple/SimpleGraphTest.java index 350a307..0951942 100644 --- a/simple/src/test/java/org/apache/commons/rdf/simple/SimpleGraphTest.java +++ b/simple/src/test/java/org/apache/commons/rdf/simple/SimpleGraphTest.java @@ -22,13 +22,12 @@ import org.apache.commons.rdf.api.RDFTermFactory; /** * Test SimpleRDFTermFactory with AbstractGraphTest - * */ public class SimpleGraphTest extends AbstractGraphTest { - @Override - public RDFTermFactory createFactory() { - return new SimpleRDFTermFactory(); - } + @Override + public RDFTermFactory createFactory() { + return new SimpleRDFTermFactory(); + } } http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/5ee4c293/simple/src/test/java/org/apache/commons/rdf/simple/SimpleNoRelativeIRIRDFTermFactoryTest.java ---------------------------------------------------------------------- diff --git a/simple/src/test/java/org/apache/commons/rdf/simple/SimpleNoRelativeIRIRDFTermFactoryTest.java b/simple/src/test/java/org/apache/commons/rdf/simple/SimpleNoRelativeIRIRDFTermFactoryTest.java index 6426f1c..2431ecf 100644 --- a/simple/src/test/java/org/apache/commons/rdf/simple/SimpleNoRelativeIRIRDFTermFactoryTest.java +++ b/simple/src/test/java/org/apache/commons/rdf/simple/SimpleNoRelativeIRIRDFTermFactoryTest.java @@ -17,32 +17,31 @@ */ package org.apache.commons.rdf.simple; -import java.net.URI; - import org.apache.commons.rdf.api.AbstractRDFTermFactoryTest; import org.apache.commons.rdf.api.IRI; import org.apache.commons.rdf.api.RDFTermFactory; +import java.net.URI; + /** * Test simple IRI without relative IRI support. * <p?> * Ensures that {@link AbstractRDFTermFactoryTest#createIRIRelative()} is * correctly skipped (without causing an error. - * */ public class SimpleNoRelativeIRIRDFTermFactoryTest extends - AbstractRDFTermFactoryTest { - @Override - public RDFTermFactory createFactory() { - return new SimpleRDFTermFactory() { - @Override - public IRI createIRI(String iri) { - if (!URI.create(iri).isAbsolute()) { - throw new IllegalArgumentException("IRIs must be absolute"); - // ..in this subclass for testing purposes only :) - } - return super.createIRI(iri); - } - }; - } + AbstractRDFTermFactoryTest { + @Override + public RDFTermFactory createFactory() { + return new SimpleRDFTermFactory() { + @Override + public IRI createIRI(String iri) { + if (!URI.create(iri).isAbsolute()) { + throw new IllegalArgumentException("IRIs must be absolute"); + // ..in this subclass for testing purposes only :) + } + return super.createIRI(iri); + } + }; + } } http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/5ee4c293/simple/src/test/java/org/apache/commons/rdf/simple/SimpleRDFTermFactoryTest.java ---------------------------------------------------------------------- diff --git a/simple/src/test/java/org/apache/commons/rdf/simple/SimpleRDFTermFactoryTest.java b/simple/src/test/java/org/apache/commons/rdf/simple/SimpleRDFTermFactoryTest.java index fbc368f..9ef2a35 100644 --- a/simple/src/test/java/org/apache/commons/rdf/simple/SimpleRDFTermFactoryTest.java +++ b/simple/src/test/java/org/apache/commons/rdf/simple/SimpleRDFTermFactoryTest.java @@ -22,13 +22,12 @@ import org.apache.commons.rdf.api.RDFTermFactory; /** * Simple RDFTermFactory Test - * */ public class SimpleRDFTermFactoryTest extends AbstractRDFTermFactoryTest { - @Override - public RDFTermFactory createFactory() { - return new SimpleRDFTermFactory(); - } + @Override + public RDFTermFactory createFactory() { + return new SimpleRDFTermFactory(); + } } http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/5ee4c293/simple/src/test/java/org/apache/commons/rdf/simple/TestWritingGraph.java ---------------------------------------------------------------------- diff --git a/simple/src/test/java/org/apache/commons/rdf/simple/TestWritingGraph.java b/simple/src/test/java/org/apache/commons/rdf/simple/TestWritingGraph.java index 9b7a925..7c09d62 100644 --- a/simple/src/test/java/org/apache/commons/rdf/simple/TestWritingGraph.java +++ b/simple/src/test/java/org/apache/commons/rdf/simple/TestWritingGraph.java @@ -17,7 +17,12 @@ */ package org.apache.commons.rdf.simple; -import static org.junit.Assert.*; +import org.apache.commons.rdf.api.Graph; +import org.apache.commons.rdf.api.IRI; +import org.apache.commons.rdf.api.RDFTermFactory; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; import java.nio.charset.Charset; import java.nio.file.Files; @@ -27,129 +32,125 @@ import java.util.Collections; import java.util.List; import java.util.stream.Stream; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; -import org.apache.commons.rdf.api.Graph; -import org.apache.commons.rdf.api.IRI; -import org.apache.commons.rdf.api.RDFTermFactory; +import static org.junit.Assert.assertEquals; /** * Test writting graph - * */ public class TestWritingGraph { - /* - * 200k triples should do - about 7 MB on disk. Override with - * -Dtriples=20000000 to exercise your memory banks. - */ - private static final long TRIPLES = Long.getLong("triples", 200000L); - - /** Run tests with -Dkeepfiles=true to inspect /tmp files **/ - private static boolean KEEP_FILES = Boolean.getBoolean("keepfiles"); - - private static Graph graph; - - private static RDFTermFactory factory; - - @BeforeClass - public static void createGraph() throws Exception { - factory = new SimpleRDFTermFactory(); - graph = factory.createGraph(); - IRI subject = factory.createIRI("subj"); - IRI predicate = factory.createIRI("pred"); - List<IRI> types = new ArrayList<>(Types.values()); - // Ensure we don't try to create a literal with rdf:langString but - // without a language tag - types.remove(Types.RDF_LANGSTRING); - Collections.shuffle(types); - for (int i = 0; i < TRIPLES; i++) { - if (i % 11 == 0) { - graph.add(subject, predicate, - factory.createBlankNode("Example " + i)); - } else if (i % 5 == 0) { - graph.add(subject, predicate, - factory.createLiteral("Example " + i, "en")); - } else if (i % 3 == 0) { - graph.add( - subject, - predicate, - factory.createLiteral("Example " + i, - types.get(i % types.size()))); - } else { - graph.add(subject, predicate, - factory.createLiteral("Example " + i)); - } - } - } - - @AfterClass - public static void tearDownClass() throws Exception { - graph.clear(); - graph = null; - } - - @Test - public void createGraphTiming() throws Exception { - createGraph(); - } - - @Test - public void countQuery() { - IRI subject = factory.createIRI("subj"); - IRI predicate = factory.createIRI("pred"); - long count = graph.getTriples(subject, predicate, null).unordered() - .parallel().count(); - System.out.println("Counted - " + count); - assertEquals(count, TRIPLES); - } - - @Test - public void writeGraphFromStream() throws Exception { - Path graphFile = Files.createTempFile("graph", ".nt"); - if (KEEP_FILES) { - System.out.println("From stream: " + graphFile); - } else { - graphFile.toFile().deleteOnExit(); - } - - Stream<CharSequence> stream = graph.getTriples().map(Object::toString); - Files.write(graphFile, stream::iterator, Charset.forName("UTF-8")); - } - - @Test - public void writeGraphFromStreamFiltered() throws Exception { - Path graphFile = Files.createTempFile("graph", ".nt"); - if (KEEP_FILES) { - System.out.println("Filtered stream: " + graphFile); - } else { - graphFile.toFile().deleteOnExit(); - } - - IRI subject = factory.createIRI("subj"); - IRI predicate = factory.createIRI("pred"); - Stream<CharSequence> stream = graph - .getTriples(subject, predicate, null).map(Object::toString); - Files.write(graphFile, stream::iterator, Charset.forName("UTF-8")); - - } - - @Test - public void writeGraphFromStreamFilteredNoMatches() throws Exception { - Path graphFile = Files.createTempFile("graph-empty-", ".nt"); - if (KEEP_FILES) { - System.out.println("Filtered stream: " + graphFile); - } else { - graphFile.toFile().deleteOnExit(); - } - - IRI subject = factory.createIRI("nonexistent"); - IRI predicate = factory.createIRI("pred"); - Stream<CharSequence> stream = graph - .getTriples(subject, predicate, null).map(Object::toString); - Files.write(graphFile, stream::iterator, Charset.forName("UTF-8")); - - } + /* + * 200k triples should do - about 7 MB on disk. Override with + * -Dtriples=20000000 to exercise your memory banks. + */ + private static final long TRIPLES = Long.getLong("triples", 200000L); + + /** + * Run tests with -Dkeepfiles=true to inspect /tmp files * + */ + private static boolean KEEP_FILES = Boolean.getBoolean("keepfiles"); + + private static Graph graph; + + private static RDFTermFactory factory; + + @BeforeClass + public static void createGraph() throws Exception { + factory = new SimpleRDFTermFactory(); + graph = factory.createGraph(); + IRI subject = factory.createIRI("subj"); + IRI predicate = factory.createIRI("pred"); + List<IRI> types = new ArrayList<>(Types.values()); + // Ensure we don't try to create a literal with rdf:langString but + // without a language tag + types.remove(Types.RDF_LANGSTRING); + Collections.shuffle(types); + for (int i = 0; i < TRIPLES; i++) { + if (i % 11 == 0) { + graph.add(subject, predicate, + factory.createBlankNode("Example " + i)); + } else if (i % 5 == 0) { + graph.add(subject, predicate, + factory.createLiteral("Example " + i, "en")); + } else if (i % 3 == 0) { + graph.add( + subject, + predicate, + factory.createLiteral("Example " + i, + types.get(i % types.size()))); + } else { + graph.add(subject, predicate, + factory.createLiteral("Example " + i)); + } + } + } + + @AfterClass + public static void tearDownClass() throws Exception { + graph.clear(); + graph = null; + } + + @Test + public void createGraphTiming() throws Exception { + createGraph(); + } + + @Test + public void countQuery() { + IRI subject = factory.createIRI("subj"); + IRI predicate = factory.createIRI("pred"); + long count = graph.getTriples(subject, predicate, null).unordered() + .parallel().count(); + System.out.println("Counted - " + count); + assertEquals(count, TRIPLES); + } + + @Test + public void writeGraphFromStream() throws Exception { + Path graphFile = Files.createTempFile("graph", ".nt"); + if (KEEP_FILES) { + System.out.println("From stream: " + graphFile); + } else { + graphFile.toFile().deleteOnExit(); + } + + Stream<CharSequence> stream = graph.getTriples().map(Object::toString); + Files.write(graphFile, stream::iterator, Charset.forName("UTF-8")); + } + + @Test + public void writeGraphFromStreamFiltered() throws Exception { + Path graphFile = Files.createTempFile("graph", ".nt"); + if (KEEP_FILES) { + System.out.println("Filtered stream: " + graphFile); + } else { + graphFile.toFile().deleteOnExit(); + } + + IRI subject = factory.createIRI("subj"); + IRI predicate = factory.createIRI("pred"); + Stream<CharSequence> stream = graph + .getTriples(subject, predicate, null).map(Object::toString); + Files.write(graphFile, stream::iterator, Charset.forName("UTF-8")); + + } + + @Test + public void writeGraphFromStreamFilteredNoMatches() throws Exception { + Path graphFile = Files.createTempFile("graph-empty-", ".nt"); + if (KEEP_FILES) { + System.out.println("Filtered stream: " + graphFile); + } else { + graphFile.toFile().deleteOnExit(); + } + + IRI subject = factory.createIRI("nonexistent"); + IRI predicate = factory.createIRI("pred"); + Stream<CharSequence> stream = graph + .getTriples(subject, predicate, null).map(Object::toString); + Files.write(graphFile, stream::iterator, Charset.forName("UTF-8")); + + } } http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/5ee4c293/simple/src/test/java/org/apache/commons/rdf/simple/TypesTest.java ---------------------------------------------------------------------- diff --git a/simple/src/test/java/org/apache/commons/rdf/simple/TypesTest.java b/simple/src/test/java/org/apache/commons/rdf/simple/TypesTest.java index 65e1f52..02c841d 100644 --- a/simple/src/test/java/org/apache/commons/rdf/simple/TypesTest.java +++ b/simple/src/test/java/org/apache/commons/rdf/simple/TypesTest.java @@ -17,54 +17,53 @@ */ package org.apache.commons.rdf.simple; -import static org.junit.Assert.*; - import org.junit.Test; +import static org.junit.Assert.*; + /** * Tests for the {@link Types} enumeration. - * */ public class TypesTest { - /** - * Test method for {@link Types#getIRIString()} - * . - */ - @Test - public final void testGetIRIString() { - assertEquals("http://www.w3.org/1999/02/22-rdf-syntax-ns#langString", - Types.RDF_LANGSTRING.getIRIString()); - } + /** + * Test method for {@link Types#getIRIString()} + * . + */ + @Test + public final void testGetIRIString() { + assertEquals("http://www.w3.org/1999/02/22-rdf-syntax-ns#langString", + Types.RDF_LANGSTRING.getIRIString()); + } - /** - * Test method for - * {@link Types#ntriplesString()}. - */ - @Test - public final void testNtriplesString() { - assertEquals("<http://www.w3.org/1999/02/22-rdf-syntax-ns#langString>", - Types.RDF_LANGSTRING.ntriplesString()); - } + /** + * Test method for + * {@link Types#ntriplesString()}. + */ + @Test + public final void testNtriplesString() { + assertEquals("<http://www.w3.org/1999/02/22-rdf-syntax-ns#langString>", + Types.RDF_LANGSTRING.ntriplesString()); + } - /** - * Test method for - * {@link Types#get(org.apache.commons.rdf.api.IRI)} - * . - */ - @Test - public final void testGet() { - assertTrue(Types.get( - new IRIImpl("http://www.w3.org/2001/XMLSchema#boolean")) - .isPresent()); - assertEquals( - "http://www.w3.org/2001/XMLSchema#boolean", - Types.get( - new IRIImpl("http://www.w3.org/2001/XMLSchema#boolean")) - .get().getIRIString()); - assertFalse(Types.get( - new IRIImpl("http://www.w3.org/2001/XMLSchema#nonExistent")) - .isPresent()); - } + /** + * Test method for + * {@link Types#get(org.apache.commons.rdf.api.IRI)} + * . + */ + @Test + public final void testGet() { + assertTrue(Types.get( + new IRIImpl("http://www.w3.org/2001/XMLSchema#boolean")) + .isPresent()); + assertEquals( + "http://www.w3.org/2001/XMLSchema#boolean", + Types.get( + new IRIImpl("http://www.w3.org/2001/XMLSchema#boolean")) + .get().getIRIString()); + assertFalse(Types.get( + new IRIImpl("http://www.w3.org/2001/XMLSchema#nonExistent")) + .isPresent()); + } }