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:com.brighttag.agathon.security.ec2.Ec2SecurityGroupService.java
/** * Converts EC2 {@link IpPermission}s to {@link SecurityGroupPermission}s. *///from w ww . j ava 2 s .com private ImmutableSet<SecurityGroupPermission> fromIpPermissions(Iterable<IpPermission> permissions) { return FluentIterable.from(permissions).transform(new Function<IpPermission, SecurityGroupPermission>() { @Override public SecurityGroupPermission apply(IpPermission permission) { return new SecurityGroupPermission(Netmask.fromCidr(permission.getIpRanges()), Range.closed(permission.getFromPort(), permission.getToPort())); } }).toSet(); }
From source file:org.onos.yangtools.yang.data.impl.codec.AbstractIntegerStringCodec.java
private Range<N> createRange(final Number yangMin, final Number yangMax) { final N min = convertValue(yangMin); final N max = convertValue(yangMax); return Range.closed(min, max); }
From source file:org.corpus_tools.peppermodules.annis.Audio2ANNISMapper.java
@Override public void nodeReached(GRAPH_TRAVERSE_TYPE traversalType, String traversalId, SNode currNode, SRelation sRelation, SNode fromNode, long order) { if (sRelation instanceof SMedialRelation && traversionType == Salt2ANNISMapper.TRAVERSION_TYPE.DOCUMENT_STRUCTURE_AUDIO) { SMedialRelation dsRel = (SMedialRelation) sRelation; Double start = dsRel.getStart(); Double end = dsRel.getEnd(); String val; if (start != null && end != null) { val = "" + start + "-" + end; } else if (start != null) { val = "" + start; } else if (end != null) { val = "-" + end; } else {// w w w . ja v a 2s .c o m val = ""; } SToken tok = dsRel.getSource(); List<Long> virtualToken = idManager.getVirtualisedTokenId(tok.getId()); if (virtualToken == null) { tok.createAnnotation("annis", "time", val); mapSNode(dsRel.getSource()); } else if (!virtualToken.isEmpty()) { // there is already a virtual span written for this token, // add the time information to the overlapped virtual token instead if (virtualToken.size() == 1) { Range<Double> newRange = Range.all(); if (start != null && end != null) { newRange = Range.closed(start, end); } else if (start != null) { newRange = Range.atLeast(start); } else if (end != null) { newRange = Range.atMost(end); } addVirtualRange(virtualToken.get(0), newRange); } else { Long firstTokenID = virtualToken.get(0); Long lastTokenID = virtualToken.get(virtualToken.size() - 1); if (start != null) { addVirtualRange(firstTokenID, Range.atLeast(start)); } if (end != null) { addVirtualRange(lastTokenID, Range.atMost(end)); } } } URI linkedFile = dsRel.getTarget().getMediaReference(); if (linkedFile != null) { if (mappedFiles.add(linkedFile)) { copyLinkedFile(linkedFile); } } } }
From source file:org.geogig.osm.internal.history.HistoryDownloader.java
/** * @return the next available changeset, or absent if reached the last one * @throws IOException/* www . ja va 2s.c o m*/ * @throws InterruptedException */ public Iterator<Changeset> fetchChangesets() { Range<Long> range = Range.closed(initialChangeset, finalChangeset); ContiguousSet<Long> changesetIds = ContiguousSet.create(range, DiscreteDomain.longs()); final int fetchSize = 100; Iterable<List<Long>> partitions = Iterables.partition(changesetIds, fetchSize); final Function<List<Long>, Iterable<Changeset>> asChangesets = (batchIds) -> { Iterable<Changeset> changesets = downloader.fetchChangesets(batchIds); return changesets; }; Iterable<Iterable<Changeset>> changesets = Iterables.transform(partitions, asChangesets); Iterable<Changeset> concat = Iterables.concat(changesets); return concat.iterator(); }
From source file:io.github.msdk.featdet.srmdetection.SrmDetectionMethod.java
/** {@inheritDoc} */ @Override/*from w w w . ja va2 s .com*/ public List<Chromatogram> execute() throws MSDKException { logger.info("Started Srm chromatogram builder on file " + rawDataFile.getName()); // Chromatograms List<Chromatogram> chromatograms = rawDataFile.getChromatograms(); total += chromatograms.size(); // Scans List<MsScan> scans = rawDataFile.getScans(); total += scans.size(); // Check if we have any chomatograms or scans if (total == 0) { throw new MSDKException("No chromatograms or scans provided for SRM detection method"); } // Iterate over all chromatograms for (Chromatogram chromatogram : chromatograms) { // Canceled if (canceled) return null; // Ignore non SRM chromatograms if (chromatogram.getChromatogramType() != ChromatogramType.MRM_SRM) { parsed++; continue; } // Add the SRM chromatogram to the list result.add(chromatogram); parsed++; } // Iterate over all scans Map<String, BuildingChromatogram> chromatogramMap = new HashMap<String, BuildingChromatogram>(); Map<Double, Range<Double>> q1IsolationMzRangeMap = new HashMap<Double, Range<Double>>(); Map<Double, Range<Double>> q3IsolationMzRangeMap = new HashMap<Double, Range<Double>>(); for (MsScan scan : scans) { // Canceled if (canceled) return null; // Ignore non SRM scans MsFunction msFunction = scan.getMsFunction(); if (!msFunction.getName().equals("srm")) { parsed++; continue; } // Q1 data Double q1 = scan.getIsolations().get(0).getPrecursorMz(); // Q3 data /* * TODO: This is a workaround for issue # 123: * https://github.com/msdk/msdk/issues/127 */ String scanDefinition = scan.getScanDefinition(); Pattern pattern = Pattern.compile("(?<=\\[)(.*)(?=\\])"); Matcher matcher = pattern.matcher(scanDefinition); Double q3 = 1d; Range<Double> q3IsolationMzRange = Range.singleton(q3); if (matcher.find()) { String str = matcher.group(0); String[] mzValues = str.split("-"); double mz1 = Double.parseDouble(mzValues[0]); double mz2 = Double.parseDouble(mzValues[1]); q3 = (mz1 + mz2) / 2; q3IsolationMzRange = Range.closed(mz1, mz2); } // Get the chromatogram for the Q1 and Q3 value or generate a new BuildingChromatogram buildingChromatogram = chromatogramMap.get(q1 + ";" + q3); if (buildingChromatogram == null) { buildingChromatogram = new BuildingChromatogram(); chromatogramMap.put(q1 + ";" + q3, buildingChromatogram); // Store the mz isolation range for the q1 and q3 values q1IsolationMzRangeMap.put(q1, scan.getIsolations().get(0).getIsolationMzRange()); q3IsolationMzRangeMap.put(q3, q3IsolationMzRange); } // Add the new data point ChromatographyInfo rt = scan.getChromatographyInfo(); float intenstiy = scan.getIntensityValues()[0]; // Assume only 1 // value buildingChromatogram.addDataPoint(rt, 0d, intenstiy); parsed++; } // Add the newly generated chromatograms to the result list int chromatogramNumber = 1; Iterator<Map.Entry<String, BuildingChromatogram>> iterator = chromatogramMap.entrySet().iterator(); while (iterator.hasNext()) { Map.Entry<String, BuildingChromatogram> entry = iterator.next(); String q1q3 = entry.getKey(); BuildingChromatogram buildingChromatogram = entry.getValue(); // Create the final chromatogram Chromatogram chromatogram = MSDKObjectBuilder.getChromatogram(dataStore, chromatogramNumber, ChromatogramType.MRM_SRM, SeparationType.UNKNOWN); // Add the data points to the final chromatogram ChromatographyInfo[] rtValues = buildingChromatogram.getRtValues(); double[] mzValues = buildingChromatogram.getMzValues(); float[] intensityValues = buildingChromatogram.getIntensityValues(); int size = buildingChromatogram.getSize(); chromatogram.setDataPoints(rtValues, mzValues, intensityValues, size); // Set the Q1 and Q3 values to the isolations for the chromatogram String[] strs = q1q3.split(";"); double q1 = Double.parseDouble(strs[0]); double q3 = Double.parseDouble(strs[1]); List<IsolationInfo> isolations = chromatogram.getIsolations(); IsolationInfo isolationInfo = MSDKObjectBuilder.getIsolationInfo(q1IsolationMzRangeMap.get(q1), null, q1, null, null); isolations.add(isolationInfo); isolationInfo = MSDKObjectBuilder.getIsolationInfo(q3IsolationMzRangeMap.get(q3), null, q3, null, null); isolations.add(isolationInfo); // Add the chromatogram result.add(chromatogram); chromatogramNumber++; iterator.remove(); } return result; }
From source file:io.horizondb.model.core.fields.AbstractField.java
/** * {@inheritDoc} */ @Override public RangeSet<Field> allValues() { return ImmutableRangeSet.of(Range.closed(minValue(), maxValue())); }
From source file:com.github.fge.grappa.matchers.join.JoinMatcherBuilder.java
/** * Return a rule with both lower and upper bounds on the number of cycles * * <p>Note that the range of cycles to run is closed on both ends (that is, * the minimum and maximum number of cycles are inclusive).</p> * * <p>Note also that the rule <strong>will not</strong> fail if there are * more than the maximum number of cycles; it will simply stop matching if * this number of cycles is reached.</p> * * @param minCycles the minimum number of cycles * @param maxCycles the maximum number of cycles * @return a rule/*from w w w.j a va2 s . c om*/ * @throws IllegalArgumentException minimum number of cycles is negative; or * maximum number of cycles is less than the minimum * * @see Range#closed(Comparable, Comparable) */ public Rule times(int minCycles, int maxCycles) { Preconditions.checkArgument(minCycles >= 0, "illegal repetition number specified (" + minCycles + "), must be 0 or greater"); Preconditions.checkArgument(maxCycles >= minCycles, "illegal range specified (" + minCycles + ", " + maxCycles + "): maximum must be greater than minimum"); return range(Range.closed(minCycles, maxCycles)); }
From source file:org.sonar.java.filters.SuppressWarningFilter.java
private void handleSuppressWarning(List<AnnotationTree> annotationTrees, Tree tree) { int startLine = -1; List<String> rules = Lists.newArrayList(); for (AnnotationTree annotationTree : annotationTrees) { if (isSuppressWarningsAnnotation(annotationTree)) { startLine = ((JavaTree) annotationTree).getLine(); rules.addAll(getRules(annotationTree)); break; }// w w w . j ava 2s . c o m } if (startLine != -1) { int endLine = tree.lastToken().line(); Set<Integer> filteredlines = ContiguousSet.create(Range.closed(startLine, endLine), DiscreteDomain.integers()); for (String rule : rules) { excludeLines(filteredlines, rule); } } }
From source file:li.klass.fhem.service.graph.gplot.GPlotParser.java
private GPlotAxis createAxis(Map<String, String> setsDeclarations, String prefix) { String labelKey = prefix + "label"; String rightLabel = setsDeclarations.containsKey(labelKey) ? setsDeclarations.get(labelKey) : ""; String rangeKey = prefix + "range"; Optional<Range<Double>> optRange = Optional.absent(); if (setsDeclarations.containsKey(rangeKey)) { String rangeValue = setsDeclarations.get(rangeKey); String[] parts = rangeValue.split(":"); Range<Double> range; if (rangeValue.startsWith(":")) { range = Range.atMost(Double.parseDouble(parts[0])); } else if (rangeValue.endsWith(":")) { range = Range.atLeast(Double.parseDouble(parts[0])); } else {//from w w w . jav a 2 s . co m range = Range.closed(Double.parseDouble(parts[0]), Double.parseDouble(parts[1])); } optRange = Optional.of(range); } return new GPlotAxis(rightLabel, optRange); }
From source file:com.rockhoppertech.music.examples.Guava.java
public static void goofaround() { MIDITrack track = MIDITrackBuilder.create().noteString("C D E").sequential().build(); // http://docs.guava-libraries.googlecode.com/git-history/release12/javadoc/com/google/common/collect/FluentIterable.html#filter(com.google.common.base.Predicate) ImmutableList<MIDINote> notes = FluentIterable.from(track).transform(new AddFunction(1)).limit(10).toList(); for (MIDINote note : notes) { logger.debug("{}", note); }/*from www.j a v a 2 s. com*/ RangeSet<Double> rangeSet = TreeRangeSet.create(); rangeSet.add(Range.closed(1d, 10d)); rangeSet.add(Range.closed(11d, 20d)); for (Range<Double> r : rangeSet.asRanges()) { logger.debug("{}", r); } logger.debug("span {}", rangeSet.span()); logger.debug("contains {}", rangeSet.contains(20d)); logger.debug("contains {}", rangeSet.contains(20.1)); }