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

org.freshmarker.money.MonetaPluginProvider Maven / Gradle / Ivy

The newest version!
package org.freshmarker.money;

import org.freshmarker.core.buildin.BuiltIn;
import org.freshmarker.core.buildin.BuiltInKey;
import org.freshmarker.core.buildin.BuiltInKeyBuilder;
import org.freshmarker.core.model.TemplateObject;
import org.freshmarker.core.plugin.PluginProvider;
import org.javamoney.moneta.Money;
import org.javamoney.moneta.spi.JDKCurrencyAdapter;

import java.util.Map;
import java.util.function.Function;

public final class MonetaPluginProvider implements PluginProvider {
    @Override
    public void registerMapper(Map, Function> mapper) {
        mapper.put(Money.class, o -> new TemplateMoney((Money) o));
        mapper.put(JDKCurrencyAdapter.class, o -> new TemplateConcurrency((JDKCurrencyAdapter) o));
    }

    @Override
    public void registerBuildIn(Map builtIns) {
        BuiltInKeyBuilder builder = new BuiltInKeyBuilder<>(TemplateMoney.class);
        builtIns.put(builder.of("currency"), (x, y, e) -> new TemplateConcurrency((JDKCurrencyAdapter) ((TemplateMoney) x).getValue().getCurrency()));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy