List of usage examples for java.util BitSet set
public void set(int bitIndex)
From source file:com.surevine.alfresco.esl.impl.ESCAfterInvocationProvider.java
/** * Called from decide(...) this method filters the contents of the input ResultSet, returning an output ResultSet containing only those results that RMCaveatConfig allows the current user to see * /* ww w . jav a 2 s . co m*/ * @param unfilteredResultSet * A result set to filter * @return ResultSet containing only those elemenets in <code>unfilteredResultSet</code> for which the Caveat Service allows access to the current user */ protected ResultSet decideOnResultSet(ResultSet unfilteredResultSet) { boolean recordAnyMissingNodes = new Date().after(_nextTimeToReportMissingNodes); boolean foundMissingNodes = false; if (LOGGER.isDebugEnabled()) { LOGGER.debug("Entering decideOnResultSet"); } // Shortcut some obvious exit conditions if (unfilteredResultSet == null) { return null; } if (unfilteredResultSet.length() == 0) { return unfilteredResultSet; } BitSet inclusionMask = new BitSet(unfilteredResultSet.length()); FilteringResultSet frs = new FilteringResultSet(unfilteredResultSet, inclusionMask); int length = unfilteredResultSet.length(); for (int i = 0; i < length; i++) { NodeRef nodeRef = unfilteredResultSet.getNodeRef(i); if (_nodeService.exists(nodeRef)) { // If the node exists, check whether we can see it if (_caveatComponent.hasAccess(nodeRef)) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Access Granted to " + nodeRef); } inclusionMask.set(i); } else if (LOGGER.isDebugEnabled()) { LOGGER.debug("Access forbidden to " + nodeRef); } } else { foundMissingNodes = true; if (recordAnyMissingNodes) { LOGGER.warn("The node [" + nodeRef + "] was returned from a search but does not exist."); } } } if (foundMissingNodes) { _nextTimeToReportMissingNodes = new Date(new Date().getTime() + _missingNodeReportingFrequencyMillis); LOGGER.info("To preserve performance, the system will not report on further missing nodes until " + _nextTimeToReportMissingNodes); } if (LOGGER.isDebugEnabled()) { LOGGER.debug("Leaving decideOnResultSet"); } return frs; }
From source file:org.apache.openjpa.jdbc.sql.JoinSet.java
/** * Iterator over joins that prepares them for SQL translation. *///from w w w . j a v a 2 s.c om public Iterator joinIterator() { if (_size < 2) return iterator(); if (_sorted != null) return _sorted.iterator(); List sorted = new ArrayList(_size); LinkedList queue = new LinkedList(); BitSet seen = new BitSet(_graph.size() * _graph.size() + _graph.size()); // traverse graph Node n; int idx, sidx; for (int i = 0; i < _graph.size(); i++) { // seed queue with next set of disconnected joins for (n = (Node) _graph.get(i); n != null; n = n.next) { sidx = getSeenIndex(n.join); if (!seen.get(sidx)) { seen.set(sidx); queue.add(n); } } if (queue.isEmpty()) continue; // traverse from those joins to reachables while (!queue.isEmpty()) { n = (Node) queue.removeFirst(); // don't repeat a join to a table we've already joined, but // do traverse through it in the graph (the first indexes of // the seeen bitset are reserved for joined-to tables) idx = (n.forward) ? n.join.getIndex2() : n.join.getIndex1(); if (!seen.get(idx)) { sorted.add((n.forward) ? n.join : n.join.reverse()); seen.set(idx); } for (n = (Node) _graph.get(idx); n != null; n = n.next) { sidx = getSeenIndex(n.join); if (!seen.get(sidx)) { seen.set(sidx); queue.add(n); } } } } _sorted = sorted; return _sorted.iterator(); }
From source file:org.apache.hyracks.algebricks.rewriter.rules.ExtractCommonOperatorsRule.java
private void computeClusters(Mutable<ILogicalOperator> parentRef, Mutable<ILogicalOperator> opRef, MutableInt currentClusterId) {// w w w . j a v a 2 s . com // only replicate operator has multiple outputs int outputIndex = 0; if (opRef.getValue().getOperatorTag() == LogicalOperatorTag.REPLICATE) { ReplicateOperator rop = (ReplicateOperator) opRef.getValue(); List<Mutable<ILogicalOperator>> outputs = rop.getOutputs(); for (outputIndex = 0; outputIndex < outputs.size(); outputIndex++) { if (outputs.get(outputIndex).equals(parentRef)) { break; } } } AbstractLogicalOperator aop = (AbstractLogicalOperator) opRef.getValue(); Pair<int[], int[]> labels = aop.getPhysicalOperator().getInputOutputDependencyLabels(opRef.getValue()); List<Mutable<ILogicalOperator>> inputs = opRef.getValue().getInputs(); for (int i = 0; i < inputs.size(); i++) { Mutable<ILogicalOperator> inputRef = inputs.get(i); if (labels.second[outputIndex] == 1 && labels.first[i] == 0) { // 1 -> 0 if (labels.second.length == 1) { clusterMap.put(opRef, currentClusterId); // start a new cluster MutableInt newClusterId = new MutableInt(++lastUsedClusterId); computeClusters(opRef, inputRef, newClusterId); BitSet waitForList = clusterWaitForMap.get(currentClusterId.getValue()); if (waitForList == null) { waitForList = new BitSet(); clusterWaitForMap.put(currentClusterId.getValue(), waitForList); } waitForList.set(newClusterId.getValue()); } } else { // 0 -> 0 and 1 -> 1 MutableInt prevClusterId = clusterMap.get(opRef); if (prevClusterId == null || prevClusterId.getValue().equals(currentClusterId.getValue())) { clusterMap.put(opRef, currentClusterId); computeClusters(opRef, inputRef, currentClusterId); } else { // merge prevClusterId and currentClusterId: update all the map entries that has currentClusterId to prevClusterId for (BitSet bs : clusterWaitForMap.values()) { if (bs.get(currentClusterId.getValue())) { bs.clear(currentClusterId.getValue()); bs.set(prevClusterId.getValue()); } } clusterWaitForMap.remove(currentClusterId.getValue()); currentClusterId.setValue(prevClusterId.getValue()); } } } }
From source file:edu.uci.ics.hyracks.algebricks.rewriter.rules.ExtractCommonOperatorsRule.java
private void candidatesGrow(List<Mutable<ILogicalOperator>> opList, List<Mutable<ILogicalOperator>> candidates) { List<Mutable<ILogicalOperator>> previousCandidates = new ArrayList<Mutable<ILogicalOperator>>(); previousCandidates.addAll(candidates); candidates.clear();// w ww .j a v a 2s . com boolean validCandidate = false; for (Mutable<ILogicalOperator> op : opList) { List<Mutable<ILogicalOperator>> inputs = op.getValue().getInputs(); for (int i = 0; i < inputs.size(); i++) { Mutable<ILogicalOperator> inputRef = inputs.get(i); validCandidate = false; for (Mutable<ILogicalOperator> candidate : previousCandidates) { // if current input is in candidates if (inputRef.getValue().equals(candidate.getValue())) { if (inputs.size() == 1) { validCandidate = true; } else { BitSet candidateInputBitMap = opToCandidateInputs.get(op); if (candidateInputBitMap == null) { candidateInputBitMap = new BitSet(inputs.size()); opToCandidateInputs.put(op, candidateInputBitMap); } candidateInputBitMap.set(i); if (candidateInputBitMap.cardinality() == inputs.size()) { validCandidate = true; } } break; } } } if (!validCandidate) continue; if (!candidates.contains(op)) candidates.add(op); } }
From source file:org.springframework.kafka.listener.ConcurrentMessageListenerContainerTests.java
@Test public void testManualCommitSyncExisting() throws Exception { this.logger.info("Start MANUAL_IMMEDIATE with Existing"); Map<String, Object> senderProps = KafkaTestUtils.producerProps(embeddedKafka); ProducerFactory<Integer, String> pf = new DefaultKafkaProducerFactory<Integer, String>(senderProps); KafkaTemplate<Integer, String> template = new KafkaTemplate<>(pf); template.setDefaultTopic(topic8);/* ww w. ja v a2 s . com*/ template.sendDefault(0, "foo"); template.sendDefault(2, "bar"); template.sendDefault(0, "baz"); template.sendDefault(2, "qux"); template.flush(); Map<String, Object> props = KafkaTestUtils.consumerProps("testManualExistingSync", "false", embeddedKafka); props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest"); DefaultKafkaConsumerFactory<Integer, String> cf = new DefaultKafkaConsumerFactory<Integer, String>(props); ContainerProperties containerProps = new ContainerProperties(topic8); containerProps.setSyncCommits(true); final CountDownLatch latch = new CountDownLatch(8); final BitSet bitSet = new BitSet(8); containerProps.setMessageListener((AcknowledgingMessageListener<Integer, String>) (message, ack) -> { ConcurrentMessageListenerContainerTests.this.logger.info("manualExisting: " + message); ack.acknowledge(); bitSet.set((int) (message.partition() * 4 + message.offset())); latch.countDown(); }); containerProps.setAckMode(AckMode.MANUAL_IMMEDIATE); ConcurrentMessageListenerContainer<Integer, String> container = new ConcurrentMessageListenerContainer<>(cf, containerProps); container.setConcurrency(1); container.setBeanName("testManualExisting"); container.start(); ContainerTestUtils.waitForAssignment(container, embeddedKafka.getPartitionsPerTopic()); template.sendDefault(0, "fooo"); template.sendDefault(2, "barr"); template.sendDefault(0, "bazz"); template.sendDefault(2, "quxx"); template.flush(); assertThat(latch.await(60, TimeUnit.SECONDS)).isTrue(); assertThat(bitSet.cardinality()).isEqualTo(8); container.stop(); this.logger.info("Stop MANUAL_IMMEDIATE with Existing"); }
From source file:org.apache.jackrabbit.core.query.lucene.CachingIndexReader.java
private BitSet initShareableNodes(IndexReader delegatee) throws IOException { BitSet shareableNodes = new BitSet(); TermDocs tDocs = delegatee.termDocs(new Term(FieldNames.SHAREABLE_NODE, "")); try {//from w w w .j a va2 s.c om while (tDocs.next()) { shareableNodes.set(tDocs.doc()); } } finally { tDocs.close(); } return shareableNodes; }
From source file:org.apache.hyracks.algebricks.rewriter.rules.ExtractCommonOperatorsRule.java
private void candidatesGrow(List<Mutable<ILogicalOperator>> opList, List<Mutable<ILogicalOperator>> candidates) { List<Mutable<ILogicalOperator>> previousCandidates = new ArrayList<Mutable<ILogicalOperator>>(); previousCandidates.addAll(candidates); candidates.clear();// www . ja va 2s.c om boolean validCandidate = false; for (Mutable<ILogicalOperator> op : opList) { List<Mutable<ILogicalOperator>> inputs = op.getValue().getInputs(); for (int i = 0; i < inputs.size(); i++) { Mutable<ILogicalOperator> inputRef = inputs.get(i); validCandidate = false; for (Mutable<ILogicalOperator> candidate : previousCandidates) { // if current input is in candidates if (inputRef.getValue().equals(candidate.getValue())) { if (inputs.size() == 1) { validCandidate = true; } else { BitSet candidateInputBitMap = opToCandidateInputs.get(op); if (candidateInputBitMap == null) { candidateInputBitMap = new BitSet(inputs.size()); opToCandidateInputs.put(op, candidateInputBitMap); } candidateInputBitMap.set(i); if (candidateInputBitMap.cardinality() == inputs.size()) { validCandidate = true; } } break; } } } if (!validCandidate) { continue; } if (!candidates.contains(op)) { candidates.add(op); } } }
From source file:org.dataconservancy.packaging.tool.integration.PackageGenerationTest.java
/** * Reads in any BagIt file that uses a ':' to delimit a keyword and value pair. * * @param bagItFile the file to read//from ww w . ja v a 2 s. c om * @return a Map keyed by the keywords, with the List of values as they appear in the file * @throws IOException */ private Map<String, List<String>> parseBagItKeyValuesFile(File bagItFile) throws IOException { Map<String, List<String>> result = new HashMap<>(); // Used to track state; a streams no-no. Probably should do this the old-fashioned way. BitSet bitSet = new BitSet(1); bitSet.set(0); StringBuilder key = new StringBuilder(); Files.lines(bagItFile.toPath(), Charset.forName("UTF-8")).flatMap(line -> Stream .of(line.substring(0, line.indexOf(":")), line.substring(line.indexOf(":") + 1).trim())) .forEach(token -> { if (bitSet.get(0)) { // key key.delete(0, key.length()); result.putIfAbsent(token, new ArrayList<>()); key.append(token); bitSet.clear(0); } else { // value result.get(key.toString()).add(token); bitSet.set(0); } }); return result; }
From source file:org.apache.hadoop.mapred.TestCombineTextInputFormat.java
@Test(timeout = 10000) public void testFormat() throws Exception { JobConf job = new JobConf(defaultConf); Random random = new Random(); long seed = random.nextLong(); LOG.info("seed = " + seed); random.setSeed(seed);// www .j a v a2 s. co m localFs.delete(workDir, true); FileInputFormat.setInputPaths(job, workDir); final int length = 10000; final int numFiles = 10; createFiles(length, numFiles, random); // create a combined split for the files CombineTextInputFormat format = new CombineTextInputFormat(); LongWritable key = new LongWritable(); Text value = new Text(); for (int i = 0; i < 3; i++) { int numSplits = random.nextInt(length / 20) + 1; LOG.info("splitting: requesting = " + numSplits); InputSplit[] splits = format.getSplits(job, numSplits); LOG.info("splitting: got = " + splits.length); // we should have a single split as the length is comfortably smaller than // the block size assertEquals("We got more than one splits!", 1, splits.length); InputSplit split = splits[0]; assertEquals("It should be CombineFileSplit", CombineFileSplit.class, split.getClass()); // check the split BitSet bits = new BitSet(length); LOG.debug("split= " + split); RecordReader<LongWritable, Text> reader = format.getRecordReader(split, job, voidReporter); try { int count = 0; while (reader.next(key, value)) { int v = Integer.parseInt(value.toString()); LOG.debug("read " + v); if (bits.get(v)) { LOG.warn("conflict with " + v + " at position " + reader.getPos()); } assertFalse("Key in multiple partitions.", bits.get(v)); bits.set(v); count++; } LOG.info("splits=" + split + " count=" + count); } finally { reader.close(); } assertEquals("Some keys in no partition.", length, bits.cardinality()); } }
From source file:fingerprints.HashedBloomFingerprinter.java
private void setRingBits(BitSet bitset, IRingSet rings) { int ringSize = 0; for (IAtomContainer ring : rings.atomContainers()) { int atomCount = ring.getAtomCount(); if (atomCount < ringBitCount) { if (ringSize < atomCount) { int toHashCode = new HashCodeBuilder(17, 37).append(atomCount).toHashCode(); int ringPosition = (int) generateMersenneTwisterRandomNumber(ringBitCount, toHashCode); int index = bloomFilter.getBitArraySize() + (ringPosition - 2); if (index < getFingerprintLength()) { bitset.set(index); }/*from w ww .j av a2 s.c o m*/ ringSize++; } } } }