private void doUpdateChildren(ChildrenUpdate childrenUpdate) {
    List<MavenArtifactNode> children = childrenUpdate.children();
    MavenProject mavenProject = childrenUpdate.mavenProject();

    List<DependencyNode> newNodes = null;
    int validChildCount = 0;

    for (MavenArtifactNode each : children) {
      if (each.getState() != MavenArtifactState.ADDED &&
          each.getState() != MavenArtifactState.CONFLICT &&
          each.getState() != MavenArtifactState.DUPLICATE) {
        continue;
      }

      if (newNodes == null) {
        if (validChildCount < myChildren.size()) {
          DependencyNode currentValidNode = myChildren.get(validChildCount);
          if (currentValidNode.getArtifact().equals(each.getArtifact())
              && currentValidNode.isUnresolved() == each.getArtifact().isFileUnresolved()) {
            if (each.getState() == MavenArtifactState.ADDED) {
              currentValidNode.updateChildren(each.getDependencies(), mavenProject);
            }

            validChildCount++;
            continue;
          }
        }

        newNodes = new ArrayList<>(children.size());
        newNodes.addAll(myChildren.subList(0, validChildCount));
      }

      DependencyNode newNode = findOrCreateNodeFor(each, mavenProject, validChildCount);
      newNodes.add(newNode);
      if (each.getState() == MavenArtifactState.ADDED) {
        newNode.updateChildren(each.getDependencies(), mavenProject);
      }
      newNode.updateDependency();
    }

    if (newNodes == null) {
      if (validChildCount == myChildren.size()) {
        return; // All nodes are valid, child did not changed.
      }

      assert validChildCount < myChildren.size();

      newNodes = new ArrayList<>(myChildren.subList(0, validChildCount));
    }

    myChildren.clear();
    myChildren.addAll(newNodes);
    childrenChanged();
  }
private void doUpdateChildren(ChildrenUpdate childrenUpdate)