/** * */ package it.univr.di.labeledvalue; import java.lang.reflect.InvocationTargetException; import java.util.logging.Logger; import com.google.common.base.Supplier; /** * Basic factory of LabeledIntMap objects. * A implementation C must provide * * @author posenato * @param implementation class of LabeledIntMap interface. */ public final class LabeledIntMapSupplier implements Supplier { /** * class logger */ @SuppressWarnings("unused") static private Logger LOG = Logger.getLogger("LabeledIntMapSupplier"); /** * */ static final public Class DEFAULT_LABELEDINTMAP_CLASS = LabeledIntTreeMap.class; /** * */ private C generator; /** * */ private Class generatorClass; /** * @param implementationClass */ public LabeledIntMapSupplier(Class implementationClass) { super(); this.generatorClass = implementationClass; try { this.generator = implementationClass.getDeclaredConstructor().newInstance(); } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) { e.printStackTrace(); } } /** * @return a new LabeledIntMap concrete object. */ @Override public C get() { return this.generatorClass.cast(this.generator.newInstance()); } /** * @param lim * @return a new LabeledIntMap concrete object. */ public C get(LabeledIntMap lim) { return this.generatorClass.cast(this.generator.newInstance(lim)); } @Override public String toString() { return this.generatorClass.getSimpleName(); } public Class getReturnedObjectClass() { return this.generatorClass; } }