Example usage for java.util BitSet BitSet

List of usage examples for java.util BitSet BitSet

Introduction

In this page you can find the example usage for java.util BitSet BitSet.

Prototype

public BitSet() 

Source Link

Document

Creates a new bit set.

Usage

From source file:org.apache.hawq.pxf.service.utilities.AnalyzeUtils.java

/**
 * Marks sampleSize bits out of the poolSize, in a uniform way.
 *
 * @param poolSize pool size//from   w  w w.ja v  a2  s.c  o m
 * @param sampleSize sample size
 * @return bit set with sampleSize bits set out of poolSize.
 */
static public BitSet generateSamplingBitSet(int poolSize, int sampleSize) {

    int skip = 0, chosen = 0, curIndex = 0;
    BitSet bitSet = new BitSet();

    if (poolSize <= 0 || sampleSize <= 0) {
        return bitSet;
    }

    if (sampleSize >= poolSize) {
        LOG.debug("sampling bit map has " + poolSize + " elements (100%)");
        bitSet.set(0, poolSize);
        return bitSet;
    }

    skip = (poolSize / sampleSize) + 1;

    while (chosen < sampleSize) {

        bitSet.set(curIndex);
        chosen++;
        if (chosen == sampleSize) {
            break;
        }

        for (int i = 0; i < skip; ++i) {
            curIndex = nextClearBitModulo((++curIndex) % poolSize, poolSize, bitSet);
            if (curIndex == -1) {
                // should never happen
                throw new IllegalArgumentException("Trying to sample more than pool size " + "(pool size "
                        + poolSize + ", sampling size " + sampleSize);
            }
        }
    }

    LOG.debug("sampling bit map has " + chosen + " elements:" + bitSet.toString());

    return bitSet;
}

From source file:com.palominolabs.crm.sf.rest.PicklistEntry.java

@JsonCreator
PicklistEntry(@JsonProperty("value") String value, @JsonProperty("active") boolean active,
        @JsonProperty("label") String label, @JsonProperty("defaultValue") boolean defaultValue,
        @Nullable @JsonProperty("validFor") String validFor) {
    this.value = value;
    this.active = active;
    this.label = label;
    this.defaultValue = defaultValue;

    if (validFor == null) {
        this.validFor = new ImmutableBitSet(new BitSet());
    } else {//from   w  w  w .  j  a v  a 2 s  . com
        //validFor is in base64
        Base64 base64 = new Base64();

        byte[] decoded = base64.decode(validFor);

        this.validFor = ImmutableBitSets.parseValidForBytes(decoded);
    }
}

From source file:org.apache.kylin.cube.cuboid.algorithm.ITGeneticAlgorithmTest.java

@Test
public void testChromosomeIsSame() {
    BenefitPolicy benefitPolicy = new BPUSCalculator(cuboidStats);

    double maxSpaceLimit = cuboidStats.getBaseCuboidSize() * 10;
    BitsChromosomeHelper helper = new BitsChromosomeHelper(maxSpaceLimit, cuboidStats);

    double maxSpaceLimit1 = cuboidStats.getBaseCuboidSize() * 12;
    BitsChromosomeHelper helper1 = new BitsChromosomeHelper(maxSpaceLimit1, cuboidStats);

    BitSet representation = new BitSet();
    representation.set(10);/*from  ww  w.ja v a2 s .  c  o  m*/
    Chromosome chromosome = new BitsChromosome(representation, benefitPolicy, helper);
    Set<Chromosome> chromosomeSet = Sets.newHashSet(chromosome);

    BitSet representation1 = new BitSet();
    representation1.set(10);
    chromosomeSet.add(((BitsChromosome) chromosome).newBitsChromosome(representation1));
    assertEquals(1, chromosomeSet.size());

    BitSet representation2 = new BitSet();
    representation2.set(12);
    chromosomeSet.add(((BitsChromosome) chromosome).newBitsChromosome(representation2));
    assertEquals(2, chromosomeSet.size());

    BitSet representation3 = new BitSet();
    representation3.set(12);
    chromosomeSet.add(new BitsChromosome(representation3, benefitPolicy, helper1));
    assertEquals(2, chromosomeSet.size());
}

From source file:net.bioclipse.cdk.ui.sdfeditor.CDKFingerPrintPropertyCalculator.java

