Start integrating GCR and JCR (not yet working)
[lgpl/argeo-commons.git] / org.argeo.api / src / org / argeo / api / gcr / AttributeFormatter.java
diff --git a/org.argeo.api/src/org/argeo/api/gcr/AttributeFormatter.java b/org.argeo.api/src/org/argeo/api/gcr/AttributeFormatter.java
new file mode 100644 (file)
index 0000000..a628cda
--- /dev/null
@@ -0,0 +1,19 @@
+package org.argeo.api.gcr;
+
+/**
+ * An attribute type MUST consistently parse a string to an object so that
+ * <code>parse(obj.toString()).equals(obj)</code> is verified.
+ * {@link #format(Object)} can be overridden to provide more efficient
+ * implementations but the returned
+ * <code>String<code> MUST be the same, that is <code>format(obj).equals(obj.toString())</code>
+ * is verified.
+ */
+public interface AttributeFormatter<T> {
+       /** Parses a String to a Java object. */
+       T parse(String str) throws IllegalArgumentException;
+
+       /** Default implementation returns {@link Object#toString()} on the argument. */
+       default String format(T obj) {
+               return obj.toString();
+       }
+}