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

📄 msgblockiterator.java

📁 cwbbs 云网论坛源码
💻 JAVA
字号:
package com.redmoon.forum;public class MsgBlockIterator {            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 MsgBlockIterator(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 != Long.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.MSG_BLOCK_SIZE) {                        MsgCache mc = new MsgCache();            this.infoBlock = mc.getMsgBlock(query, groupKey, index);            this.blockID = index / MsgCache.MSG_BLOCK_SIZE;            this.blockStart = blockID * MsgCache.MSG_BLOCK_SIZE;        }        Object element = null;                        int relativeIndex = (int) (index % MsgCache.MSG_BLOCK_SIZE);                if (relativeIndex < infoBlock.length) {            MsgMgr msgmgr = new MsgMgr();            element = msgmgr.getMsgDb(infoBlock[relativeIndex]);        }        return element;    }}

⌨️ 快捷键说明

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