Brooklyn

brooklyn.util.math
[Java] Class BitList

java.lang.Object
  brooklyn.util.math.BitList

public class BitList

represents an immutable ordered collection of bits with a known length

when converting to and from bytes and larger numbers, this representation uses the least-significant first convention both for bits and for bytes (little endian)

(i.e. least significant byte is first, as is the least significant bit; ninth element in this list is the least significant bit in the second byte, so a list {0,0,0,0,0,0,0,0,1,0} represents 256)


Field Summary
protected int length

 
Constructor Summary
protected BitList(java.util.BitSet bits, int length)

 
Method Summary
BitList anded(BitList other)

represents the result of this bit list logically ANDed with the other

boolean[] asArray()

java.math.BigInteger asBigInteger()

java.util.BitSet asBitSet()

nb: BitSet forgets the length

java.util.List asByteList()

byte[] asBytes()

returns the bits converted to bytes, with least significant bit first and* first 8 bits in the first byte

java.util.List asList()

int[] asUnsignedBytes()

byte byteValue()

returns value of this as a byte(ignoring any too-high bits)

int commonPrefixLength(BitList other)

boolean equals(java.lang.Object obj)

boolean get(int index)

int hashCode()

int intValue()

returns value of this as an integer (ignoring any too-high bits)

boolean isEmpty()

true iff the length is 0; see also isZero

boolean isZero()

true iff all bits are 0

int length()

long longValue()

returns value of this as a long (ignoring any too-high bits)

static BitList newInstance(java.util.BitSet bits, int length)

static BitList newInstance(byte... bytes)

static BitList newInstance(java.util.List l)

static BitList newInstance(boolean... l)

static BitList newInstance(java.math.BigInteger x)

static BitList newInstanceFromBytes(int... bytes)

as newInstance(byte...), but accepting ints for convenience; only the least significant 8 bits of the parameters are considered

BitList notted()

represents the result of this bit list logically notted

BitList orred(BitList other)

represents the result of this bit list logically ORred with the other

BitList resized(int length)

creates a new instance with the given length, either reducing the list or padding it with 0's (at the end, in both cases)

BitList reversed()

java.lang.String toString()

BitList xorred(BitList other)

represents the result of this bit list logically XORred with the other

 
Methods inherited from class java.lang.Object
java.lang.Object#wait(), java.lang.Object#wait(long), java.lang.Object#wait(long, int), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()
 

Field Detail

length

protected final int length


 
Constructor Detail

BitList

protected BitList(java.util.BitSet bits, int length)


 
Method Detail

anded

public BitList anded(BitList other)
represents the result of this bit list logically ANDed with the other


asArray

public boolean[] asArray()


asBigInteger

public java.math.BigInteger asBigInteger()


asBitSet

public java.util.BitSet asBitSet()
nb: BitSet forgets the length


asByteList

public java.util.List asByteList()


asBytes

public byte[] asBytes()
returns the bits converted to bytes, with least significant bit first *and* first 8 bits in the first byte

NB this may be different to BitSet.valueOf available since java 7 (as late as that!) which reverses the order of the bytes


asList

public java.util.List asList()


asUnsignedBytes

public int[] asUnsignedBytes()


byteValue

public byte byteValue()
returns value of this as a byte(ignoring any too-high bits)


commonPrefixLength

public int commonPrefixLength(BitList other)


equals

@Override
public boolean equals(java.lang.Object obj)


get

public boolean get(int index)


hashCode

@Override
public int hashCode()


intValue

public int intValue()
returns value of this as an integer (ignoring any too-high bits)


isEmpty

public boolean isEmpty()
true iff the length is 0; see also isZero


isZero

public boolean isZero()
true iff all bits are 0


length

public int length()


longValue

public long longValue()
returns value of this as a long (ignoring any too-high bits)


newInstance

public static BitList newInstance(java.util.BitSet bits, int length)


newInstance

public static BitList newInstance(byte... bytes)


newInstance

public static BitList newInstance(java.util.List l)


newInstance

public static BitList newInstance(boolean... l)


newInstance

public static BitList newInstance(java.math.BigInteger x)


newInstanceFromBytes

public static BitList newInstanceFromBytes(int... bytes)
as newInstance(byte...), but accepting ints for convenience; only the least significant 8 bits of the parameters are considered


notted

public BitList notted()
represents the result of this bit list logically notted


orred

public BitList orred(BitList other)
represents the result of this bit list logically ORred with the other


resized

public BitList resized(int length)
creates a new instance with the given length, either reducing the list or padding it with 0's (at the end, in both cases)


reversed

public BitList reversed()


toString

@Override
public java.lang.String toString()


xorred

public BitList xorred(BitList other)
represents the result of this bit list logically XORred with the other


 

Brooklyn Multi-Cloud Application Management Platform
brooklyncentral.github.com. Apache License. © 2012.