org.limewire.collection
Class XorView
java.lang.Object
org.limewire.collection.XorView
- All Implemented Interfaces:
- BitField
public class XorView
- extends Object
Provides an XOR view. XorView gets and finds the next set
(equal to 1) and clear (equal to 0) bit starting at a specific location.
See exclusive or
for more information.
void sampleCodeXorView(){
BitSet bs1 = new BitSet();
bs1.set(0);
bs1.set(1);
BitSet bs2 = new BitSet();
bs2.set(0);
bs2.set(2);
BitField bf1 = new BitFieldSet(bs1, 5);
BitField bf2 = new BitFieldSet(bs2, 5);
printBitField(bf1, "bf1");
printBitField(bf2, "bf2");
XorView xov = new XorView(bf1, bf2);
printBitField(xov, "xov");
}
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:
bf1: 11000
bf2: 10100
xov: 01100
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
fields
protected final BitField[] fields
XorView
public XorView(BitField first,
BitField... more)
get
public boolean get(int i)
nextClearBit
public int nextClearBit(int startIndex)
nextSetBit
public int nextSetBit(int startIndex)
- Returns:
- index of next set bit from index
i or -1 if there is no bit left
maxSize
public int maxSize()
- Specified by:
maxSize in interface BitField
cardinality
public int cardinality()
- Specified by:
cardinality in interface BitField
Copyright © 2008 Lime Wire LLC. All Rights Reserved.