List of usage examples for java.util BitSet set
public void set(int bitIndex)
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 ww w .jav a2 s .com 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:org.apache.hadoop.mapred.TestMultiFileInputFormat.java
public void testFormat() throws IOException { if (LOG.isInfoEnabled()) { LOG.info("Test started"); LOG.info("Max split count = " + MAX_SPLIT_COUNT); LOG.info("Split count increment = " + SPLIT_COUNT_INCR); LOG.info("Max bytes per file = " + MAX_BYTES); LOG.info("Max number of files = " + MAX_NUM_FILES); LOG.info("Number of files increment = " + NUM_FILES_INCR); }//w w w . j a v a 2 s . c o m MultiFileInputFormat<Text, Text> format = new DummyMultiFileInputFormat(); FileSystem fs = FileSystem.getLocal(job); for (int numFiles = 1; numFiles < MAX_NUM_FILES; numFiles += (NUM_FILES_INCR / 2) + rand.nextInt(NUM_FILES_INCR / 2)) { Path dir = initFiles(fs, numFiles, -1); BitSet bits = new BitSet(numFiles); for (int i = 1; i < MAX_SPLIT_COUNT; i += rand.nextInt(SPLIT_COUNT_INCR) + 1) { LOG.info("Running for Num Files=" + numFiles + ", split count=" + i); MultiFileSplit[] splits = (MultiFileSplit[]) format.getSplits(job, i); bits.clear(); for (MultiFileSplit split : splits) { long splitLength = 0; for (Path p : split.getPaths()) { long length = fs.getContentSummary(p).getLength(); assertEquals(length, lengths.get(p.getName()).longValue()); splitLength += length; String name = p.getName(); int index = Integer.parseInt(name.substring(name.lastIndexOf("file_") + 5)); assertFalse(bits.get(index)); bits.set(index); } assertEquals(splitLength, split.getLength()); } } assertEquals(bits.cardinality(), numFiles); fs.delete(dir, true); } LOG.info("Test Finished"); }
From source file:org.onosproject.tetopology.management.SimpleTeTopologyStore.java
@Override public void updateNetwork(Network network) { InternalNetwork curNetwork = networkMap.get(network.networkId()); if (curNetwork != null) { // Existing topology update // Remove existing map entries first, removeNetworkMapEntrys(curNetwork, false); }//from w w w . ja v a2s . c o m TeTopologyKey topoKey = null; if (network.teTopologyId() != null) { topoKey = newTeTopologyKey(network.teTopologyId()); } // Update TE nodes List<TeNodeKey> teNodeKeys = null; if (MapUtils.isNotEmpty(network.nodes())) { teNodeKeys = Lists.newArrayList(); for (Map.Entry<KeyId, NetworkNode> entry : network.nodes().entrySet()) { NetworkNodeKey nodeKey = new NetworkNodeKey(network.networkId(), entry.getKey()); TeNodeKey teNodeKey = null; if (topoKey != null && entry.getValue().teNode() != null) { teNodeKey = new TeNodeKey(topoKey, entry.getValue().teNode().teNodeId()); } updateNetworkNode(nodeKey, entry.getValue(), true, false, teNodeKey); teNodeKeys.add(teNodeKey); } } // Update TE links List<TeLinkTpGlobalKey> teLinkKeys = null; if (MapUtils.isNotEmpty(network.links())) { teLinkKeys = Lists.newArrayList(); for (Map.Entry<KeyId, NetworkLink> entry : network.links().entrySet()) { NetworkLinkKey linkKey = new NetworkLinkKey(network.networkId(), entry.getKey()); TeLinkTpGlobalKey teLinkKey = null; if (topoKey != null && entry.getValue().teLink() != null) { teLinkKey = new TeLinkTpGlobalKey(topoKey, entry.getValue().teLink().teLinkKey()); } updateNetworkLink(linkKey, entry.getValue(), true, false, teLinkKey); teLinkKeys.add(teLinkKey); } } // New network, update TE Topology first if (curNetwork == null) { InternalTeTopology intTopo = new InternalTeTopology(network.teTopologyId().topologyId()); intTopo.setTeNodeKeys(teNodeKeys); intTopo.setTeLinkKeys(teLinkKeys); BitSet flags = new BitSet(TeConstants.FLAG_MAX_BITS); flags.set(TeTopology.BIT_LEARNT); if (network.teTopologyId().clientId() == TeTopologyManager.DEFAULT_PROVIDER_ID) { // Hard rule for now flags.set(TeTopology.BIT_CUSTOMIZED); } CommonTopologyData common = new CommonTopologyData(network.networkId(), OptimizationType.NOT_OPTIMIZED, flags, network.ownerId()); intTopo.setTopologydata(common); teTopologyMap.put(topoKey, intTopo); // Assume new topology TeTopologyEvent topologyEvent = new TeTopologyEvent(TE_TOPOLOGY_ADDED, teTopology(topoKey)); notifyDelegate(topologyEvent); } // Finally Update networkMap InternalNetwork newNetwork = new InternalNetwork(network); newNetwork.setTeTopologyKey(topoKey); networkMap.put(network.networkId(), newNetwork); // Assume new network TeTopologyEvent topologyEvent = new TeTopologyEvent(NETWORK_ADDED, network(network.networkId())); notifyDelegate(topologyEvent); }
From source file:au.org.ala.delta.translation.intkey.IntkeyItemsFileWriter.java
private void writeTextAttributes(int filteredCharNumber, Character textChar) { int characterNumber = textChar.getCharacterId(); List<String> values = new ArrayList<String>(); BitSet inapplicableBits = new BitSet(); Iterator<FilteredItem> items = _dataSet.filteredItems(); while (items.hasNext()) { FilteredItem item = items.next(); Attribute attribute = _dataSet.getAttribute(item.getItem().getItemNumber(), characterNumber); if (isInapplicable(attribute)) { inapplicableBits.set(item.getItemNumber() - 1); }/* ww w .java 2 s .c o m*/ if (attribute == null || attribute.isUnknown()) { values.add(""); continue; } values.add(_formatter.formatCharacterComment(attribute.getValueAsString())); } _itemsFile.writeAttributeStrings(filteredCharNumber, inapplicableBits, values); }
From source file:org.apache.hadoop.hbase.security.visibility.DefaultVisibilityLabelServiceImpl.java
@Override public VisibilityExpEvaluator getVisibilityExpEvaluator(Authorizations authorizations) throws IOException { // If a super user issues a get/scan, he should be able to scan the cells // irrespective of the Visibility labels if (isReadFromSystemAuthUser()) { return new VisibilityExpEvaluator() { @Override/*from w w w.j a v a 2s .co m*/ public boolean evaluate(Cell cell) throws IOException { return true; } }; } List<String> authLabels = null; for (ScanLabelGenerator scanLabelGenerator : scanLabelGenerators) { try { // null authorizations to be handled inside SLG impl. authLabels = scanLabelGenerator.getLabels(VisibilityUtils.getActiveUser(), authorizations); authLabels = (authLabels == null) ? new ArrayList<String>() : authLabels; authorizations = new Authorizations(authLabels); } catch (Throwable t) { LOG.error(t); throw new IOException(t); } } int labelsCount = this.labelsCache.getLabelsCount(); final BitSet bs = new BitSet(labelsCount + 1); // ordinal is index 1 based if (authLabels != null) { for (String authLabel : authLabels) { int labelOrdinal = this.labelsCache.getLabelOrdinal(authLabel); if (labelOrdinal != 0) { bs.set(labelOrdinal); } } } return new VisibilityExpEvaluator() { @Override public boolean evaluate(Cell cell) throws IOException { boolean visibilityTagPresent = false; // Save an object allocation where we can if (cell.getTagsLength() > 0) { Iterator<Tag> tagsItr = CellUtil.tagsIterator(cell.getTagsArray(), cell.getTagsOffset(), cell.getTagsLength()); while (tagsItr.hasNext()) { boolean includeKV = true; Tag tag = tagsItr.next(); if (tag.getType() == VISIBILITY_TAG_TYPE) { visibilityTagPresent = true; int offset = tag.getTagOffset(); int endOffset = offset + tag.getTagLength(); while (offset < endOffset) { Pair<Integer, Integer> result = StreamUtils.readRawVarint32(tag.getBuffer(), offset); int currLabelOrdinal = result.getFirst(); if (currLabelOrdinal < 0) { // check for the absence of this label in the Scan Auth labels // ie. to check BitSet corresponding bit is 0 int temp = -currLabelOrdinal; if (bs.get(temp)) { includeKV = false; break; } } else { if (!bs.get(currLabelOrdinal)) { includeKV = false; break; } } offset += result.getSecond(); } if (includeKV) { // We got one visibility expression getting evaluated to true. Good to include this // KV in the result then. return true; } } } } return !(visibilityTagPresent); } }; }
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 a v a2 s . c o m return new ImmutableBitSet(result); }
From source file:org.apache.lucene.index.collocations.CollocationExtractor.java
private int recordAllPositionsOfTheTermInCurrentDocumentBitset(int docSeq, Term term, BitSet termPos, Terms tv, String[] terms) throws IOException { // first record all of the positions of the term in a bitset which represents terms in the current doc. int index = Arrays.binarySearch(terms, term.text()); if (index >= 0) { // found // Bits liveDocs = MultiFields.getLiveDocs(this.reader); // int[] pos = tpv.getTermPositions(index); DocsAndPositionsEnum dpe = MultiFields.getTermPositionsEnum(this.reader, null, this.fieldName, new BytesRef(terms[index])); dpe.advance(docSeq);//from w w w. ja va 2 s .c o m // remember all positions of the term in this doc for (int j = 0; j < dpe.freq(); j++) { termPos.set(dpe.nextPosition()); } } return index; }
From source file:org.apache.ctakes.ytex.kernel.metric.ConceptSimilarityServiceImpl.java
/** * convert the list of tuis into a bitset * //from ww w . j a v a2 s . c om * @param tuis * @param mapTuiIndex * @return */ private BitSet tuiListToBitset(Set<String> tuis, SortedMap<String, Integer> mapTuiIndex) { BitSet bs = new BitSet(mapTuiIndex.size()); for (String tui : tuis) { bs.set(mapTuiIndex.get(tui)); } return bs; }
From source file:org.wso2.andes.kernel.router.TopicRoutingMatcher.java
/** * @param constituentIndex The index to create the constituent for * @return The created constituent table *///from w ww . j ava2 s .c o m private Map<String, BitSet> addConstituentTable(int constituentIndex) { Map<String, BitSet> constituentTable = new HashMap<>(); BitSet nullBitSet = new BitSet(storageQueueList.size()); BitSet otherBitSet = new BitSet(storageQueueList.size()); // Fill null and other constituent values for all available queues for (int queueIndex = 0; queueIndex < storageQueueList.size(); queueIndex++) { String[] constituentsOfQueue = queueConstituents.get(queueIndex); if (constituentsOfQueue.length < constituentIndex + 1) { // There is no constituent in this queue for this constituent index nullBitSet.set(queueIndex); // If last constituent of the queue is multiLevelWildCard, then any other is a match if (multiLevelWildCard.equals(constituentsOfQueue[constituentsOfQueue.length - 1])) { otherBitSet.set(queueIndex); } } else { String queueConstituent = constituentsOfQueue[constituentIndex]; // Check if this is a wildcard if (multiLevelWildCard.equals(queueConstituent) || singleLevelWildCard.equals(queueConstituent)) { otherBitSet.set(queueIndex); } } } // Add 'null' and 'other' constituent constituentTable.put(NULL_CONSTITUENT, nullBitSet); constituentTable.put(OTHER_CONSTITUENT, otherBitSet); constituentTables.add(constituentIndex, constituentTable); return constituentTable; }
From source file:org.apache.carbondata.hadoop.api.CarbonTableInputFormat.java
/** * set the matched partition indices into a BitSet * @param partitionIds from alter table command, for normal query, it's null * @param filter from query// ww w .j a v a2 s .c om * @param partitionInfo * @param oldPartitionIdList only used in alter table command * @return */ private BitSet setMatchedPartitions(String partitionIds, Expression filter, PartitionInfo partitionInfo, List<Integer> oldPartitionIdList) { BitSet matchedPartitions = null; if (null != partitionIds) { String[] partList = partitionIds.replace("[", "").replace("]", "").split(","); // partList[0] -> use the first element to initiate BitSet, will auto expand later matchedPartitions = new BitSet(Integer.parseInt(partList[0].trim())); for (String partitionId : partList) { Integer index = oldPartitionIdList.indexOf(Integer.parseInt(partitionId.trim())); matchedPartitions.set(index); } } else { if (null != filter) { matchedPartitions = new FilterExpressionProcessor().getFilteredPartitions(filter, partitionInfo); } } return matchedPartitions; }