Example usage for java.util BitSet clone

List of usage examples for java.util BitSet clone

Introduction

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

Prototype

public Object clone() 

Source Link

Document

Cloning this BitSet produces a new BitSet that is equal to it.

Usage

From source file:MainClass.java

public static void main(String args[]) {
    BitSet bites = new BitSet();
    bites.set(0);//from   w w  w  .j ava 2s. com
    bites.set(1);
    bites.set(2);
    bites.set(3);
    BitSet bitSetClone = (BitSet) bites.clone();
    System.out.println(bites);
    System.out.println(bitSetClone);
}

From source file:BitOps.java

public static void main(String args[]) {
    BitSet set = new BitSet();
    set.set(1);//ww  w  . jav  a  2s .c om
    set.set(2);
    set.set(3);
    set.set(4);
    set.set(5);
    System.out.println(set);
    BitSet set2 = new BitSet();
    set2.set(1);
    set2.set(3);
    set2.set(5);
    set2.set(7);
    BitSet set3 = (BitSet) set.clone();
    set3.and(set2);
    System.out.println(set3);
    set3 = (BitSet) set.clone();
    set3.or(set2);
    System.out.println(set3);
    set3 = (BitSet) set.clone();
    set3.xor(set2);
    System.out.println(set3);
    set3 = (BitSet) set.clone();
    set3.andNot(set2);
    System.out.println(set3);
    set3.andNot(null);
}

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  ww  w  .j av a 2s  .  c o m*/
    bitset1.set(1);
    bitset1.set(2);

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

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

    // clone bitset1 to bitset2
    bitset2 = (BitSet) bitset1.clone();

    // print new bitsets
    System.out.println(bitset1);
    System.out.println(bitset2);

}

From source file:Main.java

/**
 * very inefficient, but Java wonderful bitset has no subset op
 * perhaps using bit iterator would be faster, I can't be bothered.
 * @param x//from  w  w  w.j  av  a 2 s.com
 * @param y
 * @return
 */
public static boolean isSubSet(BitSet x, BitSet y) {
    y = (BitSet) y.clone();
    y.and(x);
    return y.equals(x);
}

From source file:com.textocat.textokit.postagger.DictionaryComplianceChecker.java

private static int calcDistance(final BitSet xArg, final BitSet yArg) {
    BitSet x = (BitSet) xArg.clone();
    x.xor(yArg);/*from ww w. j a  v a2 s.  c om*/
    return x.cardinality();
}

From source file:de.uniba.wiai.lspi.chord.data.ID.java

private static BitSet bitsetArithPwrOf2(final BitSet _bs, final int pwrOf2, final boolean addition) {
    // The bitset is defined as big-endian unsigned, i.e. (idx 0 is highest bit)
    final BitSet bs = (BitSet) _bs.clone();
    assert (pwrOf2 < kTotalBitLen);
    for (int i = kTotalBitLen - 1 - pwrOf2; i >= 0; --i) {
        bs.flip(i);//from  w  w  w.  j a v  a  2s  .com
        // add/sub for unsigned binary is the same, except we bail if (set == addition) after flip
        if (bs.get(i) == addition)
            break;
    }

    return bs;
}

From source file:edu.udo.scaffoldhunter.model.db.StringProperty.java

/**
 * Returns a new {@link BitSet} of the BitFingerprint
 * /* www  .  j  a  va2  s  .  c om*/
 * @return the fingerprint ({@link BitSet})
 */
public BitSet getBitFingerprintBitSet() {
    checkBitFingerprint();

    if (bitsCache != null) {
        return (BitSet) bitsCache.clone();
    }

    BitSet bits = new BitSet();
    byte[] bitFingerprint;
    bitFingerprint = Base64.decodeBase64(value);

    short length = bitFingerprintToLength(bitFingerprint);

    for (int i = 0; i < length; i++) {
        if ((bitFingerprint[i / sizeofbyte + lengthbytes] & (1 << (i % sizeofbyte))) > 0) {
            bits.set(i);
        }
    }

    bitsCache = (BitSet) bits.clone();
    lengthCache = length;
    return bits;
}

From source file:com.bittorrent.mpetazzoni.client.SharedTorrent.java

/**
 * Bit field availability handler.//from   ww w  .j  av  a  2s  . co m
 *
 * <p>
 * Handle updates in piece availability from a peer's BITFIELD message.
 * When this happens, we need to mark in all the pieces the peer has that
 * they can be reached through this peer, thus augmenting the global
 * availability of pieces.
 * </p>
 *
 * @param peer The peer we got the update from.
 * @param availablePieces The pieces availability bit field of the peer.
 */
