static ListContext withParent(ListContext parent) {
   ListContext context = new ListContext();
   if (parent != null) {
     context.parent = parent;
     context.level = parent.level + 1;
   } else {
     context.level = 1;
   }
   return context;
 }
 public void enterList() {
   currentList = ListContext.empty();
   handler.startList();
 }
  public void enterListItem(NodeContext context) {
    int times, dots = 0;
    if ((times = context.getIntAttribute("times.count", -1)) > 0) {
      if (currentList.type == ListType.Unordered) {
        if (currentList.bullets == times) {

        } else if (currentList.bullets < times) {
          currentList = ListContext.withParent(currentList);
          currentList.bullets = times;
        } else if (currentList.bullets > times) {
          while (currentList.bullets > times && currentList.level > 1) {
            handler.endUnorderedList(currentList.level);
            currentList = currentList.parent;
          }
        }
      } else if (currentList.type == ListType.Ordered) {
        currentList = ListContext.withParent(currentList);
        currentList.bullets = times;
      }
    } else if ((dots = context.getIntAttribute("dots.count", -1)) > 0) {
      if (currentList.type == ListType.Ordered) {
        if (currentList.bullets == dots) {

        } else if (currentList.bullets < dots) {
          currentList = ListContext.withParent(currentList);
          currentList.bullets = dots;
        } else if (currentList.bullets > dots) {
          while (currentList.bullets > times && currentList.level > 1) {
            handler.endOrderedList(currentList.level);
            currentList = currentList.parent;
          }
        }
      } else if (currentList.type == ListType.Unordered) {
        currentList = ListContext.withParent(currentList);
        currentList.bullets = dots;
      }
    }

    if (currentList.type == null) {
      if (times > 0) {
        currentList.type = ListType.Unordered;
        currentList.bullets = times;
        handler.startUnorderedList(currentList.level, consumeAttList());
      } else if (dots > 0) {
        currentList.type = ListType.Ordered;
        currentList.bullets = dots;
        handler.startOrderedList(currentList.level, consumeAttList());
      }
    }
    handler.startListItem(currentList.level);
    clearAttList();
  }
 static ListContext empty() {
   ListContext ctx = new ListContext();
   ctx.level = 1;
   ctx.root = ctx;
   return ctx;
 }