📄 booleanbuffer.java
字号:
package com.reddragon2046.base.utilities.data.adapters;
import com.reddragon2046.base.utilities.data.*;
import com.reddragon2046.base.utilities.data.algorithms.Removing;
import java.util.*;
// Referenced classes of package com.reddragon2046.base.utilities.data.adapters:
// AbstractArrayAdapter, ByteBuffer, BooleanArray, BooleanIterator,
// ByteIterator, AbstractArrayIterator, Algorithms
public class BooleanBuffer extends AbstractArrayAdapter
{
public BooleanBuffer()
{
this(0);
}
public BooleanBuffer(int size)
{
if(size < 0)
{
throw new IllegalArgumentException("Attempt to create an BooleanBuffer with a negative size");
} else
{
storage = new ByteBuffer(size / 8 + 1);
this.size = size;
return;
}
}
public BooleanBuffer(int size, boolean object)
{
this(size);
for(int i = 0; i < storage.size(); i++)
storage.put(i, ((byte)(object ? -1 : 0)));
}
public BooleanBuffer(boolean array[])
{
this(new BooleanArray(array));
}
BooleanBuffer(ByteBuffer array)
{
storage = array;
size = 0;
}
public BooleanBuffer(BooleanBuffer array)
{
storage = array.storage;
size = array.size;
}
public BooleanBuffer(BooleanArray array)
{
this(array.size());
Algorithms.Copying.copy(array.begin(), array.end(), begin());
}
public BooleanBuffer(BitSet bitset)
{
this(bitset.size());
BidirectionalIterator b = begin();
synchronized(bitset)
{
for(int i = 0; i < size(); i++)
b.put(i, new Boolean(bitset.get(i)));
}
}
public synchronized Object clone()
{
return new BooleanBuffer(this);
}
public synchronized int hashCode()
{
return storage.hashCode();
}
public boolean equals(Object object)
{
return (object instanceof BooleanBuffer) && equals((BooleanBuffer)object) || (object instanceof BooleanArray) && equals((BooleanArray)object);
}
public boolean equals(BooleanBuffer array)
{
boolean flag;
synchronized(array)
{
flag = Algorithms.Comparing.equal(this, array);
}
return flag;
}
public boolean equals(BooleanArray array)
{
boolean flag;
synchronized(array)
{
flag = Algorithms.Comparing.equal(this, array);
}
return flag;
}
public boolean equals(boolean array[])
{
return equals(new BooleanArray(array));
}
public synchronized String toString()
{
return Algorithms.Printing.toString(this, "BooleanBuffer");
}
public synchronized void copy(BooleanBuffer array)
{
if(this == array)
{
return;
} else
{
storage = new ByteBuffer(array.storage);
size = array.size;
return;
}
}
public synchronized void copyTo(boolean array[])
{
synchronized(array)
{
int x = 0;
BooleanIterator b = (BooleanIterator)begin();
for(; x < size(); x++)
array[x] = b.getBoolean(x);
}
}
public synchronized void copyTo(BitSet bitset)
{
synchronized(bitset)
{
int x = 0;
BooleanIterator b = (BooleanIterator)begin();
for(; x < size(); x++)
if(b.getBoolean(x))
bitset.set(x);
else
bitset.clear(x);
}
}
public synchronized boolean[] get()
{
boolean data[] = new boolean[size()];
copyTo(data);
return data;
}
public int size()
{
return size;
}
public int capacity()
{
return storage.size() * 8 - 1;
}
public Object get(int index)
{
AbstractArrayAdapter.checkIndex(index, size);
return (new BooleanIterator(this, index)).get();
}
public boolean booleanAt(int index)
{
return ((Boolean)get(index)).booleanValue();
}
public void put(int index, Object object)
{
put(index, asBoolean(object));
}
public synchronized void put(int index, boolean object)
{
AbstractArrayAdapter.checkIndex(index, size);
begin().put(index, new Boolean(object));
}
public synchronized void clear()
{
storage.clear();
size = 0;
}
public synchronized Object remove(int index)
{
AbstractArrayAdapter.checkIndex(index, size);
Iterator iter = new BooleanIterator(this, index);
Object obj = iter.next();
iter.remove();
return obj;
}
public synchronized int remove(int first, int last)
{
if(last < first)
{
return 0;
} else
{
AbstractArrayAdapter.checkRange(first, last, size);
com.reddragon2046.base.utilities.data.algorithms.Removing.remove(SeriesFactory.createModifiable(this, first, last));
return last - first;
}
}
public synchronized Object popBack()
{
if(size == 0)
throw new NoSuchElementException("BooleanBuffer is empty");
else
return (new BooleanIterator(this, --size)).get();
}
public boolean add(Object object)
{
add(asBoolean(object));
return true;
}
public synchronized void add(boolean b)
{
BooleanIterator finish = new BooleanIterator(this, size);
if(atEnd())
{
insertAux(finish, b);
} else
{
size++;
finish.put(b);
}
}
public void pushBack(Object object)
{
add(asBoolean(object));
}
public void pushBack(boolean b)
{
add(b);
}
public BooleanIterator insert(BooleanIterator pos, Object object)
{
return insert(pos, asBoolean(object));
}
public BooleanIterator insert(BooleanIterator pos, boolean object)
{
int n = pos.index();
if(n == size)
pushBack(object);
else
insertAux(pos, object);
return new BooleanIterator(this, n);
}
public void insert(int index, Object object)
{
insert(index, asBoolean(object));
}
public synchronized void insert(int index, boolean object)
{
AbstractArrayAdapter.checkIndex(index, size + 1);
insert(new BooleanIterator(this, index), object);
}
public void insert(BooleanIterator pos, int n, Object object)
{
if(n < 0)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -