当前位置: 首页>>代码示例>>Java>>正文


Java RangeMap.put方法代码示例

本文整理汇总了Java中com.google.common.collect.RangeMap.put方法的典型用法代码示例。如果您正苦于以下问题:Java RangeMap.put方法的具体用法?Java RangeMap.put怎么用?Java RangeMap.put使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.common.collect.RangeMap的用法示例。


在下文中一共展示了RangeMap.put方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: update

import com.google.common.collect.RangeMap; //导入方法依赖的package包/类
@Override
public synchronized void update(Fragment fragment) {
  RangeMap<RangeValue, String> ranges = getRanges(fragment.getSegmentId());
  Map.Entry<Range<RangeValue>, String> entry = ranges.getEntry(RangeValue.of(fragment.getStartVersion()));
  if (entry != null) {
      Preconditions.checkArgument(entry.getValue().equals(fragment.getBlock().getBlockId()),
      "New range overlaps an existing by block Id");
    Preconditions.checkArgument(fragment.getStartVersion() == entry.getKey().lowerEndpoint().get(),
      "New range overlaps an existing by start version");
    entry.getKey().upperEndpoint().set(fragment.isLast() ? Long.MAX_VALUE : fragment.getLastModifiedVersion());
  } else {
    ranges.put(Range.closed(RangeValue.of(fragment.getStartVersion()),
      RangeValue.of(fragment.isLast() ? Long.MAX_VALUE : fragment.getLastModifiedVersion())),
      fragment.getBlock().getBlockId());
  }
}
 
开发者ID:jorkey,项目名称:Wiab.pro,代码行数:17,代码来源:BlockIndexImpl.java

示例2: getRanges

import com.google.common.collect.RangeMap; //导入方法依赖的package包/类
private RangeMap<RangeValue, String> getRanges(SegmentId segmentId) {
  RangeMap<RangeValue, String> ranges = rangeMap.getIfPresent(segmentId);
  if (ranges == null) {
    try {
      ranges = rangeMap.get(segmentId);
      if (serialized != null) {
        int index = serialized.getSegmentIdList().indexOf(segmentId.serialize());
        if (index != -1) {
          SegmentRanges serializedRanges = serialized.getSegmentRanges(index);
          for (ByteString serializedFragment : serializedRanges.getRawFragmentRangesList()) {
            ProtoBlockIndex.BlockIndex.FragmentRange fragment =
                ProtoBlockIndex.BlockIndex.FragmentRange.parseFrom(serializedFragment);
            ranges.put(Range.closed(RangeValue.of(fragment.getSourceVersion()),
                RangeValue.of(fragment.getTargetVersion())), fragment.getBlockId());
          }
        }
      }
    } catch (ExecutionException | InvalidProtocolBufferException ex) {
      throw new RuntimeException(ex);
    }
  }
  return ranges;
}
 
开发者ID:jorkey,项目名称:Wiab.pro,代码行数:24,代码来源:BlockIndexImpl.java

示例3: parseDiscretize

import com.google.common.collect.RangeMap; //导入方法依赖的package包/类
static
private RangeMap<Double, String> parseDiscretize(Discretize discretize){
	RangeMap<Double, String> result = TreeRangeMap.create();

	List<DiscretizeBin> discretizeBins = discretize.getDiscretizeBins();
	for(DiscretizeBin discretizeBin : discretizeBins){
		Interval interval = discretizeBin.getInterval();
		if(interval == null){
			throw new MissingAttributeException(discretizeBin, PMMLAttributes.DISCRETIZEBIN_INTERVAL);
		}

		Range<Double> range = toRange(interval);

		String binValue = discretizeBin.getBinValue();
		if(binValue == null){
			throw new MissingAttributeException(discretizeBin, PMMLAttributes.DISCRETIZEBIN_BINVALUE);
		}

		result.put(range, binValue);
	}

	return result;
}
 
开发者ID:jpmml,项目名称:jpmml-evaluator,代码行数:24,代码来源:DiscretizationUtil.java

示例4: main

import com.google.common.collect.RangeMap; //导入方法依赖的package包/类
public static void main(String[] args) {

		// define rages for checks
		RangeMap<Integer, Double> checkFee = TreeRangeMap.create();
		checkFee.put(Range.closed(0, 19), .1);
		checkFee.put(Range.closed(20, 39), .8);
		checkFee.put(Range.closed(40, 59), .6);
		checkFee.put(Range.closed(60, Integer.MAX_VALUE), .4);

		// Create a Scanner object for keyboard input.
		Scanner keyboard = new Scanner(System.in);

		// Get the number of checks written.
		System.out.print("Enter the number of checks written " + "this month: ");
		int numChecks = keyboard.nextInt();

		//close scanner
		keyboard.close();

		// calculate total fee
		double total = BASE_FEE + (checkFee.get(numChecks) * numChecks); 
		
		// Display the total bank fees.
		System.out.printf("The total fees are $%.2f\n", total);
	}
 
开发者ID:leveluplunch,项目名称:levelup-java-exercises,代码行数:26,代码来源:BankCharges.java

示例5: finalizeSheet

import com.google.common.collect.RangeMap; //导入方法依赖的package包/类
/**
 * Finalise la création de la feuille de calcul, notamment en demandant le
 * redimensionnement automatique des colonnes.
 * 
 * @param sheet feuilles de calcul
 * @param columnInfos collection contenant les informations de colonnes
 * @param landscapePrintSetup définit si la feuille est imprimée 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);
}
 
开发者ID:openwide-java,项目名称:owsi-core-parent,代码行数:18,代码来源:AbstractExcelTableExport.java

示例6: setDynamismLevels

import com.google.common.collect.RangeMap; //导入方法依赖的package包/类
/**
 * Sets the dynamism levels.
 * @param levels At least one level must be given. The default level is
 *          <code>.5</code>.
 * @return This, as per the builder pattern.
 */
public Builder setDynamismLevels(Iterable<Double> levels) {
  checkArgument(Iterables.size(levels) > 0);
  final RangeSet<Double> rangeSet = TreeRangeSet.create();
  final Set<Range<Double>> dynamismLevelsB = new LinkedHashSet<>();
  final RangeMap<Double, Double> map = TreeRangeMap.create();
  for (final Double d : levels) {
    checkArgument(d >= 0d && d <= 1d);
    final Range<Double> newRange = createDynRange(d);
    checkArgument(
      rangeSet.subRangeSet(newRange).isEmpty(),
      "Can not add dynamism level %s, it is too close to another level.",
      d);
    rangeSet.add(newRange);
    dynamismLevelsB.add(newRange);
    map.put(newRange, d);
  }

  final SetMultimap<TimeSeriesType, Range<Double>> timeSeriesTypes =
    LinkedHashMultimap
      .<TimeSeriesType, Range<Double>>create();

  for (final Range<Double> r : dynamismLevelsB) {
    checkArgument(DYNAMISM_MAP.get(r.lowerEndpoint()) != null);
    checkArgument(DYNAMISM_MAP.get(r.lowerEndpoint()) == DYNAMISM_MAP.get(r
      .upperEndpoint()));

    timeSeriesTypes.put(DYNAMISM_MAP.get(r.lowerEndpoint()), r);
  }
  dynamismLevels = ImmutableSetMultimap.copyOf(timeSeriesTypes);
  dynamismRangeMap = ImmutableRangeMap.copyOf(map);
  return this;
}
 
开发者ID:rinde,项目名称:pdptw-dataset-generator,代码行数:39,代码来源:DatasetGenerator.java

示例7: buildReplacements

import com.google.common.collect.RangeMap; //导入方法依赖的package包/类
/** 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;
    }
    // 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()).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;
}
 
开发者ID:google,项目名称:google-java-format,代码行数:36,代码来源:RemoveUnusedImports.java

示例8: parsePartitions

import com.google.common.collect.RangeMap; //导入方法依赖的package包/类
/**
 * Create {@link HomRefBlock}s which will collectively accept variants of any genotype quality
 *
 * Each individual block covers a band of genotype qualities with the splits between bands occurring at values in {@code gqPartitions}.
 * There will be {@code gqPartitions.size() +1} bands produced covering the entire possible range of genotype qualities from 0 to {@link VCFConstants#MAX_GENOTYPE_QUAL}.
 *
 * @param gqPartitions proposed GQ partitions
 * @return a list of HomRefBlocks accepting bands of genotypes qualities split at the points specified in gqPartitions
 */
@VisibleForTesting
static RangeMap<Integer,Range<Integer>> parsePartitions(final List<Integer> gqPartitions) {
    Utils.nonEmpty(gqPartitions);
    Utils.containsNoNull(gqPartitions, "The list of GQ partitions contains a null integer");
    final RangeMap<Integer, Range<Integer>> result = TreeRangeMap.create();
    int lastThreshold = 0;
    for (final Integer value : gqPartitions) {
        if (value < 0) {
            throw new IllegalArgumentException("The list of GQ partitions contains a non-positive integer.");
        } else if (value > MAX_GENOTYPE_QUAL + 1) {
            throw new IllegalArgumentException(String.format("The value %d in the list of GQ partitions is greater than VCFConstants.MAX_GENOTYPE_QUAL + 1 = %d.", value, MAX_GENOTYPE_QUAL + 1));
        } else if (value < lastThreshold) {
            throw new IllegalArgumentException(String.format("The list of GQ partitions is out of order. Previous value is %d but the next is %d.", lastThreshold, value));
        } else if (value == lastThreshold) {
            throw new IllegalArgumentException(String.format("The value %d appears more than once in the list of GQ partitions.", value));
        }

        result.put(Range.closedOpen(lastThreshold, value), Range.closedOpen(lastThreshold, value));
        lastThreshold = value;
    }

    if (lastThreshold <= MAX_GENOTYPE_QUAL) {
        result.put(Range.closedOpen(lastThreshold, MAX_GENOTYPE_QUAL + 1), Range.closedOpen(lastThreshold,MAX_GENOTYPE_QUAL + 1));
    }

    return result;
}
 
