
us.bpsm.edn.parser.AbstractInstantHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of edn-java Show documentation
Show all versions of edn-java Show documentation
edn-java is an parser and printer for 'edn' written in Java, for Java and
requiring no external dependencies.
// (c) 2012 B Smith-Mannschott -- Distributed under the Eclipse Public License
package us.bpsm.edn.parser;
import us.bpsm.edn.EdnSyntaxException;
import us.bpsm.edn.Tag;
/**
* This class may be extended to support additional {@code #inst}
* representations.
*
* @see InstantToCalendar
* @see InstantToDate
* @see InstantToTimestamp
* @see ParsedInstant
*/
public abstract class AbstractInstantHandler implements TagHandler {
public final Object transform(Tag tag, Object value) {
if (!(value instanceof String)) {
throw new EdnSyntaxException(tag.toString() + " expects a String.");
}
return transform(InstantUtils.parse((String) value));
}
/**
* This will be called by the Parser when parsing an {@code #inst} value.
* Implement it to return an instance of your chosen instant representation.
*
* @param pi
* The contents fields of string following the {@code #inst} tag
* as a {@link ParsedInstant}.
* @return Some value representing the instant pi. Never null.
*/
protected abstract Object transform(ParsedInstant pi);
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy