You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commonsrdf.apache.org by an...@apache.org on 2015/03/28 06:02:24 UTC
[1/4] incubator-commonsrdf git commit: Add note about not storing
language tag field as an Optional if an implementation requires Serialzable
objects
Repository: incubator-commonsrdf
Updated Branches:
refs/heads/master b773bbff6 -> be1420cfe
Add note about not storing language tag field as an Optional if an
implementation requires Serialzable objects
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/98df1c01
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/98df1c01
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/98df1c01
Branch: refs/heads/master
Commit: 98df1c018aa306214a8a954a7aedd14fcab850ef
Parents: b773bbf
Author: Peter Ansell <p_...@yahoo.com>
Authored: Sat Mar 28 15:29:25 2015 +1100
Committer: Peter Ansell <p_...@yahoo.com>
Committed: Sat Mar 28 15:33:48 2015 +1100
----------------------------------------------------------------------
.../java/org/apache/commons/rdf/api/Literal.java | 8 +++++++-
.../apache/commons/rdf/simple/LiteralImpl.java | 18 +++++++++++-------
2 files changed, 18 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/98df1c01/api/src/main/java/org/apache/commons/rdf/api/Literal.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/Literal.java b/api/src/main/java/org/apache/commons/rdf/api/Literal.java
index d4caa63..3890404 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/Literal.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/Literal.java
@@ -17,6 +17,7 @@
*/
package org.apache.commons.rdf.api;
+import java.io.Serializable;
import java.util.Optional;
/**
@@ -59,7 +60,12 @@ public interface Literal extends RDFTerm {
* href="http://www.w3.org/1999/02/22-rdf-syntax-ns#langString"
* >http://www.w3.org/1999/02/22-rdf-syntax-ns#langString</a>, this method
* must return {@link Optional#empty()}.
- *
+ * <p>
+ * Implementor note: If your application requires {@link Serializable}
+ * objects, it is best not to store an {@link Optional} in a field. It is
+ * recommended to use {@link Optional#ofNullable(Object)} to create the
+ * return value for this method.
+ *
* @return The {@link Optional} language tag for this literal. If
* {@link Optional#isPresent()} returns true, the value returned by
* {@link Optional#get()} must be a non-empty string conforming to
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/98df1c01/simple/src/main/java/org/apache/commons/rdf/simple/LiteralImpl.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/LiteralImpl.java b/simple/src/main/java/org/apache/commons/rdf/simple/LiteralImpl.java
index 521353d..b26cf6b 100644
--- a/simple/src/main/java/org/apache/commons/rdf/simple/LiteralImpl.java
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/LiteralImpl.java
@@ -33,9 +33,9 @@ class LiteralImpl implements Literal {
private static final String QUOTE = "\"";
- private IRI dataType;
- private Optional<String> languageTag;
- private String lexicalForm;
+ private final IRI dataType;
+ private final String languageTag;
+ private final String lexicalForm;
public LiteralImpl(String literal) {
this(literal, Types.XSD_STRING);
@@ -45,12 +45,13 @@ class LiteralImpl implements Literal {
this.lexicalForm = Objects.requireNonNull(lexicalForm);
this.dataType = Types.get(Objects.requireNonNull(dataType)).orElse(
dataType);
- this.languageTag = Optional.empty();
+ this.languageTag = null;
}
public LiteralImpl(String literal, String languageTag) {
this.lexicalForm = Objects.requireNonNull(literal);
- this.languageTag = Optional.of(languageTag.toLowerCase(Locale.ENGLISH));
+ this.languageTag = Objects.requireNonNull(languageTag).toLowerCase(
+ Locale.ENGLISH);
if (languageTag.isEmpty()) {
// TODO: Check against
// http://www.w3.org/TR/n-triples/#n-triples-grammar
@@ -74,7 +75,7 @@ class LiteralImpl implements Literal {
@Override
public Optional<String> getLanguageTag() {
- return languageTag;
+ return Optional.ofNullable(languageTag);
}
@Override
@@ -117,7 +118,10 @@ class LiteralImpl implements Literal {
@Override
public boolean equals(Object obj) {
- if (!(obj instanceof Literal)) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null || !(obj instanceof Literal)) {
return false;
}
Literal literal = (Literal) obj;
[2/4] incubator-commonsrdf git commit: Change fields to private and
final per the classes being package private
Posted by an...@apache.org.
Change fields to private and final per the classes being package private
There is no reason to allow for extensibility with package private
classes, so locking them down to prevent accidental situations where
this is possible
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/2b72b84b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/2b72b84b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/2b72b84b
Branch: refs/heads/master
Commit: 2b72b84b1687d3dff80f0049b3d89cd7e251fb9a
Parents: 98df1c0
Author: Peter Ansell <p_...@yahoo.com>
Authored: Sat Mar 28 15:53:38 2015 +1100
Committer: Peter Ansell <p_...@yahoo.com>
Committed: Sat Mar 28 15:54:25 2015 +1100
----------------------------------------------------------------------
.../java/org/apache/commons/rdf/simple/GraphImpl.java | 4 ++--
.../java/org/apache/commons/rdf/simple/IRIImpl.java | 14 +++++++++-----
.../org/apache/commons/rdf/simple/LiteralImpl.java | 2 +-
.../org/apache/commons/rdf/simple/TripleImpl.java | 8 ++++----
4 files changed, 16 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/2b72b84b/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java b/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java
index bcbc825..30ab15e 100644
--- a/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java
@@ -38,10 +38,10 @@ import org.apache.commons.rdf.api.Triple;
* <p>
* All Stream operations are performed using parallel and unordered directives.
*/
-class GraphImpl implements Graph {
+final class GraphImpl implements Graph {
private static final int TO_STRING_MAX = 10;
- protected final Set<Triple> triples = new LinkedHashSet<Triple>();
+ private final Set<Triple> triples = new LinkedHashSet<Triple>();
@Override
public void add(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/2b72b84b/simple/src/main/java/org/apache/commons/rdf/simple/IRIImpl.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/IRIImpl.java b/simple/src/main/java/org/apache/commons/rdf/simple/IRIImpl.java
index 02d80d1..a735737 100644
--- a/simple/src/main/java/org/apache/commons/rdf/simple/IRIImpl.java
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/IRIImpl.java
@@ -21,18 +21,19 @@ import java.net.URI;
import org.apache.commons.rdf.api.IRI;
-/**
+/**
* A simple implementation of IRI.
*
*/
-class IRIImpl implements IRI {
+final class IRIImpl implements IRI {
- protected String iri;
+ private final String iri;
public IRIImpl(String iri) {
// should throw IllegalArgumentException on most illegal IRIs
URI.create(iri);
- // NOTE: We don't keep the URI as it uses outdated RFC2396 and will get some IDNs wrong
+ // NOTE: We don't keep the URI as it uses outdated RFC2396 and will get
+ // some IDNs wrong
this.iri = iri;
}
@@ -53,7 +54,10 @@ class IRIImpl implements IRI {
@Override
public boolean equals(Object obj) {
- if (!(obj instanceof IRI)) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null || !(obj instanceof IRI)) {
return false;
}
IRI other = (IRI) obj;
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/2b72b84b/simple/src/main/java/org/apache/commons/rdf/simple/LiteralImpl.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/LiteralImpl.java b/simple/src/main/java/org/apache/commons/rdf/simple/LiteralImpl.java
index b26cf6b..13c65ef 100644
--- a/simple/src/main/java/org/apache/commons/rdf/simple/LiteralImpl.java
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/LiteralImpl.java
@@ -29,7 +29,7 @@ import org.apache.commons.rdf.api.Literal;
* A simple implementation of Literal.
*
*/
-class LiteralImpl implements Literal {
+final class LiteralImpl implements Literal {
private static final String QUOTE = "\"";
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/2b72b84b/simple/src/main/java/org/apache/commons/rdf/simple/TripleImpl.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/TripleImpl.java b/simple/src/main/java/org/apache/commons/rdf/simple/TripleImpl.java
index fb6904d..6c9c825 100644
--- a/simple/src/main/java/org/apache/commons/rdf/simple/TripleImpl.java
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/TripleImpl.java
@@ -32,11 +32,11 @@ import org.apache.commons.rdf.api.Triple;
* A simple implementation of Triple.
*
*/
-class TripleImpl implements Triple {
+final class TripleImpl implements Triple {
- private BlankNodeOrIRI subject;
- private IRI predicate;
- private RDFTerm object;
+ private final BlankNodeOrIRI subject;
+ private final IRI predicate;
+ private final RDFTerm object;
/**
* Construct Triple from its constituent parts.
[4/4] incubator-commonsrdf git commit: Convert Types from enum to a
static class so we can override hashCode and equals
Posted by an...@apache.org.
Convert Types from enum to a static class so we can override hashCode
and equals
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/be1420cf
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/be1420cf
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/be1420cf
Branch: refs/heads/master
Commit: be1420cfe1173bf1c98fdc46a9f248d2f4c3b738
Parents: 6ba4c76
Author: Peter Ansell <p_...@yahoo.com>
Authored: Sat Mar 28 16:00:22 2015 +1100
Committer: Peter Ansell <p_...@yahoo.com>
Committed: Sat Mar 28 16:00:22 2015 +1100
----------------------------------------------------------------------
.../org/apache/commons/rdf/simple/Types.java | 210 ++++++++++++++-----
1 file changed, 159 insertions(+), 51 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/be1420cf/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 83f2e68..800174b 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,7 +17,10 @@
*/
package org.apache.commons.rdf.simple;
+import java.util.Collections;
+import java.util.LinkedHashSet;
import java.util.Optional;
+import java.util.Set;
import org.apache.commons.rdf.api.IRI;
@@ -26,13 +29,15 @@ import org.apache.commons.rdf.api.IRI;
*
* @author Peter Ansell p_ansell@yahoo.com
*/
-public enum Types implements IRI {
+public final class Types implements IRI {
/** <tt>http://www.w3.org/1999/02/22-rdf-syntax-ns#HTML</tt> */
- RDF_HTML("http://www.w3.org/1999/02/22-rdf-syntax-ns#HTML"),
+ 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> */
- RDF_LANGSTRING("http://www.w3.org/1999/02/22-rdf-syntax-ns#langString"),
+ 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>
@@ -40,129 +45,212 @@ public enum Types implements IRI {
* @deprecated Not used in RDF-1.1
*/
@Deprecated
- RDF_PLAINLITERAL("http://www.w3.org/1999/02/22-rdf-syntax-ns#PlainLiteral"),
+ 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> */
- RDF_XMLLITERAL("http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral"),
+ 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> */
- XSD_ANYURI("http://www.w3.org/2001/XMLSchema#anyURI"),
+ public static final Types XSD_ANYURI = new Types(
+ "http://www.w3.org/2001/XMLSchema#anyURI");
/** <tt>http://www.w3.org/2001/XMLSchema#base64Binary</tt> */
- XSD_BASE64BINARY("http://www.w3.org/2001/XMLSchema#base64Binary"),
+ public static final Types XSD_BASE64BINARY = new Types(
+ "http://www.w3.org/2001/XMLSchema#base64Binary");
/** <tt>http://www.w3.org/2001/XMLSchema#boolean</tt> */
- XSD_BOOLEAN("http://www.w3.org/2001/XMLSchema#boolean"),
+ public static final Types XSD_BOOLEAN = new Types(
+ "http://www.w3.org/2001/XMLSchema#boolean");
/** <tt>http://www.w3.org/2001/XMLSchema#byte</tt> */
- XSD_BYTE("http://www.w3.org/2001/XMLSchema#byte"),
+ public static final Types XSD_BYTE = new Types(
+ "http://www.w3.org/2001/XMLSchema#byte");
/** <tt>http://www.w3.org/2001/XMLSchema#date</tt> */
- XSD_DATE("http://www.w3.org/2001/XMLSchema#date"),
+ public static final Types XSD_DATE = new Types(
+ "http://www.w3.org/2001/XMLSchema#date");
/** <tt>http://www.w3.org/2001/XMLSchema#dateTime</tt> */
- XSD_DATETIME("http://www.w3.org/2001/XMLSchema#dateTime"),
+ public static final Types XSD_DATETIME = new Types(
+ "http://www.w3.org/2001/XMLSchema#dateTime");
/** <tt>http://www.w3.org/2001/XMLSchema#dayTimeDuration</tt> */
- XSD_DAYTIMEDURATION("http://www.w3.org/2001/XMLSchema#dayTimeDuration"),
+ public static final Types XSD_DAYTIMEDURATION = new Types(
+ "http://www.w3.org/2001/XMLSchema#dayTimeDuration");
/** <tt>http://www.w3.org/2001/XMLSchema#decimal</tt> */
- XSD_DECIMAL("http://www.w3.org/2001/XMLSchema#decimal"),
+ public static final Types XSD_DECIMAL = new Types(
+ "http://www.w3.org/2001/XMLSchema#decimal");
/** <tt>http://www.w3.org/2001/XMLSchema#double</tt> */
- XSD_DOUBLE("http://www.w3.org/2001/XMLSchema#double"),
+ public static final Types XSD_DOUBLE = new Types(
+ "http://www.w3.org/2001/XMLSchema#double");
/** <tt>http://www.w3.org/2001/XMLSchema#duration</tt> */
- XSD_DURATION("http://www.w3.org/2001/XMLSchema#duration"),
+ public static final Types XSD_DURATION = new Types(
+ "http://www.w3.org/2001/XMLSchema#duration");
/** <tt>http://www.w3.org/2001/XMLSchema#float</tt> */
- XSD_FLOAT("http://www.w3.org/2001/XMLSchema#float"),
+ public static final Types XSD_FLOAT = new Types(
+ "http://www.w3.org/2001/XMLSchema#float");
/** <tt>http://www.w3.org/2001/XMLSchema#gDay</tt> */
- XSD_GDAY("http://www.w3.org/2001/XMLSchema#gDay"),
+ public static final Types XSD_GDAY = new Types(
+ "http://www.w3.org/2001/XMLSchema#gDay");
/** <tt>http://www.w3.org/2001/XMLSchema#gMonth</tt> */
- XSD_GMONTH("http://www.w3.org/2001/XMLSchema#gMonth"),
+ public static final Types XSD_GMONTH = new Types(
+ "http://www.w3.org/2001/XMLSchema#gMonth");
/** <tt>http://www.w3.org/2001/XMLSchema#gMonthDay</tt> */
- XSD_GMONTHDAY("http://www.w3.org/2001/XMLSchema#gMonthDay"),
+ public static final Types XSD_GMONTHDAY = new Types(
+ "http://www.w3.org/2001/XMLSchema#gMonthDay");
/** <tt>http://www.w3.org/2001/XMLSchema#gYear</tt> */
- XSD_GYEAR("http://www.w3.org/2001/XMLSchema#gYear"),
+ public static final Types XSD_GYEAR = new Types(
+ "http://www.w3.org/2001/XMLSchema#gYear");
/** <tt>http://www.w3.org/2001/XMLSchema#gYearMonth</tt> */
- XSD_GYEARMONTH("http://www.w3.org/2001/XMLSchema#gYearMonth"),
+ public static final Types XSD_GYEARMONTH = new Types(
+ "http://www.w3.org/2001/XMLSchema#gYearMonth");
/** <tt>http://www.w3.org/2001/XMLSchema#hexBinary</tt> */
- XSD_HEXBINARY("http://www.w3.org/2001/XMLSchema#hexBinary"),
+ public static final Types XSD_HEXBINARY = new Types(
+ "http://www.w3.org/2001/XMLSchema#hexBinary");
/** <tt>http://www.w3.org/2001/XMLSchema#int</tt> */
- XSD_INT("http://www.w3.org/2001/XMLSchema#int"),
+ public static final Types XSD_INT = new Types(
+ "http://www.w3.org/2001/XMLSchema#int");
/** <tt>http://www.w3.org/2001/XMLSchema#integer</tt> */
- XSD_INTEGER("http://www.w3.org/2001/XMLSchema#integer"),
+ public static final Types XSD_INTEGER = new Types(
+ "http://www.w3.org/2001/XMLSchema#integer");
/** <tt>http://www.w3.org/2001/XMLSchema#language</tt> */
- XSD_LANGUAGE("http://www.w3.org/2001/XMLSchema#language"),
+ public static final Types XSD_LANGUAGE = new Types(
+ "http://www.w3.org/2001/XMLSchema#language");
/** <tt>http://www.w3.org/2001/XMLSchema#long</tt> */
- XSD_LONG("http://www.w3.org/2001/XMLSchema#long"),
+ public static final Types XSD_LONG = new Types(
+ "http://www.w3.org/2001/XMLSchema#long");
/** <tt>http://www.w3.org/2001/XMLSchema#Name</tt> */
- XSD_NAME("http://www.w3.org/2001/XMLSchema#Name"),
+ public static final Types XSD_NAME = new Types(
+ "http://www.w3.org/2001/XMLSchema#Name");
/** <tt>http://www.w3.org/2001/XMLSchema#NCName</tt> */
- XSD_NCNAME("http://www.w3.org/2001/XMLSchema#NCName"),
+ public static final Types XSD_NCNAME = new Types(
+ "http://www.w3.org/2001/XMLSchema#NCName");
/** <tt>http://www.w3.org/2001/XMLSchema#negativeInteger</tt> */
- XSD_NEGATIVEINTEGER("http://www.w3.org/2001/XMLSchema#negativeInteger"),
+ public static final Types XSD_NEGATIVEINTEGER = new Types(
+ "http://www.w3.org/2001/XMLSchema#negativeInteger");
/** <tt>http://www.w3.org/2001/XMLSchema#NMTOKEN</tt> */
- XSD_NMTOKEN("http://www.w3.org/2001/XMLSchema#NMTOKEN"),
+ public static final Types XSD_NMTOKEN = new Types(
+ "http://www.w3.org/2001/XMLSchema#NMTOKEN");
/** <tt>http://www.w3.org/2001/XMLSchema#nonNegativeInteger</tt> */
- XSD_NONNEGATIVEINTEGER(
- "http://www.w3.org/2001/XMLSchema#nonNegativeInteger"),
+ public static final Types XSD_NONNEGATIVEINTEGER = new Types(
+ "http://www.w3.org/2001/XMLSchema#nonNegativeInteger");
/** <tt>http://www.w3.org/2001/XMLSchema#nonPositiveInteger</tt> */
- XSD_NONPOSITIVEINTEGER(
- "http://www.w3.org/2001/XMLSchema#nonPositiveInteger"),
+ public static final Types XSD_NONPOSITIVEINTEGER = new Types(
+ "http://www.w3.org/2001/XMLSchema#nonPositiveInteger");
/** <tt>http://www.w3.org/2001/XMLSchema#normalizedString</tt> */
- XSD_NORMALIZEDSTRING("http://www.w3.org/2001/XMLSchema#normalizedString"),
+ public static final Types XSD_NORMALIZEDSTRING = new Types(
+ "http://www.w3.org/2001/XMLSchema#normalizedString");
/** <tt>http://www.w3.org/2001/XMLSchema#positiveInteger</tt> */
- XSD_POSITIVEINTEGER("http://www.w3.org/2001/XMLSchema#positiveInteger"),
+ public static final Types XSD_POSITIVEINTEGER = new Types(
+ "http://www.w3.org/2001/XMLSchema#positiveInteger");
/** <tt>http://www.w3.org/2001/XMLSchema#short</tt> */
- XSD_SHORT("http://www.w3.org/2001/XMLSchema#short"),
+ public static final Types XSD_SHORT = new Types(
+ "http://www.w3.org/2001/XMLSchema#short");
/** <tt>http://www.w3.org/2001/XMLSchema#string</tt> */
- XSD_STRING("http://www.w3.org/2001/XMLSchema#string"),
+ public static final Types XSD_STRING = new Types(
+ "http://www.w3.org/2001/XMLSchema#string");
/** <tt>http://www.w3.org/2001/XMLSchema#time</tt> */
- XSD_TIME("http://www.w3.org/2001/XMLSchema#time"),
+ public static final Types XSD_TIME = new Types(
+ "http://www.w3.org/2001/XMLSchema#time");
/** <tt>http://www.w3.org/2001/XMLSchema#token</tt> */
- XSD_TOKEN("http://www.w3.org/2001/XMLSchema#token"),
+ public static final Types XSD_TOKEN = new Types(
+ "http://www.w3.org/2001/XMLSchema#token");
/** <tt>http://www.w3.org/2001/XMLSchema#unsignedByte</tt> */
- XSD_UNSIGNEDBYTE("http://www.w3.org/2001/XMLSchema#unsignedByte"),
+ public static final Types XSD_UNSIGNEDBYTE = new Types(
+ "http://www.w3.org/2001/XMLSchema#unsignedByte");
/** <tt>http://www.w3.org/2001/XMLSchema#unsignedInt</tt> */
- XSD_UNSIGNEDINT("http://www.w3.org/2001/XMLSchema#unsignedInt"),
+ public static final Types XSD_UNSIGNEDINT = new Types(
+ "http://www.w3.org/2001/XMLSchema#unsignedInt");
/** <tt>http://www.w3.org/2001/XMLSchema#unsignedLong</tt> */
- XSD_UNSIGNEDLONG("http://www.w3.org/2001/XMLSchema#unsignedLong"),
+ public static final Types XSD_UNSIGNEDLONG = new Types(
+ "http://www.w3.org/2001/XMLSchema#unsignedLong");
/** <tt>http://www.w3.org/2001/XMLSchema#unsignedShort</tt> */
- XSD_UNSIGNEDSHORT("http://www.w3.org/2001/XMLSchema#unsignedShort"),
-
- ;
+ 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;
- Types(String field) {
+ private Types(String field) {
this.field = new IRIImpl(field);
}
@@ -176,18 +264,38 @@ public enum Types implements IRI {
return this.field.ntriplesString();
}
+ @Override
+ public boolean equals(Object other) {
+ return this.field.equals(other);
+ }
+
+ @Override
+ public int hashCode() {
+ return this.field.hashCode();
+ }
+
+ /**
+ * 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 enum if it is present, or return
+ * 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 enum or
+ * @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) {
- for (Types nextType : values()) {
- if (nextType.field.equals(nextIRI)) {
+ for (IRI nextType : values()) {
+ if (nextType.equals(nextIRI)) {
return Optional.of(nextType);
}
}
[3/4] incubator-commonsrdf git commit: Avoid storing Optional objects,
per their lack of serialisability
Posted by an...@apache.org.
Avoid storing Optional objects, per their lack of serialisability
This will enable a smooth change in the future if we decide the simple
module should be serialisable, which is unlikely, but best not to
promote the use of Optional fields per this reason.
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/6ba4c76b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/6ba4c76b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/6ba4c76b
Branch: refs/heads/master
Commit: 6ba4c76b85304f81553a7dc3de71cb6210d2df4b
Parents: 2b72b84
Author: Peter Ansell <p_...@yahoo.com>
Authored: Sat Mar 28 15:55:29 2015 +1100
Committer: Peter Ansell <p_...@yahoo.com>
Committed: Sat Mar 28 15:55:29 2015 +1100
----------------------------------------------------------------------
.../main/java/org/apache/commons/rdf/simple/BlankNodeImpl.java | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/6ba4c76b/simple/src/main/java/org/apache/commons/rdf/simple/BlankNodeImpl.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/BlankNodeImpl.java b/simple/src/main/java/org/apache/commons/rdf/simple/BlankNodeImpl.java
index 46cb32f..398ad37 100644
--- a/simple/src/main/java/org/apache/commons/rdf/simple/BlankNodeImpl.java
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/BlankNodeImpl.java
@@ -30,18 +30,18 @@ import org.apache.commons.rdf.api.Graph;
* A simple implementation of BlankNode.
*
*/
-class BlankNodeImpl implements BlankNode {
+final class BlankNodeImpl implements BlankNode {
private static AtomicLong bnodeCounter = new AtomicLong();
private final String id;
- private final Optional<Graph> localScope;
+ private final Graph localScope;
public BlankNodeImpl() {
this(Optional.empty(), "b:" + bnodeCounter.incrementAndGet());
}
public BlankNodeImpl(Optional<Graph> localScope, String id) {
- this.localScope = Objects.requireNonNull(localScope);
+ this.localScope = Objects.requireNonNull(localScope).orElse(null);
if (Objects.requireNonNull(id).isEmpty()) {
throw new IllegalArgumentException("Invalid blank node id: " + id);
// NOTE: It is valid for the id to not be a valid ntriples bnode id.