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

📄 threadblockiterator.java

📁 cwbbs 云网论坛源码
💻 JAVA
字号:
package com.redmoon.forum;public class ThreadBlockIterator {    String groupKey;    private long[] infoBlock;    private long blockID;    private long blockStart;    private String query;    private long startIndex;    private long currentIndex;    private long endIndex;    private Object previousElement = null;    private Object nextElement = null;        protected ThreadBlockIterator(long[] threadBlock, String query,                                  String groupKey,                                  long startIndex, long endIndex) {        this.infoBlock = threadBlock;        this.blockID = startIndex / MsgCache.MSG_BLOCK_SIZE;        this.blockStart = blockID * MsgCache.MSG_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(long index) {        if (index < 0) {            return null;        }                        if (index < blockStart || index >= blockStart + MsgCache.THREAD_BLOCK_SIZE) {                        MsgCache mc = new MsgCache();            this.infoBlock = mc.getThreadsBlock(query, groupKey, index);            this.blockID = index / MsgCache.THREAD_BLOCK_SIZE;            this.blockStart = blockID * MsgCache.THREAD_BLOCK_SIZE;        }        Object element = null;                        int relativeIndex = (int)(index % MsgCache.THREAD_BLOCK_SIZE);                if (relativeIndex < infoBlock.length) {            MsgMgr msgmgr = new MsgMgr();            element = msgmgr.getMsgDb(infoBlock[relativeIndex]);        }        return element;    }    public void setIndex(MsgDb msgDb) {                        nextElement = null;        previousElement = null;                long threadID = msgDb.getId();        long[] currentBlock;        for (long i = startIndex; i < endIndex; i++) {            currentBlock = msgDb.getThreadsBlock(query, msgDb.getboardcode(), i);            if (currentBlock.length == 0) {                                            }            long blockID = i / MsgCache.THREAD_BLOCK_SIZE;            long blockEnd = blockID * MsgCache.THREAD_BLOCK_SIZE +                           MsgCache.THREAD_BLOCK_SIZE;                        if (startIndex < blockEnd) {                                                for (long j = startIndex % MsgCache.THREAD_BLOCK_SIZE;                             j < currentBlock.length; j++, i++) {                    if (currentBlock[(int)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 + -