/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package reportgen.math.agregate.simpleformat;
import reportgen.prototype.context.ContextMode;
import reportgen.math.agregate.agregate.Aggregate;
import reportgen.math.agregate.agregate.AggregateFunction;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import reportgen.utils.ReportException;
/**
*
* @author axe
*/
public abstract class SimpleFormatColMode extends AggregateFunction {
private static HashMap<String, SimpleFormatColMode> mapex = new HashMap<String, SimpleFormatColMode>();
public static SimpleFormatColMode HIDE = new SimpleFormatHide();
public static SimpleFormatColMode GROUP1 = new SimpleFormatGroupBy1();
public static SimpleFormatColMode GROUP2 = new SimpleFormatGroupBy2();
public static SimpleFormatColMode GROUP3 = new SimpleFormatGroupBy3();
protected SimpleFormatColMode(String title, String description) {
super(title, description);
mapex.put(title, this);
}
@Override
protected boolean isAvailiable(ContextMode mode) {
return false;
}
@Override
public Aggregate getCalculator() {
return null;
}
@Override
public Class getResultClass(Class cls) throws ReportException {
return cls;
}
@Override
public boolean isApplicableTo(Class argument) {
return true;
}
static public Collection<AggregateFunction> getModeList(Class cls) {
Set<AggregateFunction> res = new HashSet<AggregateFunction>();
res.add(ASIS);
res.add(HIDE);
res.add(GROUP1);
res.add(GROUP2);
res.add(GROUP3);
res.add(COUNT);
res.add(COUNT_DISTINCT);
if(cls.equals(Long.class) || cls.equals(Double.class)) {
res.add(SUM);
res.add(AVG);
res.add(MIN);
res.add(MAX);
}
return res;
}
/**
* TODO функция ГРУППА не используется в форматировании, однако может быть десериализована
* @param value
* @return
* @throws ReportException
*/
public static AggregateFunction fromName(String value) throws ReportException {
AggregateFunction func = mnemonics.get(value);
if (func == null) {
throw new ReportException("Неизвестный тип агрегатной функции: " + value);
}
return func;
}
}