intqueue.java
来自「xstream是一个把java object序列化成xml文件的开源库,轻便好用」· Java 代码 · 共 50 行
JAVA
50 行
package com.thoughtworks.xstream.core.util;public final class IntQueue { private final int[] data; private int writePointer = 0; private int readPointer = 0; private boolean empty = true; public IntQueue(int size) { data = new int[size]; } public void write(int value) { if (!empty && writePointer == readPointer) { throw new OverflowException(); } data[writePointer++] = value; if (writePointer == data.length) { writePointer = 0; } empty = false; } public int read() { if (empty) { throw new NothingToReadException(); } int result = data[readPointer++]; if (readPointer == data.length) { readPointer = 0; } if (readPointer == writePointer) { empty = true; } return result; } public boolean isEmpty() { return empty; } public static class OverflowException extends RuntimeException { } public static class NothingToReadException extends RuntimeException { }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?