All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.rschmitt.dynamicobject.internal.EdnTranslatorAdapter Maven / Gradle / Ivy

There is a newer version: 1.7.3
Show newest version
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