com.github.rschmitt.dynamicobject.internal.EdnTranslatorAdapter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dynamic-object Show documentation
Show all versions of dynamic-object Show documentation
Lightweight data modeling for Java, powered by Clojure.
package com.github.rschmitt.dynamicobject.internal;
import java.io.IOException;
import java.io.Writer;
import com.github.rschmitt.dynamicobject.EdnTranslator;
import clojure.lang.AFn;
final class EdnTranslatorAdapter extends AFn {
private final EdnTranslator ednTranslator;
EdnTranslatorAdapter(EdnTranslator ednTranslator) {
this.ednTranslator = ednTranslator;
}
@Override
public Object invoke(Object arg) {
return ednTranslator.read(arg);
}
@Override
@SuppressWarnings("unchecked")
public Object invoke(Object arg1, Object arg2) {
Writer writer = (Writer) arg2;
try {
writer.write(String.format("#%s", ednTranslator.getTag()));
ednTranslator.write((T) arg1, writer);
} catch (IOException ex) {
throw new RuntimeException(ex);
}
return null;
}
public final String getTag() {
return ednTranslator.getTag();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy