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:com.opengamma.analytics.financial.model.volatility.smile.fitting.interpolation.SmileInterpolator.java

protected BitSet getGlobalFixedValues() {
    return new BitSet();
}

From source file:com.opengamma.analytics.financial.model.volatility.smile.fitting.interpolation.SmileInterpolator.java

protected BitSet getLocalFixedValues() {
    return new BitSet();
}

From source file:de.l3s.boilerpipe.sax.BoilerpipeHTMLContentHandler.java

public void flushBlock() {
    if (inBody == 0) {
        if ("TITLE".equalsIgnoreCase(lastStartTag) && inBody == 0) {
            setTitle(tokenBuffer.toString().trim());
        }/*from   w  ww  .  j  ava  2 s.  co  m*/
        textBuffer.setLength(0);
        tokenBuffer.setLength(0);
        return;
    }

    final int length = tokenBuffer.length();
    switch (length) {
    case 0:
        return;
    case 1:
        if (sbLastWasWhitespace) {
            textBuffer.setLength(0);
            tokenBuffer.setLength(0);
            return;
        }
    }
    final String[] tokens = UnicodeTokenizer.tokenize(tokenBuffer);

    int numWords = 0;
    int numLinkedWords = 0;
    int numWrappedLines = 0;
    int currentLineLength = -1; // don't count the first space
    final int maxLineLength = 80;
    int numTokens = 0;
    int numWordsCurrentLine = 0;

    for (String token : tokens) {
        if (ANCHOR_TEXT_START.equals(token)) {
            inAnchorText = true;
        } else if (ANCHOR_TEXT_END.equals(token)) {
            inAnchorText = false;
        } else if (isWord(token)) {
            numTokens++;
            numWords++;
            numWordsCurrentLine++;
            if (inAnchorText) {
                numLinkedWords++;
            }
            final int tokenLength = token.length();
            currentLineLength += tokenLength + 1;
            if (currentLineLength > maxLineLength) {
                numWrappedLines++;
                currentLineLength = tokenLength;
                numWordsCurrentLine = 1;
            }
        } else {
            numTokens++;
        }
    }
    if (numTokens == 0) {
        return;
    }
    int numWordsInWrappedLines;
    if (numWrappedLines == 0) {
        numWordsInWrappedLines = numWords;
        numWrappedLines = 1;
    } else {
        numWordsInWrappedLines = numWords - numWordsCurrentLine;
    }

    TextBlock tb = new TextBlock(textBuffer.toString().trim(), currentContainedTextElements, numWords,
            numLinkedWords, numWordsInWrappedLines, numWrappedLines, offsetBlocks, currentTag);
    currentContainedTextElements = new BitSet();

    if (tagStack.isEmpty())
        currentTag = null;
    else
        currentTag = tagStack.pop();

    offsetBlocks++;

    textBuffer.setLength(0);
    tokenBuffer.setLength(0);

    tb.setTagLevel(blockTagLevel);
    addTextBlock(tb);
    blockTagLevel = -1;
}

From source file:org.apache.kylin.gridtable.GTScanRangePlanner.java

private ImmutableBitSet makeGridTableColumns(CuboidToGridTableMapping mapping, Set<TblColRef> dimensions) {
    BitSet result = new BitSet();
    for (TblColRef dim : dimensions) {
        int idx = mapping.getIndexOf(dim);
        if (idx >= 0)
            result.set(idx);// w  ww  .ja v  a  2  s.co m
    }
    return new ImmutableBitSet(result);
}

From source file:org.apache.kylin.gridtable.GTScanRangePlanner.java

private ImmutableBitSet makeGridTableColumns(CuboidToGridTableMapping mapping,
        Collection<FunctionDesc> metrics) {
    BitSet result = new BitSet();
    for (FunctionDesc metric : metrics) {
        int idx = mapping.getIndexOf(metric);
        if (idx < 0)
            throw new IllegalStateException(metric + " not found in " + mapping);
        result.set(idx);/*from  w ww  .  j av a2  s. c om*/
    }
    return new ImmutableBitSet(result);
}

From source file:org.omnaest.utils.structure.array.ArrayUtils.java

/**
 * Calculates a {@link BitSet} which has its bits set to true at the same index where the related element from one array to the
 * other array is not {@link #equals(Object)}
 * /*from  w w w.  j av  a 2s  .  c o m*/
 * @param elements1
 * @param elements2
 * @return {@link BitSet} with modified index bits set to true
 */
public static <E> BitSet differenceBitSet(E[] elements1, E[] elements2) {
    final BitSet retvals = new BitSet();
    if (elements1 == null && elements2 != null) {
        retvals.set(0, elements2.length);
    } else if (elements1 != null && elements2 == null) {
        retvals.set(0, elements1.length);
    } else if (elements1 != null && elements2 != null) {
        for (int ii = 0; ii < elements1.length || ii < elements2.length; ii++) {
            if (ii >= elements1.length || ii >= elements2.length) {
                retvals.set(ii);
            } else if (!org.apache.commons.lang3.ObjectUtils.equals(elements1[ii], elements2[ii])) {
                retvals.set(ii);
            }
        }
    }
    return retvals;
}

From source file:com.asakusafw.runtime.stage.input.DefaultSplitCombiner.java

private Environment createEnvironment(Configuration configuration, List<Source> sources)
        throws IOException, InterruptedException {
    assert sources != null;
    Map<String, Integer> locationIds = new HashMap<>();
    List<SplitDef> results = new ArrayList<>(sources.size());
    for (Source source : sources) {
        String[] locationArray = source.getSplit().getLocations();
        long length = source.getSplit().getLength();
        BitSet locations = new BitSet();
        if (locationArray != null) {
            for (String location : locationArray) {
                Integer id = locationIds.get(location);
                if (id == null) {
                    id = locationIds.size();
                    locationIds.put(location, id);
                }//from  ww w .  ja  v a  2 s. c  o m
                locations.set(id);
            }
        }
        double localScore = length;
        double globalScore = length * configuration.nonLocalPenaltyRatio;
        results.add(new SplitDef(source, locations, localScore, globalScore));
    }
    if (locationIds.isEmpty()) {
        locationIds.put("DUMMY-LOCATION", locationIds.size()); //$NON-NLS-1$
    }
    String[] locations = new String[locationIds.size()];
    for (Map.Entry<String, Integer> entry : locationIds.entrySet()) {
        locations[entry.getValue()] = entry.getKey();
    }
    SplitDef[] splitDefs = results.toArray(new SplitDef[results.size()]);
    SlotDef[] slotDefs = resolveSlots(configuration.slotsPerInput, locations, results);
    return new Environment(locations, splitDefs, slotDefs, configuration);
}

From source file:org.apache.pig.tools.pigstats.ScriptState.java

public void setScriptFeatures(LogicalPlan plan) {
    BitSet bs = new BitSet();
    try {//from  w  w  w . j a  v a 2s  . c o m
        new LogicalPlanFeatureVisitor(plan, bs).visit();
    } catch (FrontendException e) {
        LOG.warn("unable to get script feature", e);
    }
    scriptFeatures = bitSetToLong(bs);

    LOG.info("Pig features used in the script: " + featureLongToString(scriptFeatures));
}

From source file:au.org.ala.delta.translation.intkey.IntkeyItemsFileWriter.java