开发者ID:broadinstitute,项目名称:gatk,代码行数:37,代码来源:GVCFWriter.java

示例9: google_guava_range_map_example

import com.google.common.collect.RangeMap; //导入方法依赖的package包/类
@Test
public void google_guava_range_map_example () {

	RangeMap<Integer, String> gradeScale = TreeRangeMap.create();
	gradeScale.put(Range.closed(0, 60), "F");
	gradeScale.put(Range.closed(61, 70), "D");
	gradeScale.put(Range.closed(71, 80), "C");
	gradeScale.put(Range.closed(81, 90), "B");
	gradeScale.put(Range.closed(91, 100), "A");
	
	String grade = gradeScale.get(77);
	
	assertEquals("C", grade);
}
 
开发者ID:wq19880601,项目名称:java-util-examples,代码行数:15,代码来源:RangeMapExample.java

示例10: getCachedValues

import com.google.common.collect.RangeMap; //导入方法依赖的package包/类
public static List<DoubleStream> getCachedValues(String key, PeriodicRange<?> range,
		Function<PeriodicRange<?>, List<DoubleStream>> function) {
	@SuppressWarnings("unchecked")
	Periodicity<Period> freq = (Periodicity<Period>) range.periodicity();
	String wholeKey = key + ":" + range.periodicity().code();
	RangeMap<Long, CachedSeriesList> cache = null;
	synchronized (seriesCache) {
		if (range.clearCache() || !seriesCache.containsKey(wholeKey)) {
			seriesCache.put(wholeKey, TreeRangeMap.create());
		}
		cache = seriesCache.get(wholeKey);
	}
	synchronized (cache) {
		try {
			Range<Long> requestedRange = Range.closed(range.start().longValue(), range.end().longValue());
			Set<Range<Long>> toRemove = new HashSet<>();
			List<DoubleStream> chunkData = new ArrayList<>();
			long current = requestedRange.lowerEndpoint();
			long chunkStart = current;
			Optional<Long> expirationTime = Optional.empty();
			for (Map.Entry<Range<Long>, CachedSeriesList> e : cache.subRangeMap(requestedRange).asMapOfRanges()
					.entrySet()) {
				toRemove.add(e.getKey());
				if(e.getValue().getExpirationTime().isPresent()) {
					if(System.currentTimeMillis() > e.getValue().getExpirationTime().get()) {
						break;
					} else {
						expirationTime = e.getValue().getExpirationTime();
					}
				}
				long thisChunkStart = e.getValue().getRange().start().longValue();
				long thisChunkEnd = e.getValue().getRange().end().longValue();
				chunkStart = Long.min(chunkStart, thisChunkStart);
				if (current < thisChunkStart) {
					concat(chunkData, function.apply(freq.range(current, thisChunkStart - 1, false)));
				}
				concat(chunkData, e.getValue().getSeries());
				current = thisChunkEnd + 1;
			}
			if (current <= requestedRange.upperEndpoint()) {
				concat(chunkData, function.apply(freq.range(current, requestedRange.upperEndpoint(), false)));
				current = requestedRange.upperEndpoint() + 1;
			}
			toRemove.stream().forEach(cache::remove);
			long now = freq.from(LocalDate.now()).longValue();
			if(now > chunkStart) {
				long endOfPast = Math.min(now - 1, current - 1);
				cache.put(Range.closed(chunkStart, endOfPast),
						new CachedSeriesList(freq.range(chunkStart,  endOfPast, false),
								dup(chunkData,0, (int) (1 + endOfPast - chunkStart)), Optional.empty()));
			}
			if(current - 1 >= now) {
				long startOfNow = Math.max(now, chunkStart);
				cache.put(Range.closed(startOfNow, current - 1),
						new CachedSeriesList(freq.range(startOfNow,  current - 1, false),
								dup(chunkData, (int) (startOfNow - chunkStart), (int) (current - startOfNow)),
								Optional.of(expirationTime.orElse(System.currentTimeMillis() + CURRENT_DATA_TIMEOUT))));
			}
			final long finalStart = chunkStart;
			return chunkData.stream()
					.map(s -> s.skip(requestedRange.lowerEndpoint() - finalStart).limit(range.size()))
					.collect(Collectors.toList());
		} catch (RuntimeException re) {
			seriesCache.remove(wholeKey);
			throw re;
		}
	}
}
 
开发者ID:punkbrwstr,项目名称:pinto,代码行数:69,代码来源:Cache.java


注:本文中的com.google.common.collect.RangeMap.put方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。