Exemple #1
0
  public boolean union(T item1, T item2) {
    Element e1parent = elementsMap.get(item1.getNum());
    Element e2parent = elementsMap.get(item2.getNum());
    Element e1 = e1parent;
    Element e2 = e2parent;

    while (e1parent.parent() != e1parent) e1parent = e1parent.parent();
    while (e2parent.parent() != e2parent) e2parent = e2parent.parent();

    e1.setParent(e1parent);
    e2.setParent(e2parent);

    if (e1parent == e2parent) return false;

    if (e1parent.getSize() > e2parent.getSize()) {
      e1parent.setSize(e1parent.getSize() + e2parent.getSize());
      e2parent.setSize(0);
      e2parent.setParent(e1parent);
    } else {
      e2parent.setSize(e1parent.getSize() + e2parent.getSize());
      e1parent.setSize(0);
      e1parent.setParent(e2parent);
    }
    return true;
  }
Exemple #2
0
  public T find(T item) {
    Element e = elementsMap.get(item.getNum());

    while (e != e.parent()) e = e.parent();

    return e.data();
  }
Exemple #3
0
  // merge multiple <head> or <body> contents into one, delete the remainder, and ensure they are
  // owned by <html>
  private void normaliseStructure(String tag, Element htmlEl) {
    Elements elements = this.getElementsByTag(tag);
    Element master = elements.first(); // will always be available as created above if not existent
    if (elements.size() > 1) { // dupes, move contents to master
      List<Node> toMove = new ArrayList<Node>();
      for (int i = 1; i < elements.size(); i++) {
        Node dupe = elements.get(i);
        for (Node node : dupe.childNodes) toMove.add(node);
        dupe.remove();
      }

      for (Node dupe : toMove) master.appendChild(dupe);
    }
    // ensure parented by <html>
    if (!master.parent().equals(htmlEl)) {
      htmlEl.appendChild(master); // includes remove()
    }
  }
Exemple #4
0
 private void normaliseStructure(String tag, Element htmlEl) {
   Elements elements = getElementsByTag(tag);
   Element master = elements.first();
   if (elements.size() > 1) {
     List<Node> toMove = new ArrayList();
     for (int i = 1; i < elements.size(); i++) {
       Node dupe = elements.get(i);
       for (Node node : dupe.childNodes) {
         toMove.add(node);
       }
       dupe.remove();
     }
     for (Node dupe : toMove) {
       master.appendChild(dupe);
     }
   }
   if (!master.parent().equals(htmlEl)) {
     htmlEl.appendChild(master);
   }
 }
 public void addElement(Element _element) {
   children.add(_element);
   _element.parent = this;
 }