public void addSegmentVariation(LifeSegmentVariation type, double y, HtmlColor backcolor) { if (events.size() > 0) { final Variation last = events.get(events.size() - 1); if (y < last.y) { throw new IllegalArgumentException(); } if (y == last.y && type != last.type) { throw new IllegalArgumentException(); } } events.add(new Variation(type, y, backcolor)); final int currentLevel = type.apply(stairs.getLastValue()); stairs.addStep(y, currentLevel); assert getLevel(y) == stairs.getValue(y); assert currentLevel == stairs.getValue(y); assert getLevel(y) == currentLevel; maxLevel = Math.max(getLevel(y), maxLevel); }
int getLevel(double y) { // int level = 0; // for (Variation ev : events) { // if (ev.y > y) { // return level; // } // if (ev.type == LifeSegmentVariation.LARGER) { // level++; // } else { // level--; // if (level < 0) { // level = 0; // } // } // } // assert level >= 0; // return level; return stairs.getValue(y); }