com.thihy.es.analysis.paoding.knife.KnifesModule Maven / Gradle / Ivy
package com.thihy.es.analysis.paoding.knife;
import java.util.Map;
import java.util.Map.Entry;
import org.elasticsearch.common.collect.Maps;
import org.elasticsearch.common.inject.AbstractModule;
import org.elasticsearch.common.inject.multibindings.MapBinder;
public class KnifesModule extends AbstractModule {
private final Map> knifes = Maps.newHashMap();
public KnifesModule() {
knifes.put("number", NumberKnifeFactory.class);
knifes.put("letter", LetterKnifeFactory.class);
knifes.put("cjk", CJKKnifeFactory.class);
}
public void registerKnife(String name, Class knife) {
this.knifes.put(name, knife);
}
@Override
protected void configure() {
MapBinder mapbinder = MapBinder.newMapBinder(binder(), String.class, KnifeFactory.class);
for (Entry> knifeEntry : knifes.entrySet()) {
mapbinder.addBinding(knifeEntry.getKey()).to(knifeEntry.getValue());
}
bind(KnifesService.class);
}
}