List of usage examples for com.google.common.collect Range singleton
public static <C extends Comparable<?>> Range<C> singleton(C value)
From source file:net.sf.mzmine.project.impl.RawDataFileImpl.java
public @Nonnull Range<Double> getDataRTRange(int msLevel) { // check if we have this value already cached Range<Double> rtRange = dataRTRange.get(msLevel); if (rtRange != null) return rtRange; // find the value for (Scan scan : scans.values()) { // ignore scans of other ms levels if ((msLevel != 0) && (scan.getMSLevel() != msLevel)) continue; if (rtRange == null) rtRange = Range.singleton(scan.getRetentionTime()); else/* w w w .ja va2 s .c o m*/ rtRange = rtRange.span(Range.singleton(scan.getRetentionTime())); } // cache the value if (rtRange != null) dataRTRange.put(msLevel, rtRange); else rtRange = Range.singleton(0.0); return rtRange; }
From source file:com.cinchapi.concourse.server.storage.AtomicOperation.java
/** * Check each one of the {@link #intentions} against the * {@link #destination} and grab the appropriate locks along the way. This * method will return {@code true} if all expectations are met and all * necessary locks are grabbed. Otherwise it will return {@code false}, in * which case this operation should be aborted immediately. * //from w w w . j a v a 2 s .c om * @return {@code true} if all expectations are met and all necessary locks * are grabbed. */ private boolean grabLocks() { if (isReadOnly()) { return true; } else { // NOTE: If we can't grab a lock immediately because it is held by // someone else, then we must fail immediately because the // AtomicOperation can't properly commit. locks = Maps.newHashMap(); try { // Grab write locks and remove any covered read or range read // intentions for (Token token : writes2Lock) { if (notifiedAboutVersionChange) { return false; } LockType type; if (token instanceof RangeToken) { RangeToken rangeToken = (RangeToken) token; if (!rangeReads2Lock.isEmpty(rangeToken.getKey())) { Range<Value> containing = rangeReads2Lock.get(rangeToken.getKey(), rangeToken.getValues()[0]); if (containing != null) { rangeReads2Lock.remove(rangeToken.getKey(), containing); Iterable<Range<Value>> xor = Ranges.xor(Range.singleton(rangeToken.getValues()[0]), containing); for (Range<Value> range : xor) { rangeReads2Lock.put(rangeToken.getKey(), range); } } } type = LockType.RANGE_WRITE; } else { reads2Lock.remove(token); type = LockType.WRITE; } LockDescription lock = LockDescription.forToken(token, lockService, rangeLockService, type); if (lock.getLock().tryLock()) { locks.put(lock.getToken(), lock); } else { return false; } } // Grab the read locks. We can be sure that any remaining // intentions are not covered by any of the write locks we // grabbed previously. for (Token token : reads2Lock) { if (notifiedAboutVersionChange) { return false; } LockDescription lock = LockDescription.forToken(token, lockService, rangeLockService, LockType.READ); if (lock.getLock().tryLock()) { locks.put(lock.getToken(), lock); } else { return false; } } // Grab the range read locks. We can be sure that any remaining // intentions are not covered by any of the range write locks we // grabbed previously. for (Entry<Text, RangeSet<Value>> entry : rangeReads2Lock.ranges.entrySet()) { /* (Authorized) */ if (notifiedAboutVersionChange) { return false; } Text key = entry.getKey(); for (Range<Value> range : entry.getValue().asRanges()) { RangeToken rangeToken = Ranges.convertToRangeToken(key, range); LockDescription lock = LockDescription.forToken(rangeToken, lockService, rangeLockService, LockType.RANGE_READ); if (lock.getLock().tryLock()) { locks.put(lock.getToken(), lock); } else { return false; } } } } catch (NullPointerException e) { // If we are notified a version change while grabbing locks, we // abort immediately which means that #locks will become null. return false; } return true; } }
From source file:net.sf.mzmine.modules.peaklistmethods.io.mztabimport.MzTabImportTask.java
private void importSmallMolecules(PeakList newPeakList, MZTabFile mzTabFile, Map<Integer, RawDataFile> rawDataFiles) { SortedMap<Integer, Assay> assayMap = mzTabFile.getMetadata().getAssayMap(); Collection<SmallMolecule> smallMolecules = mzTabFile.getSmallMolecules(); // Loop through SML data String formula, description, database, url = ""; double mzExp = 0, abundance = 0, peak_mz = 0, peak_rt = 0, peak_height = 0, rtValue = 0; // int charge = 0; int rowCounter = 0; for (SmallMolecule smallMolecule : smallMolecules) { // Stop the process if cancel() was called if (isCanceled()) return; rowCounter++;//from w ww .ja va 2 s . c om formula = smallMolecule.getChemicalFormula(); // smile = smallMolecule.getSmiles(); // inchiKey = smallMolecule.getInchiKey(); description = smallMolecule.getDescription(); // species = smallMolecule.getSpecies(); database = smallMolecule.getDatabase(); // dbVersion = smallMolecule.getDatabaseVersion(); // reliability = smallMolecule.getReliability(); if (smallMolecule.getURI() != null) { url = smallMolecule.getURI().toString(); } String identifier = smallMolecule.getIdentifier().toString(); SplitList<Double> rt = smallMolecule.getRetentionTime(); // SplitList<Modification> modifications = // smallMolecule.getModifications(); if (smallMolecule.getExpMassToCharge() != null) { mzExp = smallMolecule.getExpMassToCharge(); } // if (smallMolecule.getCharge() != null) charge = // smallMolecule.getCharge(); // Calculate average RT if multiple values are available if (rt != null && !rt.isEmpty()) { rtValue = DoubleMath.mean(rt); } if ((url != null) && (url.equals("null"))) { url = null; } if (identifier.equals("null")) { identifier = null; } if (description == null && identifier != null) { description = identifier; } // Add shared information to row SimplePeakListRow newRow = new SimplePeakListRow(rowCounter); newRow.setAverageMZ(mzExp); newRow.setAverageRT(rtValue); if (description != null) { SimplePeakIdentity newIdentity = new SimplePeakIdentity(description, formula, database, identifier, url); newRow.addPeakIdentity(newIdentity, false); } // Add raw data file entries to row for (Entry<Integer, RawDataFile> rawDataEntry : rawDataFiles.entrySet()) { RawDataFile rawData = rawDataEntry.getValue(); Assay dataFileAssay = assayMap.get(rawDataEntry.getKey()); abundance = 0; peak_mz = 0; peak_rt = 0; peak_height = 0; if (smallMolecule.getAbundanceColumnValue(dataFileAssay) != null) { abundance = smallMolecule.getAbundanceColumnValue(dataFileAssay); } if (smallMolecule.getOptionColumnValue(dataFileAssay, "peak_mz") != null) { peak_mz = Double.parseDouble(smallMolecule.getOptionColumnValue(dataFileAssay, "peak_mz")); } else { peak_mz = mzExp; } if (smallMolecule.getOptionColumnValue(dataFileAssay, "peak_rt") != null) { peak_rt = Double.parseDouble(smallMolecule.getOptionColumnValue(dataFileAssay, "peak_rt")); } else { peak_rt = rtValue; } if (smallMolecule.getOptionColumnValue(dataFileAssay, "peak_height") != null) { peak_height = Double .parseDouble(smallMolecule.getOptionColumnValue(dataFileAssay, "peak_height")); } else { peak_height = 0.0; } int scanNumbers[] = {}; DataPoint finalDataPoint[] = new DataPoint[1]; finalDataPoint[0] = new SimpleDataPoint(peak_mz, peak_height); int representativeScan = 0; int fragmentScan = 0; Range<Double> finalRTRange = Range.singleton(peak_rt); Range<Double> finalMZRange = Range.singleton(peak_mz); Range<Double> finalIntensityRange = Range.singleton(peak_height); FeatureStatus status = FeatureStatus.DETECTED; Feature peak = new SimpleFeature(rawData, peak_mz, peak_rt, peak_height, abundance, scanNumbers, finalDataPoint, status, representativeScan, fragmentScan, finalRTRange, finalMZRange, finalIntensityRange); if (abundance > 0) { newRow.addPeak(rawData, peak); } } // Add row to peak list newPeakList.addRow(newRow); } }
From source file:org.dishevelled.variation.cytoscape3.internal.VariationModel.java
/** * Return zero or more features that overlap with the specified variation. * * @param variation variation, must not be null * @return zero or more features that overlap with the specified variation *///from w w w . j a v a2 s.co m Iterable<Feature> hit(final Variation variation) { checkNotNull(variation); List<Feature> hits = Lists.newArrayList(); RangeTree<Long> rangeTree = rangeTrees.get(variation.getRegion()); Range<Long> query; if (variation.getStart() == variation.getEnd()) { query = Range.singleton(variation.getStart()); } // todo: Ensembl REST client variation query returns end < start for deletions, e.g ref - alt [AAA] else if (variation.getEnd() < variation.getStart()) { query = Range.closedOpen(variation.getEnd(), variation.getStart()); } else { query = Range.closedOpen(variation.getStart(), variation.getEnd()); } for (Range<Long> range : rangeTree.intersect(query)) { hits.add(featuresToRanges.inverse().get(range)); } return hits; }
From source file:fr.openwide.core.export.excel.AbstractExcelTableExport.java
/** * Finalise la cration de la feuille de calcul, notamment en demandant le * redimensionnement automatique des colonnes. * /*from w w w . ja v a 2s.c o m*/ * @param sheet feuilles de calcul * @param columnInfos collection contenant les informations de colonnes * @param landscapePrintSetup dfinit si la feuille est imprime en paysage ou non */ protected void finalizeSheet(Sheet sheet, Collection<ColumnInformation> columnInfos, boolean landscapePrintSetup) { RangeMap<Integer, ColumnInformation> map = TreeRangeMap.create(); int index = 0; for (ColumnInformation column : columnInfos) { map.put(Range.singleton(index), column); ++index; } finalizeSheet(sheet, map, landscapePrintSetup); }
From source file:org.apache.calcite.rex.RexSimplify.java
private static RexNode processRange(RexBuilder rexBuilder, List<RexNode> terms, Map<String, Pair<Range, List<RexNode>>> rangeTerms, RexNode term, RexNode ref, RexLiteral constant, SqlKind comparison) {/*from ww w. j a v a2s . c om*/ final Comparable v0 = constant.getValue(); Pair<Range, List<RexNode>> p = rangeTerms.get(ref.toString()); if (p == null) { Range r; switch (comparison) { case EQUALS: r = Range.singleton(v0); break; case LESS_THAN: r = Range.lessThan(v0); break; case LESS_THAN_OR_EQUAL: r = Range.atMost(v0); break; case GREATER_THAN: r = Range.greaterThan(v0); break; case GREATER_THAN_OR_EQUAL: r = Range.atLeast(v0); break; default: throw new AssertionError(); } rangeTerms.put(ref.toString(), new Pair(r, ImmutableList.of(term))); } else { // Exists boolean removeUpperBound = false; boolean removeLowerBound = false; Range r = p.left; switch (comparison) { case EQUALS: if (!r.contains(v0)) { // Range is empty, not satisfiable return rexBuilder.makeLiteral(false); } rangeTerms.put(ref.toString(), new Pair(Range.singleton(v0), ImmutableList.of(term))); // remove terms.removeAll(p.right); break; case LESS_THAN: { int comparisonResult = 0; if (r.hasUpperBound()) { comparisonResult = v0.compareTo(r.upperEndpoint()); } if (comparisonResult <= 0) { // 1) No upper bound, or // 2) We need to open the upper bound, or // 3) New upper bound is lower than old upper bound if (r.hasLowerBound()) { if (v0.compareTo(r.lowerEndpoint()) < 0) { // Range is empty, not satisfiable return rexBuilder.makeLiteral(false); } // a <= x < b OR a < x < b r = Range.range(r.lowerEndpoint(), r.lowerBoundType(), v0, BoundType.OPEN); } else { // x < b r = Range.lessThan(v0); } if (r.isEmpty()) { // Range is empty, not satisfiable return rexBuilder.makeLiteral(false); } // remove prev upper bound removeUpperBound = true; } else { // Remove this term as it is contained in current upper bound terms.remove(term); } break; } case LESS_THAN_OR_EQUAL: { int comparisonResult = -1; if (r.hasUpperBound()) { comparisonResult = v0.compareTo(r.upperEndpoint()); } if (comparisonResult < 0) { // 1) No upper bound, or // 2) New upper bound is lower than old upper bound if (r.hasLowerBound()) { if (v0.compareTo(r.lowerEndpoint()) < 0) { // Range is empty, not satisfiable return rexBuilder.makeLiteral(false); } // a <= x <= b OR a < x <= b r = Range.range(r.lowerEndpoint(), r.lowerBoundType(), v0, BoundType.CLOSED); } else { // x <= b r = Range.atMost(v0); } if (r.isEmpty()) { // Range is empty, not satisfiable return rexBuilder.makeLiteral(false); } // remove prev upper bound removeUpperBound = true; } else { // Remove this term as it is contained in current upper bound terms.remove(term); } break; } case GREATER_THAN: { int comparisonResult = 0; if (r.hasLowerBound()) { comparisonResult = v0.compareTo(r.lowerEndpoint()); } if (comparisonResult >= 0) { // 1) No lower bound, or // 2) We need to open the lower bound, or // 3) New lower bound is greater than old lower bound if (r.hasUpperBound()) { if (v0.compareTo(r.upperEndpoint()) > 0) { // Range is empty, not satisfiable return rexBuilder.makeLiteral(false); } // a < x <= b OR a < x < b r = Range.range(v0, BoundType.OPEN, r.upperEndpoint(), r.upperBoundType()); } else { // x > a r = Range.greaterThan(v0); } if (r.isEmpty()) { // Range is empty, not satisfiable return rexBuilder.makeLiteral(false); } // remove prev lower bound removeLowerBound = true; } else { // Remove this term as it is contained in current lower bound terms.remove(term); } break; } case GREATER_THAN_OR_EQUAL: { int comparisonResult = 1; if (r.hasLowerBound()) { comparisonResult = v0.compareTo(r.lowerEndpoint()); } if (comparisonResult > 0) { // 1) No lower bound, or // 2) New lower bound is greater than old lower bound if (r.hasUpperBound()) { if (v0.compareTo(r.upperEndpoint()) > 0) { // Range is empty, not satisfiable return rexBuilder.makeLiteral(false); } // a <= x <= b OR a <= x < b r = Range.range(v0, BoundType.CLOSED, r.upperEndpoint(), r.upperBoundType()); } else { // x >= a r = Range.atLeast(v0); } if (r.isEmpty()) { // Range is empty, not satisfiable return rexBuilder.makeLiteral(false); } // remove prev lower bound removeLowerBound = true; } else { // Remove this term as it is contained in current lower bound terms.remove(term); } break; } default: throw new AssertionError(); } if (removeUpperBound) { ImmutableList.Builder<RexNode> newBounds = ImmutableList.builder(); for (RexNode e : p.right) { if (e.isA(SqlKind.LESS_THAN) || e.isA(SqlKind.LESS_THAN_OR_EQUAL)) { terms.remove(e); } else { newBounds.add(e); } } newBounds.add(term); rangeTerms.put(ref.toString(), new Pair(r, newBounds.build())); } else if (removeLowerBound) { ImmutableList.Builder<RexNode> newBounds = ImmutableList.builder(); for (RexNode e : p.right) { if (e.isA(SqlKind.GREATER_THAN) || e.isA(SqlKind.GREATER_THAN_OR_EQUAL)) { terms.remove(e); } else { newBounds.add(e); } } newBounds.add(term); rangeTerms.put(ref.toString(), new Pair(r, newBounds.build())); } } // Default return null; }