List of usage examples for java.util BitSet length
public int length()
From source file:org.efaps.admin.datamodel.attributetype.BitEnumType.java
/** * @param _bitIndex bitindex the integer value is wanted for * @return integer value representing the bitindex *//*from w w w . j av a 2s.co m*/ public static int getInt4Index(final int _bitIndex) { final BitSet bitSet = new BitSet(_bitIndex + 1); bitSet.set(_bitIndex); int ret = 0; for (int i = 0; i < bitSet.length(); ++i) { ret += bitSet.get(i) ? 1 << i : 0; } return ret; }
From source file:mobisocial.musubi.ui.FeedListActivity.java
public static byte[] toByteArray(BitSet bits) { byte[] bytes = new byte[bits.length() / 8 + 1]; for (int i = 0; i < bits.length(); i++) { if (bits.get(i)) { bytes[bytes.length - i / 8 - 1] |= 1 << (i % 8); }/*from w w w . j a va 2 s .co m*/ } return bytes; }
From source file:jBittorrentAPI.utils.Utils.java
public static byte[] toByteArray(BitSet bits) { byte[] bytes = new byte[bits.length() / 8 + 1]; for (int i = 0; i < bits.length(); i++) { if (bits.get(i)) { bytes[i / 8] |= 1 << (7 - i % 8); }/*from www . ja va 2s .co m*/ } return bytes; }
From source file:net.bioclipse.cdk.ui.sdfeditor.CDKFingerPrintPropertyCalculator.java
public String toString(Object value) { // TODO check if this is right BitSet val = (BitSet) value; byte[] bytes = new byte[val.length() / 8 + 1]; for (int i = 0; i < val.length(); i++) { if (val.get(i)) { bytes[bytes.length - i / 8 - 1] |= 1 << (i % 8); }/*from ww w . j a v a 2 s. c o m*/ } return new String(new Base64().encode(bytes)); }
From source file:TypeConversionHelper.java
/** * Convert an instance of our value class into a boolean[]. * * @param value Object to be converted/*from www . ja v a 2 s . c om*/ * * @return converted boolean array */ public static boolean[] getBooleanArrayFromBitSet(BitSet value) { if (value == null) { return null; } boolean[] a = new boolean[value.length()]; for (int i = 0; i < a.length; i++) { a[i] = value.get(i); } return a; }
From source file:org.apache.metron.stellar.common.utils.hashing.tlsh.TLSHHasher.java
public Map<String, String> bin(String hash) throws DecoderException { Random r = new Random(0); byte[] h = Hex.decodeHex(hash.substring(2 * checksumOption.getChecksumLength()).toCharArray()); BitSet vector = BitSet.valueOf(h); int n = vector.length(); Map<String, String> ret = new HashMap<>(); boolean singleHash = hashes.size() == 1; for (int numHashes : hashes) { BitSet projection = new BitSet(); for (int i = 0; i < numHashes; ++i) { int index = r.nextInt(n); projection.set(i, vector.get(index)); }/*from w ww .ja v a 2 s . c om*/ String outputHash = numHashes + Hex.encodeHexString(projection.toByteArray()); if (singleHash) { ret.put(TLSH_BIN_KEY, outputHash); } else { ret.put(TLSH_BIN_KEY + "_" + numHashes, outputHash); } } return ret; }
From source file:org.apache.eagle.alert.engine.serialization.PartitionedEventSerializerTest.java
@Test public void testBitSet() { BitSet bitSet = new BitSet(); bitSet.set(0, true); // 1 bitSet.set(1, false); // 0 bitSet.set(2, true); // 1 LOG.info("Bit Set Size: {}", bitSet.size()); LOG.info("Bit Set Byte[]: {}", bitSet.toByteArray()); LOG.info("Bit Set Byte[]: {}", bitSet.toLongArray()); LOG.info("BitSet[0]: {}", bitSet.get(0)); LOG.info("BitSet[1]: {}", bitSet.get(1)); LOG.info("BitSet[1]: {}", bitSet.get(2)); byte[] bytes = bitSet.toByteArray(); BitSet bitSet2 = BitSet.valueOf(bytes); LOG.info("Bit Set Size: {}", bitSet2.size()); LOG.info("Bit Set Byte[]: {}", bitSet2.toByteArray()); LOG.info("Bit Set Byte[]: {}", bitSet2.toLongArray()); LOG.info("BitSet[0]: {}", bitSet2.get(0)); LOG.info("BitSet[1]: {}", bitSet2.get(1)); LOG.info("BitSet[1]: {}", bitSet2.get(2)); BitSet bitSet3 = new BitSet(); bitSet3.set(0, true);//from ww w .j a va 2 s . c o m Assert.assertEquals(1, bitSet3.length()); BitSet bitSet4 = new BitSet(); bitSet4.set(0, false); Assert.assertEquals(0, bitSet4.length()); Assert.assertFalse(bitSet4.get(1)); Assert.assertFalse(bitSet4.get(2)); }
From source file:at.tuwien.mnsa.smssender.SMSPDUConverter.java
private BitSet leftShiftBitset(BitSet bitset, int positions) { return bitset.get(positions, Math.max(positions, bitset.length())); }
From source file:at.tuwien.mnsa.smssender.SMSPDUConverter.java
/** * Right shift a bitset//from w w w . java2s . co m * @param bitset * @param positions * @return */ private BitSet rightShiftBitset(BitSet bitset, int positions) { for (int j = 0; j < positions; j++) { for (int i = bitset.length(); i > 0; i--) { bitset.set(i, bitset.get(i - 1)); } bitset.set(j, false); } return bitset; }
From source file:com.google.uzaygezen.core.BitSetBackedBitVector.java
@Override public void copyFrom(BitSet from) { Preconditions.checkArgument(from.length() <= size, "bit set is too large"); bitset.clear();/* w w w.j a v a 2 s . co m*/ bitset.or(from); }