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:27 UTC
[4/4] incubator-commonsrdf git commit: Convert Types from enum to a
static class so we can override hashCode and equals
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);
}
}