Example usage for java.util BitSet nextSetBit

List of usage examples for java.util BitSet nextSetBit

Introduction

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

Prototype

public int nextSetBit(int fromIndex) 

Source Link

Document

Returns the index of the first bit that is set to true that occurs on or after the specified starting index.

Usage

From source file:Main.java

public static void main(String[] args) {

    BitSet bitset1 = new BitSet(8);
    BitSet bitset2 = new BitSet(8);

    // assign values to bitset1
    bitset1.set(0);/*from   w ww  .  j  av a 2 s. co  m*/
    bitset1.set(1);

    // assign values to bitset2
    bitset2.set(2);
    bitset2.set(4);

    // print the sets
    System.out.println("Bitset1:" + bitset1);
    System.out.println("Bitset2:" + bitset2);

    // print the first set bit of bitset1
    System.out.println(bitset1.nextSetBit(0));

    // print the first set bit of bitset2 after index 5
    System.out.println(bitset2.nextSetBit(5));
}

From source file:Main.java

public static byte[] toByteArray(BitSet bitSet) {
    byte[] array = new byte[bitSet.size() / 8 + 1];

    for (int i = bitSet.nextSetBit(0); i >= 0; i = bitSet.nextSetBit(i + 1)) {
        array[i / 8] |= byteMask(i);/* w  w  w.jav a2s . c  om*/
    }

    return array;
}

From source file:fr.inria.lille.repair.nopol.NoPolLauncher.java

private static void displayResult(NoPol nopol, List<Patch> patches, long executionTime) {
    System.out.println("----INFORMATION----");
    List<CtType<?>> allClasses = nopol.getSpooner().spoonFactory().Class().getAll();
    int nbMethod = 0;
    for (int i = 0; i < allClasses.size(); i++) {
        CtType<?> ctSimpleType = allClasses.get(i);
        if (ctSimpleType instanceof CtClass) {
            Set methods = ((CtClass) ctSimpleType).getMethods();
            nbMethod += methods.size();//from  w  w w.j  ava 2s . c  om
        }
    }
    System.out.println("Nb classes : " + allClasses.size());
    System.out.println("Nb methods : " + nbMethod);
    BitSet coverage = NoPol.currentStatement.getCoverage();
    int countStatementSuccess = 0;
    int countStatementFailed = 0;
    int nextTest = coverage.nextSetBit(0);
    while (nextTest != -1) {
        TestResult testResult = nopol.getgZoltar().getGzoltar().getTestResults().get(nextTest);
        if (testResult.wasSuccessful()) {
            countStatementSuccess += testResult.getCoveredComponents().size();
        } else {
            countStatementFailed += testResult.getCoveredComponents().size();
        }
        nextTest = coverage.nextSetBit(nextTest + 1);
    }
    System.out
            .println("Nb statements: " + nopol.getgZoltar().getGzoltar().getSpectra().getNumberOfComponents());
    System.out.println(
            "Nb statement executed by the passing tests of the patched line: " + countStatementSuccess);
    System.out
            .println("Nb statement executed by the failing tests of the patched line: " + countStatementFailed);
    System.out.println("Nb unit tests : " + nopol.getgZoltar().getGzoltar().getTestResults().size());
    System.out.println("Nb Statements Analyzed : " + SynthesizerFactory.getNbStatementsAnalysed());
    System.out.println(
            "Nb Statements with Angelic Value Found : " + DefaultSynthesizer.getNbStatementsWithAngelicValue());
    if (Config.INSTANCE.getSynthesis() == Config.NopolSynthesis.SMT) {
        System.out.println("Nb inputs in SMT : " + DefaultSynthesizer.getDataSize());
        System.out.println("Nb SMT level: " + ConstraintBasedSynthesis.level);
        if (ConstraintBasedSynthesis.operators != null) {
            System.out.println("Nb SMT components: [" + ConstraintBasedSynthesis.operators.size() + "] "
                    + ConstraintBasedSynthesis.operators);
            Iterator<Operator<?>> iterator = ConstraintBasedSynthesis.operators.iterator();
            Map<Class, Integer> mapType = new HashMap<>();
            while (iterator.hasNext()) {
                Operator<?> next = iterator.next();
                if (!mapType.containsKey(next.type())) {
                    mapType.put(next.type(), 1);
                } else {
                    mapType.put(next.type(), mapType.get(next.type()) + 1);
                }
            }
            for (Iterator<Class> patchIterator = mapType.keySet().iterator(); patchIterator.hasNext();) {
                Class next = patchIterator.next();
                System.out.println("                  " + next + ": " + mapType.get(next));
            }
        }

        System.out.println("Nb variables in SMT : " + DefaultSynthesizer.getNbVariables());
    }
    System.out.println("Nb run failing test  : " + nbFailingTestExecution);
    System.out.println("Nb run passing test : " + nbPassedTestExecution);
    System.out.println("NoPol Execution time : " + executionTime + "ms");

    if (patches != null && !patches.isEmpty()) {
        System.out.println("----PATCH FOUND----");
        for (Patch patch : patches) {
            System.out.println(patch);
        }
    }
}

