Class BytesArray
- java.lang.Object
-
- com.metsci.glimpse.util.primitives.BytesArray
-
- All Implemented Interfaces:
Bytes,BytesModifiable
public class BytesArray extends Object implements BytesModifiable
- Author:
- hogye
-
-
Constructor Summary
Constructors Constructor Description BytesArray()BytesArray(byte[] a)For efficiency, does not clone the array arg.BytesArray(byte[] a, int n)For efficiency, does not clone the array arg.BytesArray(int n)BytesArray(Bytes xs)Clones the sequence arg.BytesArray(String s)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidappend(byte v)voidappend(byte[] vs)voidappend(byte[] vs, int from, int to)voidappend(Bytes vs)voidappend(Bytes vs, int from, int to)voidappend(String s)voidappend(String s, int from, int to)voidappend(ByteBuffer vs)voidappend(ByteBuffer vs, int c)voidclear()voidcompact()BytesArraycopy()byte[]copyOf()byte[]copyOf(int i, int c)voidcopyTo(int i, byte[] dest, int iDest, int c)voidcopyTo(int i, ByteBuffer dest, int c)voidcopyTo(ByteBuffer dest)voidensureCapacity(int minCapacity)bytefirst()voidinsert(int i, byte v)voidinsert(int i, byte[] vs)voidinsert(int i, byte[] vs, int from, int to)voidinsert(int i, Bytes vs)voidinsert(int i, Bytes vs, int from, int to)voidinsert(int i, String s)voidinsert(int i, String s, int from, int to)voidinsert(int i, ByteBuffer vs)voidinsert(int i, ByteBuffer vs, int c)booleanisEmpty()bytelast()intn()Length of the sequencestatic byte[]newArray(int oldCapacity, int minNewCapacity)Creates a new array whose capacity is at least minNewCapacity, and at least 1.618 * oldCapacity, up to Integer.MAX_VALUE.voidprepend(byte v)voidprepend(byte[] vs)voidprepend(byte[] vs, int from, int to)voidprepend(Bytes vs)voidprepend(Bytes vs, int from, int to)voidprepend(String s)voidprepend(String s, int from, int to)voidprepend(ByteBuffer vs)voidprepend(ByteBuffer vs, int c)voidprepForAppend(int c)Makes room in this array for new values to be appended.voidprepForInsert(int i, int c)Makes room in this array for new values to be inserted.voidprepForPrepend(int c)Makes room in this array for new values to be prepended.voidremove(byte v)Removes a single copy of the specified value.voidremoveIndex(int index)Remove value at index.voidremoveRange(int from, int to)Removes values starting at index from (inclusive) to index to (exclusive).voidset(int i, byte v)voidset(int i, byte[] vs)voidset(int i, byte[] vs, int from, int to)Stringstring()Stringstring(int i, int c)Strings are encoded and decoded using the UTF-8 charset (multi-byte charsets just aren't worth the increased complication in indexing).bytev(int i)Value at index i
-
-
-
Field Detail
-
encoder
public static final CharsetEncoder encoder
-
a
public byte[] a
-
n
public int n
-
-
Constructor Detail
-
BytesArray
public BytesArray(byte[] a)
For efficiency, does not clone the array arg.
-
BytesArray
public BytesArray(int n)
-
BytesArray
public BytesArray()
-
BytesArray
public BytesArray(byte[] a, int n)For efficiency, does not clone the array arg.
-
BytesArray
public BytesArray(Bytes xs)
Clones the sequence arg.
-
BytesArray
public BytesArray(String s)
-
-
Method Detail
-
v
public byte v(int i)
Description copied from interface:BytesValue at index i
-
n
public int n()
Description copied from interface:BytesLength of the sequence
-
copyTo
public void copyTo(int i, byte[] dest, int iDest, int c)
-
copyTo
public void copyTo(int i, ByteBuffer dest, int c)
-
copyTo
public void copyTo(ByteBuffer dest)
-
copy
public BytesArray copy()
- Specified by:
copyin interfaceBytes- Specified by:
copyin interfaceBytesModifiable
-
string
public String string(int i, int c)
Description copied from interface:BytesStrings are encoded and decoded using the UTF-8 charset (multi-byte charsets just aren't worth the increased complication in indexing). FIXME: This is probably broken, because UTF-8 *is* a multi-byte charset
-
set
public void set(int i, byte v)- Specified by:
setin interfaceBytesModifiable
-
set
public void set(int i, byte[] vs)- Specified by:
setin interfaceBytesModifiable
-
set
public void set(int i, byte[] vs, int from, int to)- Specified by:
setin interfaceBytesModifiable
-
insert
public void insert(int i, byte v)- Specified by:
insertin interfaceBytesModifiable
-
insert
public void insert(int i, Bytes vs)- Specified by:
insertin interfaceBytesModifiable
-
insert
public void insert(int i, Bytes vs, int from, int to)- Specified by:
insertin interfaceBytesModifiable
-
insert
public void insert(int i, String s)- Specified by:
insertin interfaceBytesModifiable
-
insert
public void insert(int i, String s, int from, int to)- Specified by:
insertin interfaceBytesModifiable
-
insert
public void insert(int i, byte[] vs)- Specified by:
insertin interfaceBytesModifiable
-
insert
public void insert(int i, byte[] vs, int from, int to)- Specified by:
insertin interfaceBytesModifiable
-
insert
public void insert(int i, ByteBuffer vs)- Specified by:
insertin interfaceBytesModifiable
-
insert
public void insert(int i, ByteBuffer vs, int c)- Specified by:
insertin interfaceBytesModifiable
-
prepForInsert
public void prepForInsert(int i, int c)Makes room in this array for new values to be inserted. When this call returns, the values inthis.aon[i,i+c)are undefined. Writing meaningful values to these indices is up to the caller.- Parameters:
i- The index at which new values will be insertedc- The count of new values that will be inserted
-
prepend
public void prepend(byte v)
- Specified by:
prependin interfaceBytesModifiable
-
prepend
public void prepend(Bytes vs)
- Specified by:
prependin interfaceBytesModifiable
-
prepend
public void prepend(Bytes vs, int from, int to)
- Specified by:
prependin interfaceBytesModifiable
-
prepend
public void prepend(String s)
- Specified by:
prependin interfaceBytesModifiable
-
prepend
public void prepend(String s, int from, int to)
- Specified by:
prependin interfaceBytesModifiable
-
prepend
public void prepend(byte[] vs)
- Specified by:
prependin interfaceBytesModifiable
-
prepend
public void prepend(byte[] vs, int from, int to)- Specified by:
prependin interfaceBytesModifiable
-
prepend
public void prepend(ByteBuffer vs)
- Specified by:
prependin interfaceBytesModifiable
-
prepend
public void prepend(ByteBuffer vs, int c)
- Specified by:
prependin interfaceBytesModifiable
-
prepForPrepend
public void prepForPrepend(int c)
Makes room in this array for new values to be prepended. When this call returns, the values inthis.aon[0,c)are undefined. Writing meaningful values to these indices is up to the caller.- Parameters:
c- The count of new values that will be inserted
-
append
public void append(byte v)
- Specified by:
appendin interfaceBytesModifiable
-
append
public void append(Bytes vs)
- Specified by:
appendin interfaceBytesModifiable
-
append
public void append(Bytes vs, int from, int to)
- Specified by:
appendin interfaceBytesModifiable
-
append
public void append(String s)
- Specified by:
appendin interfaceBytesModifiable
-
append
public void append(String s, int from, int to)
- Specified by:
appendin interfaceBytesModifiable
-
append
public void append(byte[] vs)
- Specified by:
appendin interfaceBytesModifiable
-
append
public void append(byte[] vs, int from, int to)- Specified by:
appendin interfaceBytesModifiable
-
append
public void append(ByteBuffer vs)
- Specified by:
appendin interfaceBytesModifiable
-
append
public void append(ByteBuffer vs, int c)
- Specified by:
appendin interfaceBytesModifiable
-
prepForAppend
public void prepForAppend(int c)
Makes room in this array for new values to be appended. When this call returns, the values inthis.aon[this.n-c,this.n)are undefined. Writing meaningful values to these indices is up to the caller.- Parameters:
c- The count of new values that will be appended
-
remove
public void remove(byte v)
Description copied from interface:BytesModifiableRemoves a single copy of the specified value. If multiple copies are present, there is no guarantee which one will be removed.- Specified by:
removein interfaceBytesModifiable
-
removeRange
public void removeRange(int from, int to)Description copied from interface:BytesModifiableRemoves values starting at index from (inclusive) to index to (exclusive). All other values with indices greater than or equal to index to have their index in the array decreased by to-from and the size of the array is decreased by to-from.- Specified by:
removeRangein interfaceBytesModifiable
-
removeIndex
public void removeIndex(int index)
Description copied from interface:BytesModifiableRemove value at index. All other values with indices greater than index have their index in the array decreased by one and the size of the array is decreased by one.- Specified by:
removeIndexin interfaceBytesModifiable
-
clear
public void clear()
- Specified by:
clearin interfaceBytesModifiable
-
ensureCapacity
public void ensureCapacity(int minCapacity)
- Specified by:
ensureCapacityin interfaceBytesModifiable
-
compact
public void compact()
- Specified by:
compactin interfaceBytesModifiable
-
newArray
public static byte[] newArray(int oldCapacity, int minNewCapacity)Creates a new array whose capacity is at least minNewCapacity, and at least 1.618 * oldCapacity, up to Integer.MAX_VALUE.
-
-