本文整理汇总了Java中java.util.BitSet.valueOf方法的典型用法代码示例。如果您正苦于以下问题:Java BitSet.valueOf方法的具体用法?Java BitSet.valueOf怎么用?Java BitSet.valueOf使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.BitSet
的用法示例。
在下文中一共展示了BitSet.valueOf方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: DeviceStatus
import java.util.BitSet; //导入方法依赖的package包/类
public DeviceStatus(byte[] paramArrayOfByte)
{
if (paramArrayOfByte.length == 0) {
Timber.d("DeviceStatus: all status values were zero");
this.riderDetected = false;
this.riderDetectPad1 = false;
this.riderDetectPad2 = false;
this.icsuFault = false;
this.icsvFault = false;
this.charging = false;
this.bmsCtrlComms = false;
this.brokenCapacitor = false;
return;
}
byte[] arrayOfByte = new byte[1];
arrayOfByte[0] = paramArrayOfByte[0];
BitSet localBitSet = BitSet.valueOf(arrayOfByte);
this.riderDetected = localBitSet.get(0);
this.riderDetectPad1 = localBitSet.get(1);
this.riderDetectPad2 = localBitSet.get(2);
this.icsuFault = localBitSet.get(3);
this.icsvFault = localBitSet.get(4);
this.charging = localBitSet.get(5);
this.bmsCtrlComms = localBitSet.get(6);
this.brokenCapacitor = localBitSet.get(7);
}
示例2: changePositon2
import java.util.BitSet; //导入方法依赖的package包/类
@Test
public void changePositon2(){
BitSet bitm =new BitSet(16);
bitm.set(6);
bitm.set(5);
System.out.println(bitm);
long[] lo = bitm.toLongArray();
if(lo.length > 0){
for(int j=0;j<lo.length - 1;j++){
lo[j] = lo[j] >>> 1;
lo[j] = lo[j] | (lo[j+1] << 63);
}
lo[lo.length-1] = lo[lo.length-1] >>> 1;
}
bitm = BitSet.valueOf(lo);
System.out.println(bitm.size());
System.out.println(bitm);
}
示例3: testRandomStream
import java.util.BitSet; //导入方法依赖的package包/类
@Test
public void testRandomStream() {
final int size = 1024 * 1024;
final int[] seeds = {
2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41,
43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97};
final byte[] bytes = new byte[size];
for (int seed : seeds) {
final Random random = new Random(seed);
random.nextBytes(bytes);
final BitSet bitSet = BitSet.valueOf(bytes);
final int cardinality = bitSet.cardinality();
final IntStream stream = bitSet.stream();
final int[] array = stream.toArray();
assertEquals(array.length, cardinality);
int nextSetBit = -1;
for (int i=0; i < cardinality; i++) {
nextSetBit = bitSet.nextSetBit(nextSetBit + 1);
assertEquals(array[i], nextSetBit);
}
}
}
示例4: testRandomStream
import java.util.BitSet; //导入方法依赖的package包/类
@Test
public void testRandomStream() {
final int size = 1024 * 1024;
final int[] seeds = {
2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41,
43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97};
final byte[] bytes = new byte[size];
for (int seed : seeds) {
final Random random = new Random(seed);
random.nextBytes(bytes);
BitSet bitSet = BitSet.valueOf(bytes);
testBitSetContents(bitSet, bitSet.stream().toArray());
testBitSetContents(bitSet, bitSet.stream().parallel().toArray());
}
}
示例5: read
import java.util.BitSet; //导入方法依赖的package包/类
@Override
public ChunkPositionSet read(DataInputStream stream) throws IOException {
long[] data = new long[stream.readShort()];
for (int i = 0; i < data.length; i++) {
data[i] = stream.readLong();
}
return new ChunkPositionSet(BitSet.valueOf(data));
}
示例6: testNot
import java.util.BitSet; //导入方法依赖的package包/类
@Test
public void testNot() {
BloomFilter bf = new BloomFilter(8, 1, Hash.JENKINS_HASH);
bf.bits = BitSet.valueOf(new byte[] { (byte) 0x95 });
BitSet origBitSet = (BitSet) bf.bits.clone();
bf.not();
assertFalse("BloomFilter#not should have inverted all bits",
bf.bits.intersects(origBitSet));
}
示例7: SynopsisHashMapAllDump
import java.util.BitSet; //导入方法依赖的package包/类
/**
* Hot word attenuation in hot words
*/
public void SynopsisHashMapAllDump(DumpRemoveHandler dumpRemoveHandler) {
int dumpsize = (int) (1 / Threshold_p);
dumpKeyCount++;
if (dumpKeyCount == dumpsize) {
//dump all key
Iterator<Map.Entry<String, BitSet>> iterator = predictHotKeyMap.newEntryIterator();
while (iterator.hasNext()){
Map.Entry<String, BitSet> next = iterator.next();
BitSet bitm = next.getValue();
String key = next.getKey();
if(key!=null){
long[] lo = bitm.toLongArray();
if(lo.length > 0){
for(int j=0;j<lo.length - 1;j++){
lo[j] = lo[j] >>> 1;
lo[j] = lo[j] | (lo[j+1] << 63);
}
lo[lo.length-1] = lo[lo.length-1] >>> 1;
}
bitm = BitSet.valueOf(lo);
if (bitm.isEmpty()) {
iterator.remove();
dumpRemoveHandler.dumpRemove(key);
}else
next.setValue(bitm);
}
}
dumpKeyCount = 0;
}
}
示例8: SynopsisHashMapRandomDump
import java.util.BitSet; //导入方法依赖的package包/类
/**
* New Words in Hot Words Random Dump
*/
public void SynopsisHashMapRandomDump(DumpRemoveHandler dumpRemoveHandler) {
int size=predictHotKeyMap.size;
long startTimeSystemTime=System.currentTimeMillis();
Iterator<Map.Entry<String, BitSet>> iterator = predictHotKeyMap.newEntryIterator();
while (iterator.hasNext()){
Map.Entry<String, BitSet> next = iterator.next();
if (random.nextDouble()> Threshold_p){
continue;
}
BitSet bitm = next.getValue();
String key = next.getKey();
if(key!=null){
long[] lo = bitm.toLongArray();
if(lo.length > 0){
for(int j=0;j<lo.length - 1;j++){
lo[j] = lo[j] >>> 1;
lo[j] = lo[j] | (lo[j+1] << 63);
}
lo[lo.length-1] = lo[lo.length-1] >>> 1;
}
bitm = BitSet.valueOf(lo);
if (bitm.isEmpty()) {
iterator.remove();
dumpRemoveHandler.dumpRemove(key);
}else
next.setValue(bitm);
}
}
}
示例9: decodeImpl
import java.util.BitSet; //导入方法依赖的package包/类
@Override
protected Codex<V, E> decodeImpl(ByteBuffer pData) {
int length = pData.remaining();
int initPos = pData.position();
// reference BitSet.toByteArray() for this calculation
byte[] bsarray = new byte[mBitSetByteLength];
pData.get(bsarray);
BitSet hash = BitSet.valueOf(bsarray);
hash.set(mLength);
mLog.debug("Bitset: " + Arrays.toString(bsarray));
// Usually the offset is 0, but with UDP connections it's non-zero.
pData.position(bsarray.length + initPos + pData.arrayOffset());
V[] decoded = mProps.generateEmptyArray((length - bsarray.length) / mProps.sizeOfSingle(), false);
for(int i = 0; i < decoded.length; i++) {
decoded[i] = mProps.decodeSingle(pData);
}
// Codex<V, E> result = new Codex<V, E>(this);
Codex<V, E> result = new Codex<V, E>(getDefaultValue(), super.getEnum());
int dataidx = 0;
for(int e = 0; e < mLength; e++) {
if(hash.get(e)) {
result.set(e, decoded[dataidx]);
dataidx++;
}
}
return result;
}
示例10: decodeImpl
import java.util.BitSet; //导入方法依赖的package包/类
@Override
protected Codex<Boolean, E> decodeImpl(ByteBuffer pData) {
// reference BitSet.toByteArray() for this calculation
byte[] bsarray = new byte[getBufferSizeInBytes()];
pData.get(bsarray);
BitSet hash = BitSet.valueOf(bsarray);
hash.set(mLength);
// Codex<Boolean, E> result = new Codex<>(this);
Codex<Boolean, E> result = new Codex<>(super.getEnum());
for(int i = 0; i < mLength; i++) {
result.set(i, hash.get(i));
}
return result;
}
示例11: readRecordHeader
import java.util.BitSet; //导入方法依赖的package包/类
private BitSet readRecordHeader() throws IOException {
byte[] header = in.readByteArray();
BitSet bitSet = BitSet.valueOf(header);
return bitSet;
}
示例12: BloomFilter
import java.util.BitSet; //导入方法依赖的package包/类
public BloomFilter(byte[] bloomMask) {
if (bloomMask.length != BLOOM_BYTES) throw new RuntimeException("Invalid bloom filter array length: " + bloomMask.length);
mask = BitSet.valueOf(bloomMask);
}
示例13: checkBitSet
import java.util.BitSet; //导入方法依赖的package包/类
private void checkBitSet(byte[] array) {
BitSet bitSet = BitSet.valueOf(array);
assertArrayEquals(array, Bytes.from(bitSet).array());
assertEquals(bitSet, Bytes.from(bitSet).toBitSet());
}
示例14: FLG
import java.util.BitSet; //导入方法依赖的package包/类
private FLG(int version, byte b) {
this.bitSet = BitSet.valueOf(new byte[]{b});
this.version = version;
validate();
}
示例15: next
import java.util.BitSet; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override public BitSet next() {
BitSet res = BitSet.valueOf(new long[] {i});
i++;
return res;
}