]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.api.acr/src/org/argeo/api/acr/AttributeFormatter.java
Introduce system roles
[lgpl/argeo-commons.git] / org.argeo.api.acr / src / org / argeo / api / acr / AttributeFormatter.java
1 package org.argeo.api.acr;
2
3 /**
4 * An attribute type MUST consistently parse a string to an object so that
5 * <code>parse(obj.toString()).equals(obj)</code> is verified.
6 * {@link #format(Object)} can be overridden to provide more efficient
7 * implementations but the returned
8 * <code>String<code> MUST be the same, that is <code>format(obj).equals(obj.toString())</code>
9 * is verified.
10 */
11 public interface AttributeFormatter<T> {
12 /** Parses a String to a Java object. */
13 T parse(String str) throws IllegalArgumentException;
14
15 /** Default implementation returns {@link Object#toString()} on the argument. */
16 default String format(T obj) {
17 return obj.toString();
18 }
19 }