⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 docblockiterator.java

📁 oa 源码
💻 JAVA
字号:
package com.redmoon.oa.flow;public class DocBlockIterator {      String groupKey;  private long[] infoBlock;  private int blockID;  private int blockStart;  private String query;  private int startIndex;  private int currentIndex;  private int endIndex;  private Object previousElement = null;  private Object nextElement = null;    protected DocBlockIterator(long[] threadBlock, String query, String groupKey,                              int startIndex, int endIndex) {    this.infoBlock = threadBlock;    this.blockID = startIndex / DocCacheMgr.DOC_BLOCK_SIZE;    this.blockStart = blockID * DocCacheMgr.DOC_BLOCK_SIZE;    this.query = query;    this.currentIndex = startIndex - 1;    this.startIndex = startIndex;    this.endIndex = endIndex;    this.groupKey = groupKey;  }  public boolean hasNext() {        if (currentIndex == endIndex) {      return false;    }                if (nextElement == null) {      nextElement = getNextElement();            if (nextElement == null) {        return false;      }    }    return true;  }  public boolean hasPrevious() {        if (currentIndex == startIndex) {      return false;    }            if (previousElement == null) {      previousElement = getPreviousElement();            if (previousElement == null) {        return false;      }    }    return true;  }  public Object next() throws java.util.NoSuchElementException {    Object element = null;    if (nextElement != null) {      element = nextElement;      this.nextElement = null;    }    else {      element = getNextElement();      if (element == null) {        throw new java.util.NoSuchElementException();      }    }    return element;  }  public Object previous() {    Object element = null;    if (previousElement != null) {      element = previousElement;      previousElement = null;    }    else {      element = getPreviousElement();      if (element == null) {        throw new java.util.NoSuchElementException();      }    }    return element;  }    private Object getNextElement() {    previousElement = null;    Object element = null;    if (endIndex!=Integer.MAX_VALUE) {      while (currentIndex + 1 < endIndex && element == null) {        currentIndex++;        element = getElement(currentIndex);      }    }    else {      if (currentIndex + 1 < endIndex) {        currentIndex++;        element = getElement(currentIndex);      }    }    return element;  }    private Object getPreviousElement() {    nextElement = null;    Object element = null;    while (currentIndex >= startIndex && element == null) {      currentIndex--;      element = getElement(currentIndex);    }    return element;  }    private Object getElement(int index) {    if (index < 0) {      return null;    }            if (index < blockStart || index >= blockStart + DocCacheMgr.DOC_BLOCK_SIZE) {            Document doc = new Document();      this.infoBlock = doc.getDocBlock(query, groupKey, index);      this.blockID = index / DocCacheMgr.DOC_BLOCK_SIZE;      this.blockStart = blockID * DocCacheMgr.DOC_BLOCK_SIZE;    }    Object element = null;            int relativeIndex = index % DocCacheMgr.DOC_BLOCK_SIZE;        if (relativeIndex < infoBlock.length) {        DocumentMgr docmgr = new DocumentMgr();      element = docmgr.getDocument((int)infoBlock[relativeIndex]);    }    return element;  }  public void setIndex(Document doc) {                  nextElement = null;      previousElement = null;            long threadID = doc.getID();      long[] currentBlock;      for (int i = startIndex; i < endIndex; i++) {          currentBlock = doc.getDocBlock(query, doc.getDirCode(), i);          if (currentBlock.length == 0) {                                      }          int blockID = i / DocCacheMgr.DOC_BLOCK_SIZE;          int blockEnd = blockID * DocCacheMgr.DOC_BLOCK_SIZE +                         DocCacheMgr.DOC_BLOCK_SIZE;                    if (startIndex < blockEnd) {                                          for (int j = startIndex % DocCacheMgr.DOC_BLOCK_SIZE;                           j < currentBlock.length; j++, i++) {                  if (currentBlock[j] == threadID) {                      this.currentIndex = i;                      return;                  }              }          }                    else {              for (int j = 0; j < currentBlock.length; j++, i++) {                  if (currentBlock[j] == threadID) {                      this.currentIndex = i;                      return;                  }              }          }      }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -