List of usage examples for com.google.common.collect Range closed
public static <C extends Comparable<?>> Range<C> closed(C lower, C upper)
From source file:net.sf.mzmine.modules.visualization.twod.PointTwoDXYPlot.java
public boolean render(final Graphics2D g2, final Rectangle2D dataArea, int index, PlotRenderingInfo info, CrosshairState crosshairState) { // if this is not TwoDDataSet if (index != 0) return super.render(g2, dataArea, index, info, crosshairState); // prepare some necessary constants final int x = (int) dataArea.getX(); final int y = (int) dataArea.getY(); final int width = (int) dataArea.getWidth(); final int height = (int) dataArea.getHeight(); final double imageRTMin = (double) getDomainAxis().getRange().getLowerBound(); final double imageRTMax = (double) getDomainAxis().getRange().getUpperBound(); final double imageRTStep = (imageRTMax - imageRTMin) / width; final double imageMZMin = (double) getRangeAxis().getRange().getLowerBound(); final double imageMZMax = (double) getRangeAxis().getRange().getUpperBound(); final double imageMZStep = (imageMZMax - imageMZMin) / height; // This if statement below keeps the min max values at the original values when the user // zooms in. We need some variables that scall as the box size so that the points we show // have better resolution the more someone zooms in. double dynamicImageRTMin = imageRTMin; double dynamicImageRTMax = imageRTMax; double dynamicImageMZMin = imageMZMin; double dynamicImageMZMax = imageMZMax; double dynamicImageRTStep = imageRTStep; double dynamicImageMZStep = imageMZStep; if ((zoomOutBitmap != null) && (imageRTMin == totalRTRange.lowerEndpoint()) && (imageRTMax == totalRTRange.upperEndpoint()) && (imageMZMin == totalMZRange.lowerEndpoint()) && (imageMZMax == totalMZRange.upperEndpoint()) && (zoomOutBitmap.getWidth() == width) && (zoomOutBitmap.getHeight() == height)) { g2.drawImage(zoomOutBitmap, x, y, null); return true; }/*from w w w . j a v a 2 s . c om*/ // Save current time Date renderStartTime = new Date(); // prepare a bitmap of required size //BufferedImage image = new BufferedImage(width, height, //BufferedImage.TYPE_INT_ARGB); //ArrayList<DataPoint> listOfDataPoints = new ArrayList<DataPoint>(); //ArrayList<DataPoint> listOfRTValues = new ArrayList<DataPoint>(); ArrayList<DataPoint> listOfDataPoints; ArrayList<Double> listOfRTValues; // These two function must be run in this order Range<Double> rtRangeIn = Range.closed(getDomainAxis().getRange().getLowerBound(), getDomainAxis().getRange().getUpperBound()); Range<Double> mzRangeIn = Range.closed(getRangeAxis().getRange().getLowerBound(), getRangeAxis().getRange().getUpperBound()); listOfDataPoints = dataset.getCentroidedDataPointsInRTMZRange(rtRangeIn, mzRangeIn); listOfRTValues = dataset.getrtValuesInUserRange(); // points to be plotted List plotPoints = new ArrayList(); int count = 0; // Store the current mz,rt,int values so that they can be outputed to a file if we want //currentlyPlottedMZ = new ArrayList(); //for (Iterator dpIt = listOfDataPoints.iterator(); dpIt.hasNext();) { // make a list to keep track of the intesities of each for (DataPoint curDataPoint : listOfDataPoints) { //DataPoint curDataPoint = dpIt.next(); double currentRT = listOfRTValues.get(count).doubleValue(); double currentMZ = curDataPoint.getMZ(); plotPoints.add(new Point2D.Double(currentRT, currentMZ)); count += 1; //currentlyPlottedMZ.add() } // draw image points //for (int i = 0; i < width; i++) // for (int j = 0; j < height; j++) { // Color pointColor = paletteType.getColor(values[i][j]); // //image.setRGB(i, height - j - 1, pointColor.getRGB()); // points.add(new Point2D.Float(i,j)); // } count = 0; for (Iterator i = plotPoints.iterator(); i.hasNext();) { Point2D.Double pt = (Point2D.Double) i.next(); // using the ''dynamic'' min and max will make the resolution imporve as someone zooms // in //float xPlace = (pt.x-(float)dynamicImageRTMin)/((float)dynamicImageRTStep) + x; //float yPlace = (pt.y-(float)dynamicImageMZMin)/((float)dynamicImageMZStep) + y; double xPlace = (pt.x - dynamicImageRTMin) / (dynamicImageRTStep) + (double) x; double yPlace = (double) height - (pt.y - dynamicImageMZMin) / (dynamicImageMZStep) + (double) y; //get the current intensity // use the R, G B for the intensity double curIntensity = listOfDataPoints.get(count).getIntensity(); curIntensity = curIntensity / dataset.curMaxIntensity; //g2.setColor(Color.BLACK); Color pointColor = paletteType.getColor(curIntensity); g2.setColor(pointColor); Ellipse2D dot = new Ellipse2D.Double(xPlace - 1, yPlace - 1, 2, 2); g2.fill(dot); count += 1; } //float xPlace = ((float)42.0-(float)dynamicImageRTMin)/((float)dynamicImageRTStep)+x; //float yPlace = (float)height - ((float)201.02-(float)dynamicImageMZMin)/((float)dynamicImageMZStep)+y; //Ellipse2D dot = new Ellipse2D.Float(xPlace - 1, yPlace - 1, 2, 2); //g2.fill(dot); //g2.dispose(); // if we are zoomed out, save the values if ((imageRTMin == totalRTRange.lowerEndpoint()) && (imageRTMax == totalRTRange.upperEndpoint()) && (imageMZMin == totalMZRange.lowerEndpoint()) && (imageMZMax == totalMZRange.upperEndpoint())) { //zoomOutBitmap = image; } // Paint image //g2.drawImage(image, x, y, null); //g.setColor(Color.BLACK) Date renderFinishTime = new Date(); logger.finest("Finished rendering 2D visualizer, " + (renderFinishTime.getTime() - renderStartTime.getTime()) + " ms"); return true; }
From source file:eu.itesla_project.modules.histo.tools.HistoDbPrintVoltageRangeTool.java
@Override public void run(CommandLine line) throws Exception { Interval interval = Interval.parse(line.getOptionValue("interval")); Path caseFile = Paths.get(line.getOptionValue("case-file")); Map<String, VoltageStats> ranges = new HashMap<>(); Network network = Importers.loadNetwork(caseFile); if (network == null) { throw new RuntimeException("Case '" + caseFile + "' not found"); }/*from w ww .j ava 2 s . com*/ network.getStateManager().allowStateMultiThreadAccess(true); OfflineConfig config = OfflineConfig.load(); try (HistoDbClient histoDbClient = config.getHistoDbClientFactoryClass().newInstance().create()) { Set<HistoDbAttributeId> attrIds = new LinkedHashSet<>(); for (VoltageLevel vl : network.getVoltageLevels()) { attrIds.add(new HistoDbNetworkAttributeId(vl.getId(), HistoDbAttr.V)); } HistoDbStats stats = histoDbClient.queryStats(attrIds, interval, HistoDbHorizon.SN, false); for (VoltageLevel vl : network.getVoltageLevels()) { HistoDbNetworkAttributeId attrId = new HistoDbNetworkAttributeId(vl.getId(), HistoDbAttr.V); float min = stats.getValue(HistoDbStatsType.MIN, attrId, Float.NaN) / vl.getNominalV(); float max = stats.getValue(HistoDbStatsType.MAX, attrId, Float.NaN) / vl.getNominalV(); int count = (int) stats.getValue(HistoDbStatsType.COUNT, attrId, 0); VoltageStats vstats = new VoltageStats(Range.closed(min, max), count, vl.getNominalV()); for (Generator g : vl.getGenerators()) { vstats.pmax += g.getMaxP(); } ranges.put(vl.getId(), vstats); } } Table table = new Table(7, BorderStyle.CLASSIC_WIDE); table.addCell("ID"); table.addCell("vnom"); table.addCell("range"); table.addCell("min"); table.addCell("max"); table.addCell("count"); table.addCell("pmax"); ranges.entrySet().stream().sorted((e1, e2) -> { VoltageStats stats1 = e1.getValue(); VoltageStats stats2 = e2.getValue(); Range<Float> r1 = stats1.range; Range<Float> r2 = stats2.range; float s1 = r1.upperEndpoint() - r1.lowerEndpoint(); float s2 = r2.upperEndpoint() - r2.lowerEndpoint(); return Float.compare(s1, s2); }).forEach(e -> { String vlId = e.getKey(); VoltageStats stats = e.getValue(); Range<Float> r = stats.range; float s = r.upperEndpoint() - r.lowerEndpoint(); table.addCell(vlId); table.addCell(Float.toString(stats.vnom)); table.addCell(Float.toString(s)); table.addCell(Float.toString(r.lowerEndpoint())); table.addCell(Float.toString(r.upperEndpoint())); table.addCell(Integer.toString(stats.count)); table.addCell(Float.toString(stats.pmax)); }); System.out.println(table.render()); }
From source file:org.sonar.java.filters.BaseTreeVisitorIssueFilter.java
private void computeFilteredLinesForRule(@Nullable Tree tree, Class<? extends JavaCheck> filteredRule, boolean excludeLine) { if (tree == null) { return;// ww w .j av a 2 s . c o m } SyntaxToken firstSyntaxToken = tree.firstToken(); SyntaxToken lastSyntaxToken = tree.lastToken(); if (firstSyntaxToken != null && lastSyntaxToken != null) { Set<Integer> filteredlines = ContiguousSet.create( Range.closed(firstSyntaxToken.line(), lastSyntaxToken.line()), DiscreteDomain.integers()); computeFilteredLinesForRule(filteredlines, rulesKeysByRulesClass.get(filteredRule), excludeLine); } }
From source file:org.asoem.greyfish.core.properties.AbstractRangeElementProperty.java
@Override public Range<E> getRange() { return Range.closed(lowerBound, upperBound); }
From source file:net.sf.mzmine.modules.visualization.ida.IDADataSet.java
@Override public void run() { status = TaskStatus.PROCESSING;/*from www .ja v a 2 s.c o m*/ double totalScanIntensity, maxPeakIntensity; for (int index = 0; index < totalScans; index++) { // Cancel? if (status == TaskStatus.CANCELED) return; Scan scan = rawDataFile.getScan(allScanNumbers[index]); if (scan.getMSLevel() == 1) { // Store info about MS spectra for MS/MS to allow extraction of // intensity of precursor ion in MS scan. lastMSIndex = index; } else { Double precursorMZ = scan.getPrecursorMZ(); // Precursor m/z // value Double scanRT = scan.getRetentionTime(); // Scan RT // Calculate total intensity totalScanIntensity = 0; if (intensityType == IntensityType.MS) { // Get intensity of precursor ion from MS scan Scan msscan = rawDataFile.getScan(allScanNumbers[lastMSIndex]); Double mzTolerance = precursorMZ * 10 / 1000000; Range<Double> precursorMZRange = Range.closed(precursorMZ - mzTolerance, precursorMZ + mzTolerance); DataPoint scanDataPoints[] = msscan.getDataPointsByMass(precursorMZRange); for (int x = 0; x < scanDataPoints.length; x++) { totalScanIntensity = totalScanIntensity + scanDataPoints[x].getIntensity(); } } else if (intensityType == IntensityType.MSMS) { // Get total intensity of all peaks in MS/MS scan DataPoint scanDataPoints[] = scan.getDataPoints(); for (int x = 0; x < scanDataPoints.length; x++) { totalScanIntensity = totalScanIntensity + scanDataPoints[x].getIntensity(); } } maxPeakIntensity = 0; DataPoint scanDataPoints[] = scan.getDataPoints(); for (int x = 0; x < scanDataPoints.length; x++) { if (maxPeakIntensity < scanDataPoints[x].getIntensity()) { maxPeakIntensity = scanDataPoints[x].getIntensity(); } } if (totalRTRange.contains(scanRT) && totalMZRange.contains(precursorMZ) && maxPeakIntensity > minPeakInt) { // Add values to arrays rtValues[processedScans] = scanRT; mzValues[processedScans] = precursorMZ; intensityValues[processedScans] = totalScanIntensity; scanNumbers[processedScans] = index + 1; // +1 because loop // runs from 0 not // 1 processedScans++; } } allProcessedScans++; } // Update max Z values for (int row = 0; row < totalmsmsScans; row++) { if (maxIntensity < intensityValues[row]) { maxIntensity = intensityValues[row]; } } // Update color table for all spots totalEntries = processedScans - 1; for (int index = 0; index < processedScans - 1; index++) { // Cancel? if (status == TaskStatus.CANCELED) return; double maxIntensityVal = 1; if (normalizationType == NormalizationType.all) { // Normalize based on all m/z values maxIntensityVal = maxIntensity; } else if (normalizationType == NormalizationType.similar) { // Normalize based on similar m/z values double precursorMZ = mzValues[index]; Double mzTolerance = precursorMZ * 10 / 1000000; Range<Double> precursorMZRange = Range.closed(precursorMZ - mzTolerance, precursorMZ + mzTolerance); maxIntensityVal = (double) getMaxZ(precursorMZRange); } // Calculate normalized intensity double normIntensity = (double) intensityValues[index] / maxIntensityVal; if (normIntensity > 1) { normIntensity = 1; } // Convert normIntensity into gray color tone // RGB tones go from 0 to 255 - we limit it to 220 to not include // too light colors int rgbVal = (int) Math.round(220 - normIntensity * 220); // Update color table colorValues[index] = new Color(rgbVal, rgbVal, rgbVal); processedColors++; } fireDatasetChanged(); status = TaskStatus.FINISHED; }
From source file:org.apache.brooklyn.qa.longevity.Monitor.java
private static Range<Integer> parseRange(String range) { if (range.contains("-")) { String[] parts = range.split("-"); return Range.closed(Integer.parseInt(parts[0]), Integer.parseInt(parts[1])); } else {// w ww.j a v a 2 s.c om return Range.singleton(Integer.parseInt(range)); } }
From source file:org.robotframework.ide.eclipse.main.plugin.launch.AbstractRobotLaunchConfiguration.java
@Override public int getAgentConnectionTimeout() throws CoreException { if (isUsingRemoteAgent()) { final String timeout = getAgentConnectionTimeoutValue(); final Integer timeoutAsInt = Ints.tryParse(timeout); if (timeoutAsInt == null || !Range.closed(AgentConnectionServer.MIN_CONNECTION_TIMEOUT, AgentConnectionServer.MAX_CONNECTION_TIMEOUT).contains(timeoutAsInt)) { throw newCoreException( String.format("Connection timeout '%s' must be an Integer between %,d and %,d", timeout, AgentConnectionServer.MIN_CONNECTION_TIMEOUT, AgentConnectionServer.MAX_CONNECTION_TIMEOUT)); }// w w w . ja v a 2s.c o m return timeoutAsInt; } return AgentConnectionServer.DEFAULT_CONNECTION_TIMEOUT; }
From source file:org.eclipse.m2m.internal.qvt.oml.tools.coverage.ui.TransformationCoverageModel.java
public RangeSet<Integer> getUntouchedRanges() { if (untouchedRanges == null) { untouchedRanges = TreeRangeSet.create(); for (NodeCoverageModel nodeModel : getUntouchedExpressionNodes()) { untouchedRanges.add(Range.closed(nodeModel.getStart(), nodeModel.getEnd() + 1)); }/*from w ww. jav a 2 s .co m*/ } return untouchedRanges; }
From source file:com.wandrell.tabletop.interval.util.IntervalArithmeticsUtils.java
/** * Indicates if an interval contains another. * //from ww w . j av a 2 s .c o m * @param containing * the interval which may be containing the other * @param contained * the interval which may be contained * @return {@code true} if the interval is contained, {@code false} * otherwise */ public static final Boolean isContaining(final Interval containing, final Interval contained) { final Range<Integer> rangeContaining; final Range<Integer> rangeContained; checkNotNull(containing, "Received a null pointer as the first interval"); checkNotNull(contained, "Received a null pointer as the second interval"); checkArgument(isValid(containing), "Received an invalid interval as the first argument"); checkArgument(isValid(contained), "Received an invalid interval as the second argument"); rangeContaining = Range.closed(containing.getLowerLimit(), containing.getUpperLimit()); rangeContained = Range.closed(contained.getLowerLimit(), contained.getUpperLimit()); return rangeContaining.encloses(rangeContained); }
From source file:com.qcadoo.mes.assignmentToShift.hooks.AssignmentToShiftHooks.java
private Optional<LocalDate> resolveNextStartDate(final Entity assignmentToShift) { final LocalDate startDate = LocalDate .fromDateFields(assignmentToShift.getDateField(AssignmentToShiftFields.START_DATE)); final Shift shift = shiftsFactory.buildFrom(assignmentToShift.getBelongsToField(SHIFT)); final Set<LocalDate> occupiedDates = findNextStartDatesMatching(assignmentToShift.getDataDefinition(), shift, startDate);// ww w. j a v a2 s.c o m Iterable<Integer> daysRange = ContiguousSet.create(Range.closed(1, DAYS_IN_YEAR), DiscreteDomain.integers()); return FluentIterable.from(daysRange).transform(new Function<Integer, LocalDate>() { @Override public LocalDate apply(final Integer numOfDay) { return startDate.plusDays(numOfDay); } }).firstMatch(new Predicate<LocalDate>() { @Override public boolean apply(final LocalDate localDate) { return !occupiedDates.contains(localDate) && shift.worksAt(localDate); } }); }