Example usage for java.util BitSet isEmpty

List of usage examples for java.util BitSet isEmpty

Introduction

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

Prototype

public boolean isEmpty() 

Source Link

Document

Returns true if this BitSet contains no bits that are set to true .

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);// www  .  j a v  a 2 s.  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);

    // check if bitset1 and 2 are empty
    System.out.println(bitset1.isEmpty());
    System.out.println(bitset2.isEmpty());

    // create a new empty bitset
    BitSet bitset3 = new BitSet(8);

    // check if bitset3 is empty
    System.out.println(bitset3.isEmpty());

}

From source file:examples.mail.IMAPImportMbox.java

/**
 * Is the message wanted?//w w  w  .ja va  2  s.c o  m
 *
 * @param msgNum the message number
 * @param line the From line
 * @param msgNums the list of wanted message numbers
 * @param contains the list of strings to be contained
 * @return true if the message is wanted
 */
private static boolean wanted(int msgNum, String line, BitSet msgNums, List<String> contains) {
    return (msgNums.isEmpty() && contains.isEmpty()) // no selectors
            || msgNums.get(msgNum) // matches message number
            || listContains(contains, line); // contains string
}

From source file:com.textocat.textokit.morph.commons.GramModelBasedTagMapper.java

public String toTag(BitSet wfBits) {
    if (wfBits.isEmpty()) {
        return null;
    }//from  www . j  a  va  2  s .co  m
    return targetGramJoiner.join(gramModel.toGramSet(wfBits));
}

From source file:edu.uci.ics.hyracks.algebricks.rewriter.rules.ExtractCommonOperatorsRule.java

private boolean requiresMaterialization(List<Integer> groupClusterIds, int index) {
    Integer clusterId = groupClusterIds.get(index);
    BitSet blockingClusters = new BitSet();
    getAllBlockingClusterIds(clusterId, blockingClusters);
    if (!blockingClusters.isEmpty()) {
        for (int i = 0; i < groupClusterIds.size(); i++) {
            if (i == index) {
                continue;
            }//from  w w  w  . ja v a 2 s  .c o  m
            if (blockingClusters.get(groupClusterIds.get(i))) {
                return true;
            }
        }
    }
    return false;
}

From source file:com.textocat.textokit.morph.ruscorpora.DictionaryAligningTagMapper2.java

@Override
public void mapFromRusCorpora(RusCorporaWordform srcWf, com.textocat.textokit.morph.fs.Wordform targetWf) {
    Word wordAnno = targetWf.getWord();/*from   w w  w  . ja  va2  s .  c o m*/
    delegate.mapFromRusCorpora(srcWf, targetWf);
    // first - check whether tag is in tagset
    final BitSet wfTag = toGramBits(gm, FSUtils.toList(targetWf.getGrammems()));
    // skip INIT as a whole new category
    if (wfTag.get(gm.getGrammemNumId(RNCMorphConstants.RNC_INIT))) {
        return;
    }
    if (wfTag.intersects(rncDistortionsMask)) {
        wfTag.andNot(rncDistortionsMask);
        if (!dict.containsGramSet(wfTag)) {
            onDistortedWordWithUnknownTag(wordAnno, wfTag);
        }
        return;
    }
    //
    // if there is no such tag in dictionary then look the word in it
    String wordStr = wordAnno.getCoveredText();
    List<Wordform> dictWfs = dict.getEntries(normalizeToDictionaryForm(wordStr));
    if (dictWfs == null || dictWfs.isEmpty()) {
        // wfTag.isEmpty => NON-LEX
        if (!wfTag.isEmpty() && !dict.containsGramSet(wfTag)) {
            onUnknownWordWithUnknownTag(wordAnno, wfTag);
        }
        return;
    }
    // retain only the gram categories that are represented in RNC tagset
    Set<BitSet> dictTags = rncTrimmer.trimAndMerge(Lists.transform(dictWfs, allGramBitsFunction(dict)));
    // search for a unique dictionary entry that has a tag extending the given one
    List<BitSet> wfExtensions = Lists.newLinkedList();
    for (BitSet dTag : dictTags) {
        if (contains(dTag, wfTag)) {
            wfExtensions.add(dTag);
        }
    }
    if (wfExtensions.isEmpty()) {
        onConflictingTag(wordAnno, wfTag);
    } else if (wfExtensions.size() > 1) {
        onAmbiguousWordform(wordAnno, wfTag);
    } else {
        BitSet newTag = wfExtensions.get(0);
        if (newTag.cardinality() > wfTag.cardinality()) {
            List<String> newTagStr = gm.toGramSet(newTag);
            targetWf.setGrammems(FSUtils.toStringArray(getCAS(targetWf), newTagStr));
            onTagExtended(wordAnno, wfTag, newTag);
        }
    }
}

From source file:edu.umich.flowfence.service.SandboxManager.java

private void dumpSandboxes() {
    if (localLOGV) {
        BitSet seenSandboxes = new BitSet(SANDBOX_COUNT);
        Log.v(TAG, ">>> Dumping current sandbox state:");
        Log.v(TAG, "Running: " + mRunningSandboxes.size() + " sandboxes");
        for (Sandbox sb : mRunningSandboxes) {
            dumpSandbox(sb, seenSandboxes);
        }/*from   w w  w .  j  a v  a 2  s  .c o  m*/
        Log.v(TAG, "Idle: " + mIdleSandboxes.size() + " sandboxes (LRU order)");
        for (Sandbox sb : mIdleSandboxes.keySet()) {
            dumpSandbox(sb, seenSandboxes);
        }
        Log.v(TAG, "Stopped: " + mStoppedSandboxes.size() + " sandboxes");
        for (Sandbox sb : mStoppedSandboxes) {
            dumpSandbox(sb, seenSandboxes);
        }
        Log.v(TAG, "Hot spares: " + mHotSpares.size() + " sandboxes");
        for (Sandbox sb : mHotSpares) {
            dumpSandbox(sb, seenSandboxes);
        }
        seenSandboxes.flip(0, SANDBOX_COUNT); // true = unseen
        if (!seenSandboxes.isEmpty()) {
            Log.w(TAG, "WARNING: leaked " + seenSandboxes.cardinality() + " sandboxes");
            int leaked = -1;
            while ((leaked = seenSandboxes.nextSetBit(leaked + 1)) >= 0) {
                dumpSandbox(Sandbox.get(leaked), null);
            }
        } else {
            Log.v(TAG, "No leaks detected");
        }
        Log.v(TAG, "<<< End of state dump");
    }
}

From source file:at.tuwien.mnsa.smssender.SMSPDUConverter.java

/**
 * Get the PDU encoding for the given message
 * @param message//w  w  w.j  av a  2s  .c o  m
 * @param rightshift of the content for concatination
 * @return 
 */
public SMSPDUConversionResult getContent(String message, int rightshift) {
    List<Byte> finalized = new LinkedList<>();
    BitSet currentWorkingBS = new BitSet(16);

    int currentShiftpos = 0;
    boolean currentlyExtended = false;
    int len = 0;

    //repeat while there are characters left
    while (message.length() > 0) {
        String c = message.substring(0, 1);
        message = message.substring(1);
        byte value;

        //loook up current character
        if (this.GSM_3GPP_TS_23_038.containsKey(c)) {
            value = this.GSM_3GPP_TS_23_038.get(c);
        } else {
            if (this.GSM_3GPP_TS_23_038_EXTENSION.containsKey(c)) {
                if (!currentlyExtended) {
                    //extension -> now do the escape character!
                    //do the "new" character the other round
                    message = c + message;
                    currentlyExtended = true;
                    value = this.GSM_3GPP_TS_23_038.get("\u001B");
                } else {
                    //we just did the ecsape character, now do the char from
                    //the extended alphabet
                    value = this.GSM_3GPP_TS_23_038_EXTENSION.get(c);
                    currentlyExtended = false;
                }
            } else {
                throw new RuntimeException("Not found: " + c);

            }

        }

        //start at 0x0
        if (currentShiftpos == 0) {
            //add current char beginning at pos 0
            addByteToBitset(value, currentWorkingBS, 0, 1, 7);
        } else {
            //else start at second byte and do flipping

            //make place for the right bits of the current char in the front
            currentWorkingBS = rightShiftBitset(currentWorkingBS, currentShiftpos);

            //add last X bits in front of the bitset
            addByteToBitset(value, currentWorkingBS, 0, 8 - currentShiftpos, currentShiftpos);

            //add the first X bits at the end of the bitset if any
            if (currentShiftpos < 7) {
                addByteToBitset(value, currentWorkingBS, 8, 1, 7 - currentShiftpos);
            }

            //the first byte of the bitset is now complete! :)
            byte finalByte = currentWorkingBS.toByteArray()[0];
            finalByte = swapEndianFormat(finalByte);
            finalized.add(finalByte);

            //shift bitset left by 8 bits since we just finished and exported a byte
            currentWorkingBS = leftShiftBitset(currentWorkingBS, 8);
        }

        currentShiftpos = (currentShiftpos + 1) % 8;
        len++;
        //for first character -> just add to the bitset
        //addByteToBitset(value, bitset, i*7);

        /*//exchange characters
        for (int j=0;j<((i%8)*8-(i%8)*7);j++) {
        boolean cBit = content.get()
        }*/

    }

    //add last byte (swap back our eagerly shifted byte)
    if (currentShiftpos == 7) {
        byte finalByte = 0x00;
        finalized.add(finalByte);
    } else if (currentShiftpos != 0) {
        byte finalByte = (currentWorkingBS.isEmpty()) ? 0x0 : currentWorkingBS.toByteArray()[0];
        finalByte = swapEndianFormat(finalByte);

        //I don't really know why,  
        //but java fills right shifts with 1s
        //so we have to manually set all new (left) bits to zero
        for (int i = 0; i < currentShiftpos; i++) {
            finalByte = (byte) (finalByte >> 1);
            finalByte = (byte) (finalByte & 0x7F); //unset first bit
        }

        //finalByte = (byte) (finalByte & 0x3F);
        finalized.add(finalByte);
    }

    byte[] finalM = ArrayUtils.toPrimitive(finalized.toArray(new Byte[finalized.size()]));
    Logger.getGlobal().info("1: " + DatatypeConverter.printHexBinary(finalM));

    //in case of rightshift for concatenation -> right shift the whole array
    if (rightshift > 0) {
        BitSet bs = BitSet.valueOf(finalM);
        bs = rightShiftBitset(bs, rightshift);
        finalM = bs.toByteArray();
        Logger.getGlobal().info("2: " + DatatypeConverter.printHexBinary(finalM));
    }

    SMSPDUConversionResult res = new SMSPDUConversionResult(finalM, len);

    return res;
}

