Пример #1
0
 public void reset() {
   if (values != null) {
     Arrays.fill(values, 0L);
   }
   if (children != null) {
     for (DebugValueMap child : children) {
       child.reset();
     }
   }
 }
Пример #2
0
  private void mergeWith(DebugValueMap map) {
    if (map.hasChildren()) {
      if (hasChildren()) {
        children.addAll(map.children);
      } else {
        children = map.children;
      }
      map.children = null;
    }

    int size = Math.max(this.capacity(), map.capacity());
    ensureSize(size);
    for (int i = 0; i < size; ++i) {
      long curValue = getCurrentValue(i);
      long otherValue = map.getCurrentValue(i);
      setCurrentValue(i, curValue + otherValue);
    }
  }
Пример #3
0
  public void normalize() {
    if (hasChildren()) {
      Map<String, DebugValueMap> occurred = new HashMap<>();
      for (DebugValueMap map : children) {
        String mapName = map.getName();
        if (!occurred.containsKey(mapName)) {
          occurred.put(mapName, map);
          map.normalize();
        } else {
          occurred.get(mapName).mergeWith(map);
          occurred.get(mapName).normalize();
        }
      }

      if (occurred.values().size() < children.size()) {
        // At least one duplicate was found.
        children.clear();
        for (DebugValueMap map : occurred.values()) {
          addChild(map);
          map.normalize();
        }
      }
    }
  }