@Override
public synchronized void handleBitfieldAvailability(SharingPeer peer, BitSet availablePieces) {
    // Determine if the peer is interesting for us or not, and notify it.
    BitSet interesting = (BitSet) availablePieces.clone();
    interesting.andNot(this.completedPieces);
    interesting.andNot(this.requestedPieces);

    if (interesting.cardinality() == 0) {
        peer.notInteresting();
    } else {
        peer.interesting();
    }

    // Record that the peer has all the pieces it told us it had.
    for (int i = availablePieces.nextSetBit(0); i >= 0; i = availablePieces.nextSetBit(i + 1)) {
        this.rarest.remove(this.pieces[i]);
        this.pieces[i].seenAt(peer);
        this.rarest.add(this.pieces[i]);
    }

    logger.trace("Peer {} contributes {} piece(s) ({} interesting) " + "[completed={}; available={}/{}].",
            new Object[] { peer, availablePieces.cardinality(), interesting.cardinality(),
                    this.completedPieces.cardinality(), this.getAvailablePieces().cardinality(),
                    this.pieces.length });
}

From source file:android.databinding.tool.expr.ExprModelTest.java

private void assertFlags(Expr a, Expr... exprs) {
    BitSet bitSet = a.getShouldReadFlags();
    for (Expr expr : exprs) {
        BitSet clone = (BitSet) bitSet.clone();
        clone.and(expr.getInvalidFlags());
        assertEquals("should read flags of " + a.getUniqueKey() + " should include " + expr.getUniqueKey(),
                expr.getInvalidFlags(), clone);
    }/*from www.  j a v  a  2s . c  o m*/

    BitSet composite = new BitSet();
    for (Expr expr : exprs) {
        composite.or(expr.getInvalidFlags());
    }
    assertEquals("composite flags should match", composite, bitSet);
}

From source file:com.textocat.textokit.postagger.DictionaryComplianceChecker.java

@Override
public void process(JCas jCas) throws AnalysisEngineProcessException {
    for (Word word : JCasUtil.select(jCas, Word.class)) {
        com.textocat.textokit.morph.fs.Wordform docWf = MorphCasUtils.getOnlyWordform(word);
        if (docWf == null) {
            continue;
        }//from   ww  w  . j  a  va 2s . c om
        String wordTxt = normalizeToDictionaryForm(word.getCoveredText());
        List<Wordform> dictWfs = dict.getEntries(wordTxt);
        if (dictWfs == null || dictWfs.isEmpty()) {
            notDictNum++;
            continue;
        }
        // convert to BitSet
        BitSet docBits = toGramBits(gramModel, FSUtils.toSet(docWf.getGrammems()));
        posTrimmer.trimInPlace(docBits);
        List<BitSet> _dictBitSets = Lists.transform(dictWfs, allGramBitsFunction(dict));
        Set<BitSet> dictBitSets = posTrimmer.trimAndMerge(_dictBitSets);
        dictBitSets = selectClosest(docBits, dictBitSets);
        if (calcDistance(docBits, dictBitSets.iterator().next()) == 0) {
            matchedNum++;
        } else {
            notMatchedNum++;
            StringBuilder record = new StringBuilder(wordTxt);
            record.append('\t');
            List<String> gramDiffs = Lists.newLinkedList();
            for (BitSet dictBits : dictBitSets) {
                List<String> grams = Lists.newLinkedList();
                {
                    BitSet positiveBits = (BitSet) docBits.clone();
                    positiveBits.andNot(dictBits);
                    grams.addAll(Lists.transform(gramModel.toGramSet(positiveBits), positiveGramFunc));
                }
                {
                    BitSet negativeBits = (BitSet) dictBits.clone();
                    negativeBits.andNot(docBits);
                    grams.addAll(Lists.transform(gramModel.toGramSet(negativeBits), negativeGramFunc));
                }
                gramDiffs.add(gramJoiner.join(grams));
            }
            gramSetJoiner.appendTo(record, gramDiffs);
            // write corpus grams
            record.append('\t');
            gramJoiner.appendTo(record, gramModel.toGramSet(docBits));
            // write dict grams
            record.append('\t');
            gramSetJoiner.appendTo(record, Collections2.transform(dictBitSets, gramBitsToString));
            out.println(record);
        }
    }
}