List of usage examples for java.util BitSet get
public boolean get(int bitIndex)
From source file:ezbake.deployer.impl.Files.java
public static Set<PosixFilePermission> convertTarArchiveEntryModeToPosixFilePermissions(int mode) { Set<PosixFilePermission> permissions = Sets.newHashSet(); BitSet bs = BitSet.valueOf(new long[] { mode }); if (bs.get(PosixFilePermission.OTHERS_EXECUTE.ordinal())) { permissions.add(PosixFilePermission.OTHERS_EXECUTE); }/* ww w .ja v a 2 s . c om*/ if (bs.get(PosixFilePermission.OTHERS_WRITE.ordinal())) { permissions.add(PosixFilePermission.OTHERS_WRITE); } if (bs.get(PosixFilePermission.OTHERS_READ.ordinal())) { permissions.add(PosixFilePermission.OTHERS_READ); } if (bs.get(PosixFilePermission.GROUP_EXECUTE.ordinal())) { permissions.add(PosixFilePermission.GROUP_EXECUTE); } if (bs.get(PosixFilePermission.GROUP_WRITE.ordinal())) { permissions.add(PosixFilePermission.GROUP_WRITE); } if (bs.get(PosixFilePermission.GROUP_READ.ordinal())) { permissions.add(PosixFilePermission.GROUP_READ); } if (bs.get(PosixFilePermission.OWNER_EXECUTE.ordinal())) { permissions.add(PosixFilePermission.OWNER_EXECUTE); } if (bs.get(PosixFilePermission.OWNER_WRITE.ordinal())) { permissions.add(PosixFilePermission.OWNER_WRITE); } if (bs.get(PosixFilePermission.OWNER_READ.ordinal())) { permissions.add(PosixFilePermission.OWNER_READ); } return permissions; }
From source file:com.roche.sequencing.bioinformatics.common.utils.BitSetUtil.java
/** * combine a variable number of bitsets of the same length * //from w w w . j av a 2 s. com * @param length * @param bitsets * @return */ public static BitSet combine(int length, BitSet... bitsets) { BitSet combinedBitSet = new BitSet(); int currentBitset = 0; for (BitSet bitset : bitsets) { for (int i = 0; i < length; i++) { if (bitset.get(i)) { combinedBitSet.set((currentBitset * length) + i); } } currentBitset++; } return combinedBitSet; }
From source file:com.roche.sequencing.bioinformatics.common.utils.BitSetUtil.java
/** * @param bits/*from w w w.j av a2s.c om*/ * @return the bitset as a string */ public static String getBinaryStringOfBits(BitSet bits, int size) { StringBuilder returnString = new StringBuilder(); for (int i = 0; i < size; i++) { if (bits.get(i)) { returnString.append("1"); } else { returnString.append("0"); } if (i > 0 && i % ByteUtil.BITS_PER_BYTE == 0) { returnString.append(" "); } } return returnString.toString(); }
From source file:org.apache.hawq.pxf.service.utilities.AnalyzeUtils.java
/** * In case pxf_max_fragments parameter is declared, make sure not to get * over the limit. The returned fragments are evenly distributed, in order * to achieve good sampling.//from w w w .j a v a 2s . c o m * * @param fragments fragments list * @param protData container for parameters, including sampling data. * @return a list of fragments no bigger than pxf_max_fragments parameter. */ static public List<Fragment> getSampleFragments(List<Fragment> fragments, ProtocolData protData) { int listSize = fragments.size(); int maxSize = protData.getStatsMaxFragments(); List<Fragment> samplingList = new ArrayList<Fragment>(); BitSet bitSet; if (maxSize == 0) { return fragments; } LOG.debug("fragments list has " + listSize + " fragments, maxFragments = " + maxSize); bitSet = generateSamplingBitSet(listSize, maxSize); for (int i = 0; i < listSize; ++i) { if (bitSet.get(i)) { samplingList.add(fragments.get(i)); } } return samplingList; }
From source file:Main.java
private static String urlencode(final String content, final Charset charset, final BitSet safechars, final boolean blankAsPlus) { if (content == null) { return null; }/*from w w w.j a v a 2 s .c om*/ StringBuilder buf = new StringBuilder(); ByteBuffer bb = charset.encode(content); while (bb.hasRemaining()) { int b = bb.get() & 0xff; if (safechars.get(b)) { buf.append((char) b); } else if (blankAsPlus && b == ' ') { buf.append('+'); } else { buf.append("%"); char hex1 = Character.toUpperCase(Character.forDigit((b >> 4) & 0xF, RADIX)); char hex2 = Character.toUpperCase(Character.forDigit(b & 0xF, RADIX)); buf.append(hex1); buf.append(hex2); } } return buf.toString(); }
From source file:com.roche.sequencing.bioinformatics.common.utils.BitSetUtil.java
/** * @param bits/*ww w . jav a 2 s. co m*/ * @return the bitset as a string */ public static String getBinaryStringOfBits(BitSet bitset, int start, int endInclusive) { StringBuilder returnString = new StringBuilder(); for (int i = start; i <= endInclusive; i++) { if (bitset.get(i)) { returnString.append("1"); } else { returnString.append("0"); } if (i > 0 && i % ByteUtil.BITS_PER_BYTE == 0) { returnString.append(" "); } } return returnString.toString(); }
From source file:com.roche.sequencing.bioinformatics.common.utils.BitSetUtil.java
/** * // ww w .j a v a 2 s. co m * @param fromBitSet * @param fromBitSetLength * @param toBitSet * @param toBitsetStartInBits * @return the number of bits written */ public static int copy(BitSet fromBitSet, int fromBitSetLength, BitSet toBitSet, int toBitsetStartInBits) { for (int fromBitIndex = 0; fromBitIndex < fromBitSetLength; fromBitIndex++) { boolean isBitOn = fromBitSet.get(fromBitIndex); int toBitIndex = toBitsetStartInBits + fromBitIndex; toBitSet.set(toBitIndex, isBitOn); } return fromBitSetLength; }
From source file:com.roche.sequencing.bioinformatics.common.utils.BitSetUtil.java
/** * // w w w . j a va 2s .com * @param fromBitSet * @param fromBitSetLengthInBits * @param toBitSet * @param toBitsetStartInBits * @return the number of bits written */ public static int copy(BitSet fromBitSet, int fromBitSetLengthInBits, LargeBitSet toBitSet, long toBitsetStartInBits) { for (int fromBitIndex = 0; fromBitIndex < fromBitSetLengthInBits; fromBitIndex++) { boolean isBitOn = fromBitSet.get(fromBitIndex); long toBitIndex = toBitsetStartInBits + ((long) fromBitIndex); toBitSet.set(toBitIndex, isBitOn); } return fromBitSetLengthInBits; }
From source file:HexUtil.java
/** * Pack the bits in ba into a byte[].//from ww w .j a va 2 s. c om * * @param ba : the BitSet * @param size : How many bits shall be taken into account starting from the LSB? */ public final static byte[] bitsToBytes(BitSet ba, int size) { int bytesAlloc = countBytesForBits(size); byte[] b = new byte[bytesAlloc]; StringBuilder sb = null; for (int i = 0; i < b.length; i++) { short s = 0; for (int j = 0; j < 8; j++) { int idx = i * 8 + j; boolean val = idx > size - 1 ? false : ba.get(idx); s |= val ? (1 << j) : 0; } if (s > 255) throw new IllegalStateException("WTF? s = " + s); b[i] = (byte) s; } return b; }
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); }/* w w w. j ava 2s. c o m*/ } return bytes; }