From source file:gov.nasa.jpf.constraints.solvers.cw.CWSolver.java

static void incrementElements(double[] values, BitSet selectedIndices, double increment) {
    for (int i = selectedIndices.nextSetBit(0); i >= 0; i = selectedIndices.nextSetBit(i + 1)) {
        values[i] += increment;//from   ww  w.ja  v  a2s.com
    }
}

From source file:de.upb.wdqa.wdvd.revisiontags.TagDownloaderRevisionData.java

/**
 * Converts a memory efficient byte[] representation to a more user friendly
 * List of Strings//from w  ww  . ja  va  2  s. c  o  m
 */
private Set<DbTag> bytesToTags(byte[] bytes) {
    Set<DbTag> result = new HashSet<DbTag>();
    BitSet bitSet = BitSet.valueOf(bytes);

    for (int i = bitSet.nextSetBit(0); i > -1; i = bitSet.nextSetBit(i + 1)) {
        result.add(tagFactory.getTagById(i));
    }
    return result;
}

From source file:org.osgp.adapter.protocol.dlms.domain.commands.ConfigurationObjectHelperService.java

/**
 * Create a list of unique configuration flag type objects representing the
 * active bits in the register value.//from   w w  w.  j  a v  a 2  s . c om
 *
 * @param flagByteArray
 *            The byte array holding the flag bits.
 * @return List of active configuration flag type objects.
 */
public List<ConfigurationFlag> toConfigurationFlags(final byte[] flagByteArray) {
    final List<ConfigurationFlag> configurationFlags = new ArrayList<>();
    final BitSet bitSet = BitSet
            .valueOf(new long[] { ((flagByteArray[0] & 0xFF) << 8) + (flagByteArray[1] & 0xFF) });
    for (int i = bitSet.nextSetBit(0); i >= 0; i = bitSet.nextSetBit(i + 1)) {
        final ConfigurationFlagType configurationFlagType = CONFIGURATION_FLAG_TYPE_PER_BIT_INDEX.get(i);
        configurationFlags.add(new ConfigurationFlag(configurationFlagType, true));
    }
    return configurationFlags;
}

From source file:compare.handler.get.CompareGetHandler.java

/**
 * Does one set of versions entirely contain another
 * @param container the putative container
 * @param contained the containee/*from   w w  w  .j  av  a 2  s. c o  m*/
 * @return true if all the bits of contained are in container
 */
boolean containsVersions(BitSet container, BitSet contained) {
    for (int i = contained.nextSetBit(0); i >= 0; i = contained.nextSetBit(i + 1)) {
        if (container.nextSetBit(i) != i)
            return false;
    }
    return true;
}

From source file:org.caleydo.vis.lineup.model.CategoricalRankColumnModel.java

@Override
protected void updateMask(BitSet todo, List<IRow> data, BitSet mask) {
    for (int i = todo.nextSetBit(0); i >= 0; i = todo.nextSetBit(i + 1)) {
        CATEGORY_TYPE v = this.data.apply(data.get(i));
        if (v == null && filterNA)
            mask.set(i, false);//from www .java 2  s .c o m
        else
            mask.set(i, v == null ? true : selection.contains(v));
    }
}

From source file:org.caleydo.vis.lineup.model.MultiCategoricalRankColumnModel.java

@Override
protected void updateMask(BitSet todo, List<IRow> data, BitSet mask) {
    for (int i = todo.nextSetBit(0); i >= 0; i = todo.nextSetBit(i + 1)) {
        Set<CATEGORY_TYPE> v = this.data.apply(data.get(i));
        if ((v == null || v.isEmpty()) && filterNA)
            mask.set(i, false);/*from   w w  w .ja va2 s. c  om*/
        else
            mask.set(i, v == null ? true : Iterables.any(v, Predicates.in(selection)));
    }
}

From source file:org.apache.hadoop.hive.ql.optimizer.optiq.RelOptHiveTable.java

public boolean containsPartitionColumnsOnly(BitSet cols) {

    for (int i = cols.nextSetBit(0); i >= 0; i++, i = cols.nextSetBit(i + 1)) {
        if (!hivePartitionColsMap.containsKey(i)) {
            return false;
        }//from w ww . jav  a  2s  . c  o  m
    }
    return true;
}