public StructuralSummaryNode next() throws IOException, DBException // for Iterator
      {
    // read record from file
    // transform into ssNode
    int CID;
    int qNameLen;
    String qName;
    byte[] qNameSeq;
    int parentCID;
    StructuralSummaryNode currentNode = new StructuralSummaryNode();
    int nextPage; // needed in case that data is written in more than one page
    while (true) {
      // if(unTakenNodes!=0 &&XBufferChannel.position()+2*Settings.sizeOfInt<=Settings.pageSize)
      // agar dorost bkhunim har bar position sare yek record mi iste:
      if (unTakenNodes != 0 && xBufferChannel.position() < freeOffset) {
        // bayd daghigh tar chek bshe.
        // stroage format in ssIndex: cid(int),qlen(int),qSeq(byte array),parentCId(int)

        CID = xBufferChannel.getInt();
        logManager.LogManager.log(1, "CID: " + CID);
        qNameLen = xBufferChannel.getInt();
        int reqSpace = qNameLen + Settings.sizeOfInt;
        int capacity = Settings.pageSize - xBufferChannel.position();
        if (reqSpace <= capacity) {
          qNameSeq = new byte[qNameLen];
          xBufferChannel.get(qNameSeq, 0, qNameLen);
          qName = new String(qNameSeq);
          parentCID = xBufferChannel.getInt();
          currentNode.setCID(CID);
          currentNode.setParentCID(parentCID);
          currentNode.setQName(qName);
          unTakenNodes--;
          return currentNode; // return breaks loop!
        }
      } else {

        //               if(unTakenNodes==0)//in k ghalate baz :(
        //               {   return null;  }
        //               else //if(XBufferChannel.position()+2*Settings.sizeOfInt>Settings.pageSize)
        //               {    //goTOnextPAge;
        xBufferChannel.position(Settings.nextPagePos);
        nextPage = xBufferChannel.getInt();
        bufMngr.unpinBuffer(xBufferChannel);
        if (nextPage > 0) {
          loadSSPage(nextPage); // prepares XBufferChannel and loads page into it.
          //                      System.out.println("loaded:"+nextPage);

        } else return null;
        workingPage = nextPage;
        xBufferChannel.position(
            Settings.dataStartPos); // instead of calling open(somehow opens nextpage)
        //               }
      }
    } // end while
  }
 public int getLevel() {
   if (levelComputed) return level;
   StructuralSummaryNode node = this;
   int level = 0;
   while (node.getParent() != null) {
     level++;
     node = node.getParent();
   }
   levelComputed = true;
   this.level = level;
   return level;
 }
 public boolean hasChild(StructuralSummaryNode newborn) {
   boolean present = false; // newborn exists in list or not
   for (StructuralSummaryNode child : childrenList) {
     if (child.getCID() == newborn.getCID()
         && (child.getQName() == null
             ? newborn.getQName() == null
             : child.getQName().equals(newborn.getQName()))) {
       present = true;
       break;
     }
   }
   return present;
 }
  //// end of copied//////////////////////////////////
  public void appendChild(StructuralSummaryNode childNode) {
    childNode.setParent(this);

    childrenList.add(childNode);
  }
 public void setParent(StructuralSummaryNode parent) {
   this.parent = parent;
   this.parentCID = parent.getCID();
   this.levelComputed = false;
 }