From source file:org.apache.carbondata.core.indexstore.blockletindex.BlockDataMap.java

/**
 * select the blocks based on column min and max value
 *
 * @param filterExecuter//from w  ww . j a v a  2  s  .co m
 * @param maxValue
 * @param minValue
 * @param minMaxFlag
 * @param filePath
 * @param blockletId
 * @return
 */
private boolean addBlockBasedOnMinMaxValue(FilterExecuter filterExecuter, byte[][] maxValue, byte[][] minValue,
        boolean[] minMaxFlag, String filePath, int blockletId) {
    BitSet bitSet = null;
    if (filterExecuter instanceof ImplicitColumnFilterExecutor) {
        String uniqueBlockPath = filePath.substring(filePath.lastIndexOf("/Part") + 1);
        // this case will come in case of old store where index file does not contain the
        // blocklet information
        if (blockletId != -1) {
            uniqueBlockPath = uniqueBlockPath + CarbonCommonConstants.FILE_SEPARATOR + blockletId;
        }
        bitSet = ((ImplicitColumnFilterExecutor) filterExecuter)
                .isFilterValuesPresentInBlockOrBlocklet(maxValue, minValue, uniqueBlockPath, minMaxFlag);
    } else {
        bitSet = filterExecuter.isScanRequired(maxValue, minValue, minMaxFlag);
    }
    if (!bitSet.isEmpty()) {
        return true;
    } else {
        return false;
    }
}

From source file:org.apache.carbondata.core.indexstore.blockletindex.BlockletDataMap.java

/**
 * select the blocks based on column min and max value
 *
 * @param filterExecuter//from   w  w  w  . j  av  a 2 s. co m
 * @param maxValue
 * @param minValue
 * @param filePath
 * @param blockletId
 * @return
 */
private boolean addBlockBasedOnMinMaxValue(FilterExecuter filterExecuter, byte[][] maxValue, byte[][] minValue,
        String filePath, int blockletId) {
    BitSet bitSet = null;
    if (filterExecuter instanceof ImplicitColumnFilterExecutor) {
        String uniqueBlockPath = filePath.substring(filePath.lastIndexOf("/Part") + 1);
        // this case will come in case of old store where index file does not contain the
        // blocklet information
        if (blockletId != -1) {
            uniqueBlockPath = uniqueBlockPath + CarbonCommonConstants.FILE_SEPARATOR + blockletId;
        }
        bitSet = ((ImplicitColumnFilterExecutor) filterExecuter)
                .isFilterValuesPresentInBlockOrBlocklet(maxValue, minValue, uniqueBlockPath);
    } else {
        bitSet = filterExecuter.isScanRequired(maxValue, minValue);
    }
    if (!bitSet.isEmpty()) {
        return true;
    } else {
        return false;
    }
}

From source file:org.apache.carbondata.core.scan.filter.FilterUtil.java

/**
 * This method will compare the selected data against null values and
 * flip the bitSet if any null value is found
 *
 * @param dimensionColumnPage/*from   w  w w.j av  a 2  s  .c  om*/
 * @param bitSet
 */
public static void removeNullValues(DimensionColumnPage dimensionColumnPage, BitSet bitSet,
        byte[] defaultValue) {
    if (!bitSet.isEmpty()) {
        if (null != dimensionColumnPage.getNullBits()) {
            if (!dimensionColumnPage.getNullBits().isEmpty()) {
                for (int i = bitSet.nextSetBit(0); i >= 0; i = bitSet.nextSetBit(i + 1)) {
                    if (dimensionColumnPage.getNullBits().get(i)) {
                        bitSet.flip(i);
                    }
                }
            }
        } else {
            for (int i = bitSet.nextSetBit(0); i >= 0; i = bitSet.nextSetBit(i + 1)) {
                if (dimensionColumnPage.compareTo(i, defaultValue) == 0) {
                    bitSet.flip(i);
                }
            }
        }
    }
}