package commons.cmd;
import basics.math.BasicStatistics;
import basics.unexpected.Problem;
import commons.application.GLOBAL;
import commons.application.Application;
import commons.application.core.Command;
import commons.math.BasicStatisticsCtx;
public class info extends Command
{

private static final String ARGS = "ARGS: theme, doc";

public void process () throws Problem
{
   String theme = ctx.consume("theme", "");
   String doc = ctx.consume("doc", "");
   // String info = ctx.consume("msg", "");
   String msg = "";
//   if (theme.equalsIgnoreCase("sizes"))
//   {
//      Sized object = null;
//      if (ctx.containsKey(doc))
//         object = (Sized) ctx.getr(doc, (Sized) null);
//      if (object != null)
//         msg = GLOBAL.VAL_PREFIX_INFO + FormatterUtl.formatBytesPadLeft(object.signs(), 1);
//   }
//   else 
      if (theme.equalsIgnoreCase("stats"))
   {
      BasicStatistics stats = BasicStatisticsCtx.instance(doc, ctx);
      msg = GLOBAL.VAL_PREFIX_INFO + doc + ":" + (stats == null ? "No statistics found!" : stats.toString());
   }
   else
   /* any other */{
      Object object = ctx.getr(doc);
      msg = GLOBAL.VAL_PREFIX_INFO + (object == null ? "No info(" + doc + ")!" : object.toString());
   }
   Application.ui().print(msg);
}

public void signContract ()
{
   super.demand("theme,doc", "");
}

public String description ()
{
   return implName() + " print statistcal information stored under a key in the context. " + ARGS;
}
}
