List of usage examples for com.google.common.collect Range contains
public boolean contains(C value)
From source file:net.sf.mzmine.modules.peaklistmethods.alignment.path.scorer.RTScore.java
public double calculateScore(AlignmentPath path, PeakListRow peak, ParameterSet parameters) { try {/* w w w. ja v a 2 s.c o m*/ rtTolerance = parameters.getParameter(PathAlignerParameters.RTTolerance).getValue(); mzTolerance = parameters.getParameter(PathAlignerParameters.MZTolerance).getValue(); Range<Double> rtRange = rtTolerance.getToleranceRange(path.getRT()); Range<Double> mzRange = mzTolerance.getToleranceRange(path.getMZ()); if (!rtRange.contains(peak.getAverageRT()) || !mzRange.contains(peak.getAverageMZ())) { return WORST_SCORE; } double mzDiff = Math.abs(path.getMZ() - peak.getAverageMZ()); double rtDiff = Math.abs(path.getRT() - peak.getAverageRT()); double score = ((mzDiff / (RangeUtils.rangeLength(mzRange) / 2.0))) + ((rtDiff / (RangeUtils.rangeLength(rtRange) / 2.0))); if (parameters.getParameter(PathAlignerParameters.SameChargeRequired).getValue()) { if (!PeakUtils.compareChargeState(path.convertToAlignmentRow(0), peak)) { return WORST_SCORE; } } if (parameters.getParameter(PathAlignerParameters.SameIDRequired).getValue()) { if (!PeakUtils.compareIdentities(path.convertToAlignmentRow(0), peak)) { return WORST_SCORE; } } if (parameters.getParameter(PathAlignerParameters.compareIsotopePattern).getValue()) { IsotopePattern ip1 = path.convertToAlignmentRow(0).getBestIsotopePattern(); IsotopePattern ip2 = peak.getBestIsotopePattern(); if ((ip1 != null) && (ip2 != null)) { ParameterSet isotopeParams = parameters .getParameter(PathAlignerParameters.compareIsotopePattern).getEmbeddedParameters(); if (!IsotopePatternScoreCalculator.checkMatch(ip1, ip2, isotopeParams)) { return WORST_SCORE; } } } return score; } catch (NullPointerException e) { e.printStackTrace(); return WORST_SCORE; } }
From source file:org.apache.cassandra.dht.BootStrapper.java
/** get potential sources for each range, ordered by proximity (as determined by EndpointSnitch) */ Multimap<Range, InetAddress> getRangesWithSources(String table) { assert tokenMetadata.sortedTokens().size() > 0; final AbstractReplicationStrategy strat = Table.open(table).getReplicationStrategy(); Collection<Range> myRanges = strat.getPendingAddressRanges(tokenMetadata, token, address); Multimap<Range, InetAddress> myRangeAddresses = ArrayListMultimap.create(); Multimap<Range, InetAddress> rangeAddresses = strat.getRangeAddresses(tokenMetadata); for (Range myRange : myRanges) { for (Range range : rangeAddresses.keySet()) { if (range.contains(myRange)) { List<InetAddress> preferred = DatabaseDescriptor.getEndpointSnitch() .getSortedListByProximity(address, rangeAddresses.get(range)); myRangeAddresses.putAll(myRange, preferred); break; }//from ww w . ja va2s .co m } assert myRangeAddresses.keySet().contains(myRange); } return myRangeAddresses; }
From source file:net.sf.mzmine.modules.masslistmethods.chromatogrambuilder.HighestDataPointConnector.java
public void addScan(int scanNumber, DataPoint mzValues[]) { // Sort m/z peaks by descending intensity Arrays.sort(mzValues, new DataPointSorter(SortingProperty.Intensity, SortingDirection.Descending)); // Set of already connected chromatograms in each iteration Set<Chromatogram> connectedChromatograms = new LinkedHashSet<Chromatogram>(); // TODO: these two nested cycles should be optimized for speed for (DataPoint mzPeak : mzValues) { // Search for best chromatogram, which has highest last data point Chromatogram bestChromatogram = null; for (Chromatogram testChrom : buildingChromatograms) { DataPoint lastMzPeak = testChrom.getLastMzPeak(); Range<Double> toleranceRange = mzTolerance.getToleranceRange(lastMzPeak.getMZ()); if (toleranceRange.contains(mzPeak.getMZ())) { if ((bestChromatogram == null) || (testChrom.getLastMzPeak().getIntensity() > bestChromatogram .getLastMzPeak().getIntensity())) { bestChromatogram = testChrom; }//from w ww . ja v a 2 s .c om } } // If we found best chromatogram, check if it is already connected. // In such case, we may discard this mass and continue. If we // haven't found a chromatogram, we may create a new one. if (bestChromatogram != null) { if (connectedChromatograms.contains(bestChromatogram)) { continue; } } else { bestChromatogram = new Chromatogram(dataFile, allScanNumbers); } // Add this mzPeak to the chromatogram bestChromatogram.addMzPeak(scanNumber, mzPeak); // Move the chromatogram to the set of connected chromatograms connectedChromatograms.add(bestChromatogram); } // Process those chromatograms which were not connected to any m/z peak for (Chromatogram testChrom : buildingChromatograms) { // Skip those which were connected if (connectedChromatograms.contains(testChrom)) { continue; } // Check if we just finished a long-enough segment if (testChrom.getBuildingSegmentLength() >= minimumTimeSpan) { testChrom.commitBuildingSegment(); // Move the chromatogram to the set of connected chromatograms connectedChromatograms.add(testChrom); continue; } // Check if we have any committed segments in the chromatogram if (testChrom.getNumberOfCommittedSegments() > 0) { testChrom.removeBuildingSegment(); // Move the chromatogram to the set of connected chromatograms connectedChromatograms.add(testChrom); continue; } } // All remaining chromatograms in buildingChromatograms are discarded // and buildingChromatograms is replaced with connectedChromatograms buildingChromatograms = connectedChromatograms; }
From source file:net.sf.mzmine.modules.masslistmethods.ADAPchromatogrambuilder.ADAPHighestDataPointConnector.java
public void addScan(int scanNumber, DataPoint mzValues[]) { // Sort m/z peaks by descending intensity Arrays.sort(mzValues, new DataPointSorter(SortingProperty.Intensity, SortingDirection.Descending)); // Set of already connected chromatograms in each iteration Set<ADAPChromatogram> connectedChromatograms = new LinkedHashSet<ADAPChromatogram>(); // TODO: these two nested cycles should be optimized for speed for (DataPoint mzPeak : mzValues) { // Search for best chromatogram, which has highest last data point ADAPChromatogram bestChromatogram = null; for (ADAPChromatogram testChrom : buildingChromatograms) { DataPoint lastMzPeak = testChrom.getLastMzPeak(); Range<Double> toleranceRange = mzTolerance.getToleranceRange(lastMzPeak.getMZ()); if (toleranceRange.contains(mzPeak.getMZ())) { if ((bestChromatogram == null) || (testChrom.getLastMzPeak().getIntensity() > bestChromatogram .getLastMzPeak().getIntensity())) { bestChromatogram = testChrom; }/*from w ww .j av a2 s.com*/ } } // If we found best chromatogram, check if it is already connected. // In such case, we may discard this mass and continue. If we // haven't found a chromatogram, we may create a new one. if (bestChromatogram != null) { if (connectedChromatograms.contains(bestChromatogram)) { continue; } } else { bestChromatogram = new ADAPChromatogram(dataFile, allScanNumbers); } // Add this mzPeak to the chromatogram bestChromatogram.addMzPeak(scanNumber, mzPeak); // Move the chromatogram to the set of connected chromatograms connectedChromatograms.add(bestChromatogram); } // Process those chromatograms which were not connected to any m/z peak for (ADAPChromatogram testChrom : buildingChromatograms) { // Skip those which were connected if (connectedChromatograms.contains(testChrom)) { continue; } // Check if we just finished a long-enough segment if (testChrom.getBuildingSegmentLength() >= minimumTimeSpan) { testChrom.commitBuildingSegment(); // Move the chromatogram to the set of connected chromatograms connectedChromatograms.add(testChrom); continue; } // Check if we have any committed segments in the chromatogram if (testChrom.getNumberOfCommittedSegments() > 0) { testChrom.removeBuildingSegment(); // Move the chromatogram to the set of connected chromatograms connectedChromatograms.add(testChrom); continue; } } // All remaining chromatograms in buildingChromatograms are discarded // and buildingChromatograms is replaced with connectedChromatograms buildingChromatograms = connectedChromatograms; }
From source file:yaphyre.core.shapes.SimpleSphere.java
@Override @Nonnull/*from www . j a va 2s .c o m*/ public Optional<CollisionInformation> intersect(@Nonnull Ray ray) { final Ray objectSpaceRay = transformToObjectSpace(ray); final Vector3D originPositionVector = objectSpaceRay.getOrigin().asVector(); final Vector3D direction = objectSpaceRay.getDirection(); final double a = direction.dot(direction); final double b = originPositionVector.dot(direction) * 2; final double c = originPositionVector.dot(originPositionVector) - (RADIUS * RADIUS); final double[] solutions = quadraticSolver.solve(c, b, a); final OptionalDouble minSolution = Arrays.stream(solutions).filter(distance -> { Range<Double> tRange = ray.getTRange(); LOGGER.trace(String.format("testing solution %.3f against range %s", distance, tRange)); return tRange.contains(distance); }).min(); LOGGER.trace("result: " + minSolution); if (minSolution.isPresent() && !Double.isNaN(minSolution.getAsDouble())) { final double distance = minSolution.getAsDouble(); final Point3D intersectionPoint = objectSpaceRay.getPoint(distance); return Optional.of( new CollisionInformation(ray, this, distance, getObjectToWorld().transform(intersectionPoint), getObjectToWorld().transform(calculateNormal(intersectionPoint, objectSpaceRay)), mapToLocalUV(intersectionPoint))); } else { return Optional.empty(); } }
From source file:org.robotframework.ide.eclipse.main.plugin.project.build.fix.MetadataKeyInSameColumnFixer.java
@Override public Optional<ICompletionProposal> asContentProposal(final IMarker marker, final IDocument document, final RobotSuiteFile suiteModel) { Optional<ICompletionProposal> proposal = Optional.empty(); final Optional<RobotSettingsSection> section = suiteModel.findSection(RobotSettingsSection.class); if (section.isPresent()) { final Range<Integer> range = getRange(marker); final List<RobotKeywordCall> metadataSettings = section.get().getMetadataSettings(); for (final RobotKeywordCall robotKeywordCall : metadataSettings) { if (range.contains(robotKeywordCall.getDefinitionPosition().getOffset())) { try { proposal = createProposal(document, robotKeywordCall, suiteModel); } catch (final BadLocationException e) { e.printStackTrace(); }//from www .ja v a 2 s .c om } } } return proposal; }
From source file:com.rockhoppertech.music.series.time.TimeEvent.java
public boolean overlaps(TimeEvent te) { // boolean b = this.getRange().overlaps(te.getRange()); boolean b = false; Range<Double> range1 = this.getOpenRange(); Range<Double> range2 = te.getOpenRange(); if (range1.contains(range2.lowerEndpoint()) || range1.contains(range2.upperEndpoint())) { b = true;/*from w w w. j ava 2 s. c o m*/ } logger.debug(String.format("overlaps %b %s %s", b, this.getOpenRange(), te.getOpenRange())); return b; }
From source file:org.opendaylight.lispflowmapping.type.lisp.LocatorRecord.java
public LocatorRecord setPriority(short priority) { if (priority != 0) { boolean isValidRange = false; List<Range<Short>> rangeConstraints = new ArrayList<>(); rangeConstraints.add(Range.closed(new Short("0"), new Short("255"))); for (Range<Short> r : rangeConstraints) { if (r.contains(priority)) { isValidRange = true;// www . j a v a 2 s.c o m } } if (!isValidRange) { throw new IllegalArgumentException( String.format("Invalid range: %s, expected: %s.", priority, rangeConstraints)); } } this.priority = priority; return this; }
From source file:org.opendaylight.lispflowmapping.type.lisp.LocatorRecord.java
public LocatorRecord setMulticastPriority(short value) { if (value != 0) { boolean isValidRange = false; List<Range<Short>> rangeConstraints = new ArrayList<>(); rangeConstraints.add(Range.closed(new Short("0"), new Short("255"))); for (Range<Short> r : rangeConstraints) { if (r.contains(value)) { isValidRange = true;/*from w w w.ja v a 2 s .c o m*/ } } if (!isValidRange) { throw new IllegalArgumentException( String.format("Invalid range: %s, expected: %s.", value, rangeConstraints)); } } this.multicastPriority = value; return this; }
From source file:org.opentestsystem.authoring.testauth.validation.ScoringRuleParameterValidator.java
/** * validate scalar value//from ww w . j a v a 2s. c om */ private <N extends Number> void validateScalarValue(final ComputationRuleParameter computationRuleParameter, final String scalarValue, final Errors errors) { final ComputationRuleType fieldType = computationRuleParameter.getComputationRuleType(); final String paramName = computationRuleParameter.getParameterName(); final boolean valueIsNumeric = NUMERIC_TYPES.contains(fieldType); if (!rejectIfEmpty(scalarValue, errors, SCALAR, getErrorMessageRoot() + SCALAR, valueIsNumeric ? MAX_PARSEABLE_LENGTH : MAX_STRING_LENGTH, fieldType, paramName, scalarValue) && valueIsNumeric) { try { final String min = computationRuleParameter.getMinimumValue(); final String max = computationRuleParameter.getMaximumValue(); if (fieldType == ComputationRuleType.FLOAT) { final Float floatValue = Float.parseFloat(scalarValue); final Range<Float> floatRange = buildFloatRange(min, max); if (floatRange != null && !floatRange.contains(floatValue)) { rejectValue(errors, SCALAR, getErrorMessageRoot() + SCALAR + MSG_RANGE, fieldType, paramName, scalarValue, min, max); } } else { final Long longValue = Long.parseLong(scalarValue); final Range<Long> longRange = buildLongRange(min, max); if (longRange != null && !longRange.contains(longValue)) { rejectValue(errors, SCALAR, getErrorMessageRoot() + SCALAR + MSG_RANGE, fieldType, paramName, scalarValue, min, max); } } } catch (final NumberFormatException e) { rejectValue(errors, SCALAR, getErrorMessageRoot() + SCALAR + MSG_PARSEABLE_NUMBER, fieldType, paramName, scalarValue); } } else if (ComputationRuleType.BOOLEAN.equals(fieldType) && !Boolean.FALSE.toString().equals(scalarValue.toString()) && !Boolean.TRUE.toString().equals(scalarValue.toString())) { rejectValue(errors, SCALAR, getErrorMessageRoot() + SCALAR + MSG_PARSEABLE_BOOLEAN, fieldType, paramName, scalarValue); } }