List of usage examples for com.google.common.collect RangeMap put
void put(Range<K> range, V value);
From source file:org.apache.niolex.common.guava.GuavaCollections.java
/** * @param args/* www . j a va 2s . c om*/ */ public static void main(String[] args) { Multiset<String> wordsMultiset = HashMultiset.create(); wordsMultiset.add("abc"); wordsMultiset.add("abc"); wordsMultiset.add("abcd"); System.out.println("count => " + wordsMultiset.count("abc")); System.out.println("count => " + wordsMultiset.count("abcd")); BiMap<String, String> biMap = HashBiMap.create(); biMap.put("good", "morning"); biMap.put("bad", "afternoon"); System.out.println("good => " + biMap.get("good")); System.out.println("afternoon => " + biMap.inverse().get("afternoon")); RangeMap<Integer, String> rangeMap = TreeRangeMap.create(); rangeMap.put(Range.closed(1, 11), "Nice"); rangeMap.put(Range.openClosed(11, 15), "Girl"); System.out.println("11 => " + rangeMap.get(11)); System.out.println("12 => " + rangeMap.get(12)); System.out.println("15 => " + rangeMap.get(15)); System.out.println("16 => " + rangeMap.get(16)); List<Integer> countUp = Ints.asList(1, 2, 3, 4, 5); List<Integer> countDown = Lists.reverse(countUp); // {5, 4, 3, 2, 1} System.out.println("countUp => " + countUp); System.out.println("countDown => " + countDown); }
From source file:org.mskcc.shenkers.data.interval.RangeTools.java
public static <T> RangeMap<Integer, T> asClosed(RangeMap<Integer, T> s) { RangeMap<Integer, T> closedIntervalSet = TreeRangeMap.create(); Map<Range<Integer>, T> map = s.asMapOfRanges(); for (Map.Entry<Range<Integer>, T> r : map.entrySet()) { closedIntervalSet.put(asClosed(r.getKey()), r.getValue()); }//from w w w . j a v a 2s. com return closedIntervalSet; }
From source file:org.mskcc.shenkers.control.track.bigwig.BigWigUtil.java
public static RangeMap<Integer, Double> values(BBFileReader bbfr, String chr, int start, int end, int zoom) { boolean contained = false; Iterator<BBItem> iterator = null; if (zoom == 0) { BigWigIterator bwi = bbfr.getBigWigIterator(chr, start - 1, chr, end, false); iterator = StreamSupport.stream(Spliterators.spliteratorUnknownSize(bwi, 0), false) .map(w -> new BBItem(w)).iterator(); } else {//www . java 2s . co m ZoomLevelIterator zli = bbfr.getZoomLevelIterator(zoom, chr, start - 1, chr, end, contained); iterator = StreamSupport.stream(Spliterators.spliteratorUnknownSize(zli, 0), false) .map(w -> new BBItem(w)).iterator(); } RangeMap<Integer, Double> cov = TreeRangeMap.create(); while (iterator.hasNext()) { BBItem wi = iterator.next(); cov.put(Range.closed(wi.getStart() + 1, wi.getEnd()), wi.getValue()); } return cov; }
From source file:org.jpmml.evaluator.DiscretizationUtil.java
static private RangeMap<Double, String> parseBinRanges(Discretize discretize) { RangeMap<Double, String> result = TreeRangeMap.create(); List<DiscretizeBin> discretizeBins = discretize.getDiscretizeBins(); for (DiscretizeBin discretizeBin : discretizeBins) { Interval interval = discretizeBin.getInterval(); String binValue = discretizeBin.getBinValue(); if (interval == null || binValue == null) { throw new InvalidFeatureException(discretizeBin); }//from ww w . java 2 s.c o m Range<Double> range = toRange(interval); result.put(range, binValue); } return result; }
From source file:radsoft.syntaxhighlighter.SyntaxHighlighter.java
private static void addMatch(RangeMap<Integer, String> matches, int start, int end, String styleKey) { if (styleKey == null) throw new NullPointerException("argument 'styleKey' cannot be null"); Map.Entry<Range<Integer>, String> e = matches.getEntry(start); if (e == null || start < e.getKey().lowerEndpoint()) { if (e != null) matches.remove(e.getKey());/*from w w w . java 2 s. c om*/ e = matches.getEntry(end - 1); if (e != null) matches.remove(e.getKey()); Range<Integer> r = Range.closedOpen(start, end); matches.put(r, styleKey); } }
From source file:org.mskcc.shenkers.data.interval.DiscreteRangeMap.java
public RangeMap<Integer, Double> add(RangeMap<Integer, Double> rm, Range<Integer> r, Double d) { RangeMap<Integer, Double> ram = TreeRangeMap.create(); ram.putAll(rm);//w w w .ja v a 2 s . c o m ram.put(r, d); rm.subRangeMap(r).asMapOfRanges().forEach((range, val) -> ram.put(range, val + d)); return ram; }
From source file:org.mskcc.shenkers.data.interval.DiscreteRangeMap.java
public RangeMap<Double, Double> toReal(RangeMap<Integer, Double> rm) { RangeMap<Double, Double> ram = TreeRangeMap.create(); rm.asMapOfRanges().forEach((range, val) -> ram.put(asReal(range), val)); return ram;//from www . j a v a2 s.c om }
From source file:com.google.googlejavaformat.java.RemoveUnusedImports.java
/** Construct replacements to fix unused imports. */ private static RangeMap<Integer, String> buildReplacements(String contents, JCCompilationUnit unit, Set<String> usedNames, Multimap<String, Range<Integer>> usedInJavadoc) { RangeMap<Integer, String> replacements = TreeRangeMap.create(); for (JCImport importTree : unit.getImports()) { String simpleName = getSimpleName(importTree); if (!isUnused(unit, usedNames, usedInJavadoc, importTree, simpleName)) { continue; }/*from ww w.ja v a 2s .c o m*/ // delete the import int endPosition = importTree.getEndPosition(unit.endPositions); endPosition = Math.max(CharMatcher.isNot(' ').indexIn(contents, endPosition), endPosition); String sep = Newlines.guessLineSeparator(contents); if (endPosition + sep.length() < contents.length() && contents.subSequence(endPosition, endPosition + sep.length()).toString().equals(sep)) { endPosition += sep.length(); } replacements.put(Range.closedOpen(importTree.getStartPosition(), endPosition), ""); // fully qualify any javadoc references with the same simple name as a deleted // non-static import if (!importTree.isStatic()) { for (Range<Integer> docRange : usedInJavadoc.get(simpleName)) { if (docRange == null) { continue; } String replaceWith = importTree.getQualifiedIdentifier().toString(); replacements.put(docRange, replaceWith); } } } return replacements; }
From source file:org.sosy_lab.cpachecker.cfa.CSourceOriginMapping.java
void mapInputLineRangeToDelta(String inputFilename, String originFilename, int fromInputLineNumber, int toInputLineNumber, int deltaLinesToOrigin) { RangeMap<Integer, Pair<String, Integer>> fileMapping = mapping.get(inputFilename); if (fileMapping == null) { fileMapping = TreeRangeMap.create(); mapping.put(inputFilename, fileMapping); }//w w w . j a va 2s . co m Range<Integer> lineRange = Range.openClosed(fromInputLineNumber - 1, toInputLineNumber); fileMapping.put(lineRange, Pair.of(originFilename, deltaLinesToOrigin)); }
From source file:io.blobkeeper.cluster.service.ReplicationClientServiceImpl.java
@Override public void replicate(@NotNull DifferenceInfo differenceInfo, @NotNull Address dst) { replicationStatistic.onReplicationRequest(); Partition partition = partitionService.getById(differenceInfo.getDisk(), differenceInfo.getPartition()); if (!isReplicationAvailable(partition, differenceInfo)) { return;// w w w . j a v a 2 s.c o m } // TODO: calculate what types are different instead whole range RangeMap<Long, LeafNode> nodes = TreeRangeMap.create(); differenceInfo.getDifference().stream().forEach(diff -> nodes.put(diff.getRange(), diff)); log.info("File will be synced {}, dst node {}", differenceInfo, dst); File file = null; int sentElts = 1; try { file = fileListService.getFile(differenceInfo.getDisk(), differenceInfo.getPartition()); if (null == file) { log.error("Can't replicate blob file {}, dst node {}", differenceInfo, dst); return; } List<IndexElt> elts = new ArrayList<>(indexService.getListByPartition(partition)); // sort it by offset, to read file consequentially sort(elts, new IndexEltOffsetComparator()); for (IndexElt elt : elts) { // not in diff if (null == nodes.get(elt.getId()) && !differenceInfo.isCompletelyDifferent()) { continue; } // pause to send new files if (sentElts % configuration.getReplicationMaxFiles() == 0) { sleep(configuration.getReplicationDelay()); } ByteBuffer buffer; try { buffer = FileUtils.readFile(file, elt.getOffset(), elt.getLength()); } catch (Exception e) { log.error("Can't read data for index {}, required {}", elt, elt.getLength(), e); continue; } byte[] bufferBytes = new byte[buffer.remaining()]; buffer.get(bufferBytes); if (bufferBytes.length < elt.getLength()) { log.error("Can't replicate elt {}", elt); continue; } ReplicationFile replicationFile = new ReplicationFile(elt.getDiskIndexElt(), bufferBytes); try { replicate(replicationFile, dst); } catch (ReplicationServiceException e) { log.error("Can't replicate file {}", elt, e); } } } catch (Exception e) { log.error("Can't replicate block {}", partition, e); } finally { if (null != file) { try { file.close(); } catch (Exception ignored) { } } } }