private Pair<IntRange, Boolean> writeIntegerAttributes(int filteredCharacterNumber, Character character) {

    // Returning null here will trigger a change from integer to real
    // character type.
    if (_context.getTreatIntegerCharacterAsReal(character.getCharacterId())) {
        return new Pair<IntRange, Boolean>(new IntRange(0), true);
    }//from   w w  w.  ja  va  2  s  .  c  om
    Pair<IntRange, Boolean> result = determineIntegerRange(character);
    IntRange characterRange = result.getFirst();
    if (!result.getSecond()) {

        int unfilteredCharNumber = character.getCharacterId();
        int numStates = characterRange.getMaximumInteger() - characterRange.getMinimumInteger();
        List<BitSet> attributes = new ArrayList<BitSet>();

        Iterator<FilteredItem> items = _dataSet.filteredItems();
        while (items.hasNext()) {
            FilteredItem item = items.next();

            // Turn into bitset.
            BitSet bits = new BitSet();
            IntegerAttribute attribute = (IntegerAttribute) _dataSet
                    .getAttribute(item.getItem().getItemNumber(), unfilteredCharNumber);
            if (isInapplicable(attribute)) {
                bits.set(numStates + 3);
                if (attribute.isInherited()) {
                    attributes.add(bits);
                    continue;
                }
            }
            if (attribute.isUnknown()) {
                attributes.add(bits);
                continue;
            }

            List<NumericRange> ranges = attribute.getNumericValue();

            for (NumericRange range : ranges) {
                Range usedRange;
                if (_context.getUseNormalValues(unfilteredCharNumber)) {
                    usedRange = range.getNormalRange();
                } else {
                    usedRange = range.getFullRange();
                }

                for (int j = usedRange.getMinimumInteger(); j <= usedRange.getMaximumInteger(); j++) {
                    if (j < characterRange.getMinimumInteger()) {
                        bits.set(0);
                    } else if (j <= characterRange.getMaximumInteger()) {
                        bits.set(j - characterRange.getMinimumInteger() + 1);
                    } else {
                        bits.set(numStates + 2);
                    }
                }
            }
            attributes.add(bits);

        }

        _itemsFile.writeAttributeBits(filteredCharacterNumber, attributes, numStates + 4);
    }
    return new Pair<IntRange, Boolean>(characterRange, result.getSecond());
}

From source file:gov.noaa.pfel.erddap.dataset.EDDTableFromHttpGet.java

/**
     * This gets the data from one file up to and including the specified timestamp value.
     *///from  ww  w .jav  a2  s. c o m
    public static Table readFile(String fullFileName, double timestampMillis, String[] tSortedColumns)
            throws Throwable {

        //read all columns of the file (so UPDATE's and DELETE's WHERE can be processed)
        Table oldTable = new Table();
        oldTable.readFlatNc(fullFileName, null, 0); //load all vars, don't unpack
        //String2.log("  EDDTableFromHttpGet.lowGetSourceDataFromFile table.nRows=" + table.nRows());
        //table.saveAsDDS(System.out, "s");

        //make a new Table with a shallow copy of the oldTable's metadata and columns 
        int onCols = oldTable.nColumns();
        int onRows = oldTable.nRows();
        Table newTable = new Table();
        newTable.globalAttributes().add(oldTable.globalAttributes());
        PrimitiveArray oldPAs[] = new PrimitiveArray[onCols];
        PrimitiveArray newPAs[] = new PrimitiveArray[onCols];
        DoubleArray timestampPA = null;
        ByteArray commandPA = null;
        int tCol = 0;
        for (int col = 0; col < onCols; col++) {
            PrimitiveArray pa = oldTable.getColumn(col);
            String colName = oldTable.getColumnName(col);

            //grab the TIMESTAMP and COMMAND columns
            if (colName.equals(TIMESTAMP)) {
                timestampPA = (DoubleArray) pa;
                continue;
            }
            if (colName.equals(COMMAND)) {
                commandPA = (ByteArray) pa;
                continue;
            }

            //insert all the others in newTable
            oldPAs[tCol] = pa;
            newPAs[tCol] = PrimitiveArray.factory(pa.elementClass(), onRows, false);
            newTable.addColumn(tCol++, //increment
                    colName, newPAs[col], oldTable.columnAttributes(col)); //not a clone
        }
        if (timestampPA == null || commandPA == null)
            throw new SimpleException(String2.ERROR + " while reading " + fullFileName + ": " + "columnName="
                    + (timestampPA == null ? TIMESTAMP : commandPA) + " not found.");

        //remove rows with timestamp > row's timestamp
        //        if () {
        //        }

        //sort based on sortedCols+timestamp

        //just keep last of each group of rows where sortedCols is same
        //  and last row is INSERT (not DELETE)
        BitSet justKeep = new BitSet();
        for (int row = 0; row < onRows; row++) {
            //
        }
        newTable.justKeep(justKeep);

        return newTable;
    }