public class RingBuffer<T> extends Object
| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_SIZE |
Object[] |
elements |
| Constructor and Description |
|---|
RingBuffer()
使用默认容量构造一个环形缓冲区
|
RingBuffer(int capacity)
使用指定容量构造一个环形缓冲区
|
| Modifier and Type | Method and Description |
|---|---|
int |
avaliable()
缓冲区可写空间
|
void |
clear()
清理缓冲区
|
T |
get(int offset)
获得基于索引位置的数据
|
int |
get(T[] t,
int offset,
int length)
读取所有缓冲区的数据
不影响读写位置
|
int |
getCapacity()
获得容量
|
int |
getReadPositon()
获得读指针位置
|
int |
getWritePositon()
获得写指针位置
|
Boolean |
isEmpty()
缓冲区空判断
|
Boolean |
isFull()
缓冲区满判断
|
T |
pop()
读取一个 byte
|
int |
pop(T[] ts,
int offset,
int length)
读取缓冲区的数据
|
boolean |
push(T t)
增加一个对象
|
int |
push(T[] ts,
int offset,
int length)
写入一个 byte[] 数据
|
int |
remaining()
缓冲区可用数据量
|
void |
skip(int offset)
读指针跳过特定的偏移量
|
Object[] |
toArray()
读取所有缓冲区的数据
不影响读写位置
|
String |
toString() |
public static final int DEFAULT_SIZE
public Object[] elements
public RingBuffer()
public RingBuffer(int capacity)
capacity - 分配的容量public int getReadPositon()
public int getWritePositon()
public int getCapacity()
public void skip(int offset)
offset - 偏移量public Boolean isEmpty()
public Boolean isFull()
public void clear()
public T get(int offset)
offset - 偏移量public int get(T[] t, int offset, int length)
t - 用于读取数据的 byte 数组offset - 偏移量length - 数据长度public Object[] toArray()
public T pop()
public boolean push(T t)
t - 对象public int push(T[] ts, int offset, int length)
ts - T[] 对象offset - 针对 byte[] 的偏移量length - 写入数据的长度public int remaining()
public int avaliable()
public int pop(T[] ts, int offset, int length)
ts - 用于读取数据的 byte 数组offset - 偏移量length - 读取数据的长度Copyright © 2020 Voovan. All rights reserved.