org.limewire.collection
Interface BitField
- All Known Implementing Classes:
- AndView, BitFieldSet, NandView, NorView, NotView, OrView, XorView
public interface BitField
Defines the interface to manipulate a fixed size field of bits.
BitField declares methods to return the location where a bit
is either set (equal to 1) or clear (equal to 0). The BitField
interface has a methods for returning the bit value at a particular location
and the maximum size of the field of bits.
Also, BitField has a
cardinality method for working with sets.
BitFieldSet, AndView, OrView, XorView and
NotView implement BitField. The subclasses perform
various operations on the bits.
void sampleCodeBitField(){
BitSet bs = new BitSet();
bs.set(3);
bs.set(1);
BitField completed = new BitFieldSet(bs, 64);
NotView uncompleted = new NotView(completed);
printBitField(completed, " completed");
printBitField(uncompleted, "uncompleted");
System.out.println("Completed " + completed.cardinality() + " out of " + completed.maxSize() + " tasks.");
System.out.println("Uncompleted tasks: " + new NotView(completed).cardinality() + ".");
}
void printBitField(BitField bf, String bfName){
System.out.print(bfName + ": ");
for(int i = 0; i < bf.maxSize(); i++){
int j = 0;
if(bf.get(i))
j = 1;
System.out.print(j);
}
System.out.println("");
}
Output:
completed: 0101000000000000000000000000000000000000000000000000000000000000
uncompleted: 1010111111111111111111111111111111111111111111111111111111111111
Completed 2 out of 64 tasks.
Uncompleted tasks: 62.
get
boolean get(int i)
nextSetBit
int nextSetBit(int i)
- Returns:
- index of next set bit from index
i or -1 if there is no bit left
nextClearBit
int nextClearBit(int i)
cardinality
int cardinality()
maxSize
int maxSize()
Copyright © 2008 Lime Wire LLC. All Rights Reserved.