List of usage examples for java.util BitSet BitSet
public BitSet()
From source file:sf.net.experimaestro.scheduler.SchedulerTest.java
@Test(description = "Test of the token resource - one job at a time") public void test_token_resource() throws ExperimaestroCannotOverwrite, InterruptedException, IOException { File jobDirectory = mkTestDir(); ThreadCount counter = new ThreadCount(); TokenResource token = new TokenResource("scheduler_test/test_token_resource", 1); Transaction.run((em, t) -> token.save(t)); // Sets 5 jobs WaitingJob[] jobs = new WaitingJob[5]; BitSet failure = new BitSet(); failure.set(3);/* www.j av a 2 s . co m*/ for (int i = 0; i < jobs.length; i++) { jobs[i] = new WaitingJob(counter, jobDirectory, "job" + i, new Action(250, failure.get(i) ? 1 : 0, 0)); final WaitingJob job = jobs[i]; Transaction.run((em, t) -> { job.addDependency(token.createDependency(null)); job.save(t); }); } waitToFinish(0, counter, jobs, 1500, 5); waitBeforeCheck(); // Check that one started after the other (since only one must have been active // at a time) LOGGER.info("Checking the token test output"); // Retrieve all the jobs int errors = 0; errors += checkSequence(true, false, jobs); for (int i = 0; i < jobs.length; i++) { errors += checkState( jobs[i].finalCode() != 0 ? EnumSet.of(ResourceState.ERROR) : EnumSet.of(ResourceState.DONE), jobs[i]); } Assert.assertTrue(errors == 0, "Detected " + errors + " errors after running jobs"); }
From source file:org.apache.hyracks.control.cc.executor.ActivityClusterPlanner.java
private void assignConnectorPolicy(ActivityCluster ac, Map<ActivityId, ActivityPlan> taskMap) { Map<ConnectorDescriptorId, IConnectorPolicy> cPolicyMap = new HashMap<>(); Set<ActivityId> activities = ac.getActivityMap().keySet(); BitSet targetBitmap = new BitSet(); for (ActivityId a1 : activities) { Task[] ac1TaskStates = taskMap.get(a1).getTasks(); int nProducers = ac1TaskStates.length; List<IConnectorDescriptor> outputConns = ac.getActivityOutputMap().get(a1); if (outputConns == null) { continue; }/*from w ww .j a v a 2s . c o m*/ for (IConnectorDescriptor c : outputConns) { ConnectorDescriptorId cdId = c.getConnectorId(); ActivityId a2 = ac.getConsumerActivity(cdId); Task[] ac2TaskStates = taskMap.get(a2).getTasks(); int nConsumers = ac2TaskStates.length; int[] fanouts = new int[nProducers]; if (c.allProducersToAllConsumers()) { for (int i = 0; i < nProducers; ++i) { fanouts[i] = nConsumers; } } else { for (int i = 0; i < nProducers; ++i) { c.indicateTargetPartitions(nProducers, nConsumers, i, targetBitmap); fanouts[i] = targetBitmap.cardinality(); } } IConnectorPolicy cp = assignConnectorPolicy(ac, c, nProducers, nConsumers, fanouts); cPolicyMap.put(cdId, cp); } } executor.getJobRun().getConnectorPolicyMap().putAll(cPolicyMap); }
From source file:edu.uci.ics.hyracks.control.cc.scheduler.ActivityClusterPlanner.java
private void assignConnectorPolicy(ActivityCluster ac, Map<ActivityId, ActivityPlan> taskMap) { Map<ConnectorDescriptorId, IConnectorPolicy> cPolicyMap = new HashMap<ConnectorDescriptorId, IConnectorPolicy>(); Set<ActivityId> activities = ac.getActivityMap().keySet(); BitSet targetBitmap = new BitSet(); for (ActivityId a1 : activities) { Task[] ac1TaskStates = taskMap.get(a1).getTasks(); int nProducers = ac1TaskStates.length; List<IConnectorDescriptor> outputConns = ac.getActivityOutputMap().get(a1); if (outputConns != null) { for (IConnectorDescriptor c : outputConns) { ConnectorDescriptorId cdId = c.getConnectorId(); ActivityId a2 = ac.getConsumerActivity(cdId); Task[] ac2TaskStates = taskMap.get(a2).getTasks(); int nConsumers = ac2TaskStates.length; int[] fanouts = new int[nProducers]; if (c.allProducersToAllConsumers()) { for (int i = 0; i < nProducers; ++i) { fanouts[i] = nConsumers; }/* w ww . j a v a 2 s . c o m*/ } else { for (int i = 0; i < nProducers; ++i) { c.indicateTargetPartitions(nProducers, nConsumers, i, targetBitmap); fanouts[i] = targetBitmap.cardinality(); } } IConnectorPolicy cp = assignConnectorPolicy(ac, c, nProducers, nConsumers, fanouts); cPolicyMap.put(cdId, cp); } } } scheduler.getJobRun().getConnectorPolicyMap().putAll(cPolicyMap); }
From source file:org.wso2.andes.kernel.router.TopicRoutingMatcher.java
/** * Removing a storageQueue from the structure. * * @param storageQueue The storageQueue to remove */// w w w .j a va 2s . co m public void removeStorageQueue(StorageQueue storageQueue) { int queueIndex = storageQueueList.indexOf(storageQueue); if (queueIndex > -1) { for (Map<String, BitSet> constituentTable : constituentTables) { for (Map.Entry<String, BitSet> constituentRow : constituentTable.entrySet()) { // For every row create a new BitSet with the values for the removed storageQueue removed String constituent = constituentRow.getKey(); BitSet bitSet = constituentRow.getValue(); BitSet newBitSet = new BitSet(); int bitIndex = 0; for (int i = 0; i < bitSet.size(); i++) { if (bitIndex == queueIndex) { // If the this is the index to remove then skip this round bitIndex++; } newBitSet.set(i, bitSet.get(bitIndex)); bitIndex++; } constituentTable.put(constituent, newBitSet); } } // Remove the storageQueue from storageQueue list storageQueueList.remove(queueIndex); } else { log.warn("Storage queue for with name : " + storageQueue.getName() + " is not found to " + "remove"); } }
From source file:au.org.ala.delta.translation.intkey.IntkeyItemsFileWriter.java
private Set<Float> writeRealAttributes(int filteredCharNumber, Character realChar, boolean wasInteger) { int unfilteredCharNumber = realChar.getCharacterId(); boolean useNormalValues = _context.getUseNormalValues(unfilteredCharNumber); List<FloatRange> values = new ArrayList<FloatRange>(); BitSet inapplicableBits = new BitSet(); Iterator<FilteredItem> items = _dataSet.filteredItems(); while (items.hasNext()) { FilteredItem item = items.next(); NumericAttribute attribute = (NumericAttribute) _dataSet.getAttribute(item.getItem().getItemNumber(), unfilteredCharNumber);//from ww w . j av a2s .c o m if (attribute == null || attribute.isCodedUnknown() || attribute.isInapplicable() || attribute.isVariable()) { FloatRange range = new FloatRange(Float.MAX_VALUE); values.add(range); if (isInapplicable(attribute)) { inapplicableBits.set(item.getItemNumber() - 1); } continue; } List<NumericRange> ranges = attribute.getNumericValue(); // This can happen if the attribute has a comment but no value. if (ranges.isEmpty()) { FloatRange range = new FloatRange(-Float.MAX_VALUE); values.add(range); if (isInapplicable(attribute)) { inapplicableBits.set(item.getItemNumber() - 1); } continue; } Range useRange; float min = Float.MAX_VALUE; float max = -Float.MAX_VALUE; for (NumericRange range : ranges) { if (_context.hasAbsoluteError(unfilteredCharNumber)) { range.setAbsoluteError(_context.getAbsoluteError(unfilteredCharNumber)); } else if (_context.hasPercentageError(unfilteredCharNumber)) { range.setPercentageError(_context.getPercentageError(unfilteredCharNumber)); } if (useNormalValues) { useRange = range.getNormalRange(); } else { useRange = range.getFullRange(); } min = Math.min(min, useRange.getMinimumFloat()); max = Math.max(max, useRange.getMaximumFloat()); } FloatRange floatRange = new FloatRange(min, max); values.add(floatRange); } Set<Float> floats = new HashSet<Float>(); for (FloatRange range : values) { if (range.getMinimumFloat() != Float.MAX_VALUE && range.getMinimumFloat() != -Float.MAX_VALUE) { floats.add(range.getMinimumFloat()); } else { if (range.getMinimumFloat() == -Float.MAX_VALUE && !wasInteger) { floats.add(0f); // For CONFOR compatibility, seems wrong. } } if (range.getMaximumFloat() != Float.MAX_VALUE && range.getMinimumFloat() != -Float.MAX_VALUE) { floats.add(range.getMaximumFloat()); } else { if (range.getMinimumFloat() == -Float.MAX_VALUE && !wasInteger) { floats.add(1.0f); // For CONFOR compatibility, seems wrong. } } } List<Float> boundaries = new ArrayList<Float>(floats); Collections.sort(boundaries); _itemsFile.writeAttributeFloats(filteredCharNumber, inapplicableBits, values, boundaries); return floats; }
From source file:org.wso2.andes.subscription.TopicSubscriptionBitMapStore.java
/** * Removing a subscription from the structure. * * @param subscription The subscription to remove *//* w w w.j a v a 2 s. c o m*/ @Override public void removeSubscription(AndesSubscription subscription) { int subscriptionIndex = subscriptionList.indexOf(subscription); if (subscriptionIndex > -1) { for (Map<String, BitSet> constituentTable : constituentTables) { for (Map.Entry<String, BitSet> constituentRow : constituentTable.entrySet()) { // For every row create a new BitSet with the values for the removed subscription removed String constituent = constituentRow.getKey(); BitSet bitSet = constituentRow.getValue(); BitSet newBitSet = new BitSet(); int bitIndex = 0; for (int i = 0; i < bitSet.size(); i++) { if (bitIndex == i) { // If the this is the index to remove then skip this round bitIndex++; } newBitSet.set(i, bitSet.get(bitIndex)); bitIndex++; } constituentTable.put(constituent, newBitSet); } } // Remove the subscription from subscription list subscriptionList.remove(subscriptionIndex); } else { log.warn("Subscription for destination : " + subscription.getSubscribedDestination() + " is not found to " + "remove"); } }
From source file:org.wso2.andes.subscription.ClusterSubscriptionBitMapHandler.java
/** * Removing a subscription from the structure. * * @param subscription The subscription to remove *//* w w w. j av a 2 s . com*/ @Override public void removeWildCardSubscription(AndesSubscription subscription) { int subscriptionIndex = wildCardSubscriptionList.indexOf(subscription); if (subscriptionIndex > -1) { for (Map<String, BitSet> constituentTable : constituentTables) { for (Map.Entry<String, BitSet> constituentRow : constituentTable.entrySet()) { // For every row create a new BitSet with the values for the removed subscription removed String constituent = constituentRow.getKey(); BitSet bitSet = constituentRow.getValue(); BitSet newBitSet = new BitSet(); int bitIndex = 0; for (int i = 0; i < bitSet.size(); i++) { if (bitIndex == i) { // If the this is the index to remove then skip this round bitIndex++; } newBitSet.set(i, bitSet.get(bitIndex)); bitIndex++; } constituentTable.put(constituent, newBitSet); } } // Remove the subscription from subscription list wildCardSubscriptionList.remove(subscriptionIndex); } else { log.warn("Subscription for destination : " + subscription.getSubscribedDestination() + " is not found to " + "remove"); } }
From source file:org.apache.poi.ss.format.CellNumberFormatter.java
/** {@inheritDoc} */ public void formatValue(StringBuffer toAppendTo, Object valueObject) { double value = ((Number) valueObject).doubleValue(); value *= scale;/*from www. ja v a2 s . c o m*/ // the '-' sign goes at the front, always, so we pick it out boolean negative = value < 0; if (negative) value = -value; // Split out the fractional part if we need to print a fraction double fractional = 0; if (slash != null) { if (improperFraction) { fractional = value; value = 0; } else { fractional = value % 1.0; //noinspection SillyAssignment value = (long) value; } } Set<StringMod> mods = new TreeSet<>(); StringBuffer output = new StringBuffer(desc); if (exponent != null) { writeScientific(value, output, mods); } else if (improperFraction) { writeFraction(value, null, fractional, output, mods); } else { StringBuffer result = new StringBuffer(); Formatter f = new Formatter(result); f.format(LOCALE, printfFmt, value); if (numerator == null) { writeFractional(result, output); writeInteger(result, output, integerSpecials, mods, integerCommas); } else { writeFraction(value, result, fractional, output, mods); } } // Now strip out any remaining '#'s and add any pending text ... ListIterator<Special> it = specials.listIterator(); Iterator<StringMod> changes = mods.iterator(); StringMod nextChange = (changes.hasNext() ? changes.next() : null); int adjust = 0; BitSet deletedChars = new BitSet(); // records chars already deleted while (it.hasNext()) { Special s = it.next(); int adjustedPos = s.pos + adjust; if (!deletedChars.get(s.pos) && output.charAt(adjustedPos) == '#') { output.deleteCharAt(adjustedPos); adjust--; deletedChars.set(s.pos); } while (nextChange != null && s == nextChange.special) { int lenBefore = output.length(); int modPos = s.pos + adjust; int posTweak = 0; switch (nextChange.op) { case StringMod.AFTER: // ignore adding a comma after a deleted char (which was a '#') if (nextChange.toAdd.equals(",") && deletedChars.get(s.pos)) break; posTweak = 1; //noinspection fallthrough case StringMod.BEFORE: output.insert(modPos + posTweak, nextChange.toAdd); break; case StringMod.REPLACE: int delPos = s.pos; // delete starting pos in original coordinates if (!nextChange.startInclusive) { delPos++; modPos++; } // Skip over anything already deleted while (deletedChars.get(delPos)) { delPos++; modPos++; } int delEndPos = nextChange.end.pos; // delete end point in original if (nextChange.endInclusive) delEndPos++; int modEndPos = delEndPos + adjust; // delete end point in current if (modPos < modEndPos) { if (nextChange.toAdd == "") output.delete(modPos, modEndPos); else { char fillCh = nextChange.toAdd.charAt(0); for (int i = modPos; i < modEndPos; i++) output.setCharAt(i, fillCh); } deletedChars.set(delPos, delEndPos); } break; default: throw new IllegalStateException("Unknown op: " + nextChange.op); } adjust += output.length() - lenBefore; if (changes.hasNext()) nextChange = changes.next(); else nextChange = null; } } // Finally, add it to the string if (negative) toAppendTo.append('-'); toAppendTo.append(output); }
From source file:org.apache.tez.runtime.library.common.writers.UnorderedPartitionedKVWriter.java
private Event generateEvent() throws IOException { DataMovementEventPayloadProto.Builder payloadBuidler = DataMovementEventPayloadProto.newBuilder(); String host = getHost();/*from w w w . ja va2 s . c om*/ int shufflePort = getShufflePort(); BitSet emptyPartitions = new BitSet(); for (int i = 0; i < numPartitions; i++) { if (numRecordsPerPartition[i] == 0) { emptyPartitions.set(i); } } if (emptyPartitions.cardinality() != 0) { // Empty partitions exist ByteString emptyPartitionsByteString = TezCommonUtils .compressByteArrayToByteString(TezUtilsInternal.toByteArray(emptyPartitions)); payloadBuidler.setEmptyPartitions(emptyPartitionsByteString); } if (emptyPartitions.cardinality() != numPartitions) { // Populate payload only if at least 1 partition has data payloadBuidler.setHost(host); payloadBuidler.setPort(shufflePort); payloadBuidler.setPathComponent(outputContext.getUniqueIdentifier()); } CompositeDataMovementEvent cDme = CompositeDataMovementEvent.create(0, numPartitions, payloadBuidler.build().toByteString().asReadOnlyByteBuffer()); return cDme; }
From source file:MSUmpire.SpectrumParser.mzXMLParser.java
@Override public ScanCollection GetScanDIAMS2(XYData DIAWindow, boolean IncludePeak, float startTime, float endTime) { if (dIA_Setting == null) { Logger.getRootLogger().error(filename + " is not DIA data"); return null; }/*from ww w . j a v a 2 s .c o m*/ ScanCollection swathScanCollection = new ScanCollection(parameter.Resolution); List<MzXMLthreadUnit> ScanList = new ArrayList<>(); int StartScanNo = 0; int EndScanNo = 0; StartScanNo = GetStartScan(startTime); EndScanNo = GetEndScan(endTime); // ArrayList<Integer> IncludedScans=new ArrayList<>(); final BitSet IncludedScans = new BitSet(); for (int scannum : dIA_Setting.DIAWindows.get(DIAWindow)) { if (scannum >= StartScanNo && scannum <= EndScanNo) { IncludedScans.set(scannum, true); } } ScanList = ParseScans(IncludedScans); for (MzXMLthreadUnit result : ScanList) { swathScanCollection.AddScan(result.scan); swathScanCollection.ElutionTimeToScanNoMap.put(result.scan.RetentionTime, result.scan.ScanNum); } ScanList.clear(); ScanList = null; return swathScanCollection; }