public BitSet parse(String value) {
    // TODO check if this is right
    byte[] bytes = new Base64().decode(value.getBytes());
    BitSet set = new BitSet();
    for (int i = 0; i < bytes.length * 8; i++) {
        if ((bytes[bytes.length - i / 8 - 1] & (1 << (i % 8))) > 0) {
            set.set(i);/*from   ww  w.  j  a v a2  s. co  m*/
        }
    }
    return set;
}

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  a va  2 s.  co m
 * @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:TypeConversionHelper.java

/**
 * Convert a boolean[] into an instance of our value class.
 *
 * @param buf boolean array to be converted
 *
 * @return converted boolean array as BitSet
 *///from  w  w  w .j  a  v a  2s  .  c  om
public static BitSet getBitSetFromBooleanArray(boolean[] buf) {
    BitSet set = new BitSet();
    for (int i = 0; i < buf.length; i++) {
        if (buf[i]) {
            set.set(i);
        }
    }

    return set;
}

From source file:org.apache.kylin.cube.gridtable.CuboidToGridTableMappingExt.java

private void init() {
    dynGtDataTypes = Lists.newArrayList();
    dynGtColBlocks = Lists.newArrayList();
    dynDim2gt = Maps.newHashMap();// w  w w  .  j av  a 2 s.  com
    dynMetrics2gt = Maps.newHashMap();

    int gtColIdx = super.getColumnCount();

    BitSet rtColBlock = new BitSet();
    // dynamic dimensions
    for (TblColRef rtDim : dynDims) {
        dynDim2gt.put(rtDim, gtColIdx);
        dynGtDataTypes.add(rtDim.getType());
        rtColBlock.set(gtColIdx);
        gtColIdx++;
    }
    dynamicDims = new ImmutableBitSet(rtColBlock);

    // dynamic metrics
    for (DynamicFunctionDesc rtFunc : dynFuncs) {
        dynMetrics2gt.put(rtFunc, gtColIdx);
        dynGtDataTypes.add(rtFunc.getReturnDataType());
        rtColBlock.set(gtColIdx);
        gtColIdx++;
    }

    dynGtColBlocks.add(new ImmutableBitSet(rtColBlock));
}

From source file:org.openhab.binding.satel.internal.protocol.command.ControlObjectCommand.java

/**
 * {@inheritDoc}//  w  w w. j a  v  a 2s .c  o  m
 */
@Override
public void handleResponse(SatelMessage response) {
    if (commandSucceeded(response)) {
        // force outputs refresh
        BitSet newStates = new BitSet();
        // TODO generalize for all kinds of control
        if (this.controlType instanceof OutputControl) {
            newStates.set(OutputState.OUTPUT.getRefreshCommand());
            this.getEventDispatcher().dispatchEvent(new NewStatesEvent(newStates));
        }
    }
}

From source file:ws.moor.bt.util.ByteUtil.java

public static BitSet toBitSet(byte[] bytes) {
    BitSet result = new BitSet();
    for (int i = 0; i < bytes.length * 8; i++) {
        if ((bytes[i / 8] & (1 << (7 - (i % 8)))) != 0) {
            result.set(i);//from  w  w w  . ja  v  a2  s .c  o m
        }
    }
    return result;
}

From source file:mastodon.algorithms.MHLinearAlgorithm.java

protected void initialize() {
    if (minPrunedSpeciesCount == maxPrunedSpeciesCount) {
        stub = "MH Cons.";
    } else {//from   w  w w  .  ja v a2 s.co  m
        stub = "MH Lin.";
    }

    pruningFreq = new HashMap<Integer, Integer>();
    for (int i = 0; i < bts.getTaxaCount(); i++) {
        pruningFreq.put(i, 0);
    }

    currPrunedSpeciesCount = minPrunedSpeciesCount;
    maxScorePruning = new HashMap<BitSet, double[]>();
    currPruning = new BitSet();

    for (int i = 0; i < currPrunedSpeciesCount; i++) {
        int choice = 0;
        do {
            choice = (int) (Random.nextDouble() * bts.getTaxaCount());
        } while (currPruning.get(choice));
        currPruning.set(choice);
    }
    prevPruning = (BitSet) currPruning.clone();

    prevScore = bts.pruneFast(currPruning);
    bts.unPrune();
    maxScore = prevScore.clone();
    maxScorePruning.put(prevPruning, maxScore);

    double mean = 1.0; //needed when pruning 1 taxon (can't have a mean of 0 in PoissonDistribution())
    if (currPrunedSpeciesCount > 1) {
        mean = 0.5 * (currPrunedSpeciesCount - 1);
    }
    pd = new PoissonDistribution(mean);

    setupIterations();

    iterationCounter = 0;
}