Java 类com.google.common.collect.ImmutableRangeMap 实例源码

项目:java-monitoring-client-library    文件:MutableDistributionTest.java   
@Test
public void testAdd_positiveThenNegativeValue() {
  distribution.add(2.0);
  distribution.add(-2.0);

  assertThat(distribution.count()).isEqualTo(2);
  assertThat(distribution.mean()).isWithin(0.0).of(0.0);
  assertThat(distribution.sumOfSquaredDeviation()).isWithin(0.0).of(8.0);
  assertThat(distribution.intervalCounts())
      .isEqualTo(
          ImmutableRangeMap.<Double, Long>builder()
              .put(Range.lessThan(3.0), 2L)
              .put(Range.closedOpen(3.0, 5.0), 0L)
              .put(Range.atLeast(5.0), 0L)
              .build());
}
项目:java-monitoring-client-library    文件:MutableDistributionTest.java   
@Test
public void testAdd_wideRangeOfValues() {
  distribution.add(2.0);
  distribution.add(16.0);
  distribution.add(128.0, 5);
  distribution.add(1024.0, 0);

  assertThat(distribution.count()).isEqualTo(7);
  assertThat(distribution.mean()).isWithin(0.0).of(94.0);
  assertThat(distribution.sumOfSquaredDeviation()).isWithin(0.0).of(20328.0);
  assertThat(distribution.intervalCounts())
      .isEqualTo(
          ImmutableRangeMap.<Double, Long>builder()
              .put(Range.lessThan(3.0), 1L)
              .put(Range.closedOpen(3.0, 5.0), 0L)
              .put(Range.atLeast(5.0), 6L)
              .build());
}
项目:QDrill    文件:BlockMapBuilder.java   
/**
 * Builds a mapping of block locations to file byte range
 */
private ImmutableRangeMap<Long,BlockLocation> buildBlockMap(FileStatus status) throws IOException {
  final Timer.Context context = metrics.timer(BLOCK_MAP_BUILDER_TIMER).time();
  BlockLocation[] blocks;
  ImmutableRangeMap<Long,BlockLocation> blockMap;
  blocks = fs.getFileBlockLocations(status, 0 , status.getLen());
  ImmutableRangeMap.Builder<Long, BlockLocation> blockMapBuilder = new ImmutableRangeMap.Builder<Long,BlockLocation>();
  for (BlockLocation block : blocks) {
    long start = block.getOffset();
    long end = start + block.getLength();
    Range<Long> range = Range.closedOpen(start, end);
    blockMapBuilder = blockMapBuilder.put(range, block);
  }
  blockMap = blockMapBuilder.build();
  blockMapMap.put(status.getPath(), blockMap);
  context.stop();
  return blockMap;
}
项目:martini-core    文件:DefaultMixology.java   
protected RangeMap<Integer, ScenarioDefinition> getRangeMap(FeatureWrapper feature) {
    List<ScenarioDefinition> children = Lists.newArrayList(feature.getChildren());

    ImmutableRangeMap.Builder<Integer, ScenarioDefinition> builder = ImmutableRangeMap.builder();
    while (!children.isEmpty()) {
        ScenarioDefinition child = children.remove(0);
        Location location = child.getLocation();
        Integer childStart = location.getLine();

        ScenarioDefinition sibling = children.isEmpty() ? null : children.get(0);
        Location siblingLocation = null == sibling ? null : sibling.getLocation();
        Integer siblingStart = null == siblingLocation ? null : siblingLocation.getLine();

        Range<Integer> range = null == siblingStart ? Range.atLeast(childStart) : Range.closedOpen(childStart, siblingStart);
        builder.put(range, child);
    }
    return builder.build();
}
项目:dremio-oss    文件:BlockMapBuilder.java   
/**
 * Builds a mapping of block locations to file byte range
 */
private ImmutableRangeMap<Long,BlockLocation> buildBlockMap(FileStatus status) throws IOException {
  final Timer.Context context = metrics.timer(BLOCK_MAP_BUILDER_TIMER).time();
  BlockLocation[] blocks;
  ImmutableRangeMap<Long,BlockLocation> blockMap;
  blocks = fs.getFileBlockLocations(status, 0 , status.getLen());
  ImmutableRangeMap.Builder<Long, BlockLocation> blockMapBuilder = new ImmutableRangeMap.Builder<>();
  for (BlockLocation block : blocks) {
    long start = block.getOffset();
    long end = start + block.getLength();
    Range<Long> range = Range.closedOpen(start, end);
    blockMapBuilder = blockMapBuilder.put(range, block);
  }
  blockMap = blockMapBuilder.build();
  blockMapMap.put(status.getPath(), blockMap);
  context.stop();
  return blockMap;
}
项目:drill    文件:BlockMapBuilder.java   
/**
 * Builds a mapping of block locations to file byte range
 */
private ImmutableRangeMap<Long,BlockLocation> buildBlockMap(FileStatus status) throws IOException {
  final Timer.Context context = metrics.timer(BLOCK_MAP_BUILDER_TIMER).time();
  BlockLocation[] blocks;
  ImmutableRangeMap<Long,BlockLocation> blockMap;
  blocks = fs.getFileBlockLocations(status, 0 , status.getLen());
  ImmutableRangeMap.Builder<Long, BlockLocation> blockMapBuilder = new ImmutableRangeMap.Builder<Long,BlockLocation>();
  for (BlockLocation block : blocks) {
    long start = block.getOffset();
    long end = start + block.getLength();
    Range<Long> range = Range.closedOpen(start, end);
    blockMapBuilder = blockMapBuilder.put(range, block);
  }
  blockMap = blockMapBuilder.build();
  blockMapMap.put(status.getPath(), blockMap);
  context.stop();
  return blockMap;
}
项目:zookeeper-lite    文件:BinGenerator.java   
public static <V> BinGenerator<V> create(
        Random random, Iterable<? extends Pair<Float, ? extends V>> weightedValues) {
    final ImmutableRangeMap.Builder<Float, V> bins = ImmutableRangeMap.builder();
    Float lower = Float.valueOf(0.0f);
    for (Pair<Float, ? extends V> weightedValue: weightedValues) {
        if (weightedValue.first().floatValue() <= 0.0f) {
            continue;
        }
        Float upper = Float.valueOf(Floats.min(1.0f, lower.floatValue() + weightedValue.first().floatValue()));
        checkArgument(upper.floatValue() > lower.floatValue());
        Range<Float> range = Range.closedOpen(lower, upper);
        bins.put(range, weightedValue.second());
        lower = upper;
    }
    checkArgument(Float.compare(lower.floatValue(), 1.0f) == 0);
    return new BinGenerator<V>(random, bins.build());
}
项目:java-monitoring-client-library    文件:ImmutableDistribution.java   
@VisibleForTesting
static ImmutableDistribution create(
    double mean,
    double sumOfSquaredDeviation,
    long count,
    ImmutableRangeMap<Double, Long> intervalCounts,
    DistributionFitter distributionFitter) {
  checkDouble(mean);
  checkDouble(sumOfSquaredDeviation);
  checkArgument(count >= 0);

  return new AutoValue_ImmutableDistribution(
      mean, sumOfSquaredDeviation, count, intervalCounts, distributionFitter);
}
项目:java-monitoring-client-library    文件:MutableDistributionTest.java   
@Test
public void testAdd_oneValue() {
  distribution.add(5.0);

  assertThat(distribution.count()).isEqualTo(1);
  assertThat(distribution.mean()).isWithin(0.0).of(5.0);
  assertThat(distribution.sumOfSquaredDeviation()).isWithin(0.0).of(0);
  assertThat(distribution.intervalCounts())
      .isEqualTo(
          ImmutableRangeMap.<Double, Long>builder()
              .put(Range.lessThan(3.0), 0L)
              .put(Range.closedOpen(3.0, 5.0), 0L)
              .put(Range.atLeast(5.0), 1L)
              .build());
}
项目:java-monitoring-client-library    文件:MutableDistributionTest.java   
@Test
public void testAdd_zero() {
  distribution.add(0.0);

  assertThat(distribution.count()).isEqualTo(1);
  assertThat(distribution.mean()).isWithin(0.0).of(0.0);
  assertThat(distribution.sumOfSquaredDeviation()).isWithin(0.0).of(0);
  assertThat(distribution.intervalCounts())
      .isEqualTo(
          ImmutableRangeMap.<Double, Long>builder()
              .put(Range.lessThan(3.0), 1L)
              .put(Range.closedOpen(3.0, 5.0), 0L)
              .put(Range.atLeast(5.0), 0L)
              .build());
}
项目:java-monitoring-client-library    文件:MutableDistributionTest.java   
@Test
public void testAdd_multipleOfOneValue() {
  distribution.add(4.0, 2);

  assertThat(distribution.count()).isEqualTo(2);
  assertThat(distribution.mean()).isWithin(0.0).of(4.0);
  assertThat(distribution.sumOfSquaredDeviation()).isWithin(0.0).of(0);
  assertThat(distribution.intervalCounts())
      .isEqualTo(
          ImmutableRangeMap.<Double, Long>builder()
              .put(Range.lessThan(3.0), 0L)
              .put(Range.closedOpen(3.0, 5.0), 2L)
              .put(Range.atLeast(5.0), 0L)
              .build());
}
项目:java-monitoring-client-library    文件:MutableDistributionTest.java   
@Test
public void testAdd_fitterWithNoFiniteIntervals_underflowValue_returnsUnderflowInterval()
    throws Exception {
  MutableDistribution distribution =
      new MutableDistribution(CustomFitter.create(ImmutableSet.of(5.0)));

  distribution.add(3.0);

  assertThat(distribution.intervalCounts())
      .isEqualTo(
          ImmutableRangeMap.<Double, Long>builder()
              .put(Range.lessThan(5.0), 1L)
              .put(Range.atLeast(5.0), 0L)
              .build());
}
项目:java-monitoring-client-library    文件:MutableDistributionTest.java   
@Test
public void testAdd_noFiniteIntervals_overflowValue_returnsOverflowInterval() throws Exception {
  MutableDistribution distribution =
      new MutableDistribution(CustomFitter.create(ImmutableSet.of(5.0)));

  distribution.add(10.0);

  assertThat(distribution.intervalCounts())
      .isEqualTo(
          ImmutableRangeMap.<Double, Long>builder()
              .put(Range.lessThan(5.0), 0L)
              .put(Range.atLeast(5.0), 1L)
              .build());
}
项目:java-monitoring-client-library    文件:MutableDistributionTest.java   
@Test
public void testAdd_noFiniteIntervals_edgeValue_returnsOverflowInterval() throws Exception {
  MutableDistribution distribution =
      new MutableDistribution(CustomFitter.create(ImmutableSet.of(2.0)));

  distribution.add(2.0);

  assertThat(distribution.intervalCounts())
      .isEqualTo(
          ImmutableRangeMap.<Double, Long>builder()
              .put(Range.lessThan(2.0), 0L)
              .put(Range.atLeast(2.0), 1L)
              .build());
}
项目:java-monitoring-client-library    文件:MutableDistributionTest.java   
@Test
public void testAdd_oneFiniteInterval_underflowValue_returnsUnderflowInterval() throws Exception {
  MutableDistribution distribution =
      new MutableDistribution(CustomFitter.create(ImmutableSet.of(1.0, 5.0)));

  distribution.add(0.0);

  assertThat(distribution.intervalCounts())
      .isEqualTo(
          ImmutableRangeMap.<Double, Long>builder()
              .put(Range.lessThan(1.0), 1L)
              .put(Range.closedOpen(1.0, 5.0), 0L)
              .put(Range.atLeast(5.0), 0L)
              .build());
}
项目:java-monitoring-client-library    文件:MutableDistributionTest.java   
@Test
public void testAdd_oneFiniteInterval_overflowValue_returnsOverflowInterval() throws Exception {
  MutableDistribution distribution =
      new MutableDistribution(CustomFitter.create(ImmutableSet.of(1.0, 5.0)));

  distribution.add(10.0);

  assertThat(distribution.intervalCounts())
      .isEqualTo(
          ImmutableRangeMap.<Double, Long>builder()
              .put(Range.lessThan(1.0), 0L)
              .put(Range.closedOpen(1.0, 5.0), 0L)
              .put(Range.atLeast(5.0), 1L)
              .build());
}
项目:java-monitoring-client-library    文件:MutableDistributionTest.java   
@Test
public void testAdd_oneFiniteInterval_inBoundsValue_returnsInBoundsInterval() throws Exception {
  MutableDistribution distribution =
      new MutableDistribution(CustomFitter.create(ImmutableSet.of(1.0, 5.0)));

  distribution.add(3.0);

  assertThat(distribution.intervalCounts())
      .isEqualTo(
          ImmutableRangeMap.<Double, Long>builder()
              .put(Range.lessThan(1.0), 0L)
              .put(Range.closedOpen(1.0, 5.0), 1L)
              .put(Range.atLeast(5.0), 0L)
              .build());
}
项目:java-monitoring-client-library    文件:MutableDistributionTest.java   
@Test
public void testAdd_oneFiniteInterval_firstEdgeValue_returnsFiniteInterval() throws Exception {
  MutableDistribution distribution =
      new MutableDistribution(CustomFitter.create(ImmutableSet.of(1.0, 5.0)));

  distribution.add(1.0);

  assertThat(distribution.intervalCounts())
      .isEqualTo(
          ImmutableRangeMap.<Double, Long>builder()
              .put(Range.lessThan(1.0), 0L)
              .put(Range.closedOpen(1.0, 5.0), 1L)
              .put(Range.atLeast(5.0), 0L)
              .build());
}
项目:java-monitoring-client-library    文件:MutableDistributionTest.java   
@Test
public void testAdd_oneFiniteInterval_secondEdgeValue_returnsOverflowInterval() throws Exception {
  MutableDistribution distribution =
      new MutableDistribution(CustomFitter.create(ImmutableSet.of(1.0, 5.0)));

  distribution.add(5.0);

  assertThat(distribution.intervalCounts())
      .isEqualTo(
          ImmutableRangeMap.<Double, Long>builder()
              .put(Range.lessThan(1.0), 0L)
              .put(Range.closedOpen(1.0, 5.0), 0L)
              .put(Range.atLeast(5.0), 1L)
              .build());
}
项目:ProjectAres    文件:Renewable.java   
MaterialData chooseShuffledMaterial() {
    ImmutableRangeMap.Builder<Double, MaterialData> weightsBuilder = ImmutableRangeMap.builder();
    double sum = 0d;
    for(MaterialData material : shuffleableMaterialDeficit.materials()) {
        double weight = shuffleableMaterialDeficit.get(material);
        if(weight > 0) {
            weightsBuilder.put(Range.closedOpen(sum, sum + weight), material);
            sum += weight;
        }
    }
    RangeMap<Double, MaterialData> weights = weightsBuilder.build();
    return weights.get(match.getRandom().nextDouble() * sum);
}
项目:QDrill    文件:BlockMapBuilder.java   
@Override
protected List<CompleteFileWork> runInner() throws Exception {
  final List<CompleteFileWork> work = Lists.newArrayList();
  boolean error = false;
  if (blockify && !compressed(status)) {
    try {
      ImmutableRangeMap<Long, BlockLocation> rangeMap = getBlockMap(status);
      for (Entry<Range<Long>, BlockLocation> l : rangeMap.asMapOfRanges().entrySet()) {
        work.add(new CompleteFileWork(getEndpointByteMap(new FileStatusWork(status)), l.getValue().getOffset(), l.getValue().getLength(), status.getPath().toString()));
      }
    } catch (IOException e) {
      logger.warn("failure while generating file work.", e);
      error = true;
    }
  }


  if (!blockify || error || compressed(status)) {
    work.add(new CompleteFileWork(getEndpointByteMap(new FileStatusWork(status)), 0, status.getLen(), status.getPath().toString()));
  }

  // This if-condition is specific for empty CSV file
  // For CSV files, the global variable blockify is set as true
  // And if this CSV file is empty, rangeMap would be empty also
  // Therefore, at the point before this if-condition, work would not be populated
  if(work.isEmpty()) {
    work.add(new CompleteFileWork(getEndpointByteMap(new FileStatusWork(status)), 0, 0, status.getPath().toString()));
  }

  return work;
}
项目:QDrill    文件:BlockMapBuilder.java   
private ImmutableRangeMap<Long,BlockLocation> getBlockMap(Path path) throws IOException{
  ImmutableRangeMap<Long,BlockLocation> blockMap  = blockMapMap.get(path);
  if(blockMap == null) {
    blockMap = buildBlockMap(path);
  }
  return blockMap;
}
项目:QDrill    文件:BlockMapBuilder.java   
private ImmutableRangeMap<Long,BlockLocation> getBlockMap(FileStatus status) throws IOException{
  ImmutableRangeMap<Long,BlockLocation> blockMap  = blockMapMap.get(status.getPath());
  if (blockMap == null) {
    blockMap = buildBlockMap(status);
  }
  return blockMap;
}
项目:QDrill    文件:TestAffinityCalculator.java   
@Test
public void testBuildRangeMap() {
  BlockLocation[] blocks = buildBlockLocations(new String[4], 256*1024*1024);
  long tA = System.nanoTime();
  ImmutableRangeMap.Builder<Long, BlockLocation> blockMapBuilder = new ImmutableRangeMap.Builder<Long,BlockLocation>();
  for (BlockLocation block : blocks) {
    long start = block.getOffset();
    long end = start + block.getLength();
    Range<Long> range = Range.closedOpen(start, end);
    blockMapBuilder = blockMapBuilder.put(range, block);
  }
  ImmutableRangeMap<Long,BlockLocation> map = blockMapBuilder.build();
  long tB = System.nanoTime();
  System.out.println(String.format("Took %f ms to build range map", (float)(tB - tA) / 1e6));
}
项目:dremio-oss    文件:BlockMapBuilder.java   
@Override
protected List<CompleteFileWork> runInner() throws Exception {
  final List<CompleteFileWork> work = Lists.newArrayList();
  boolean error = false;
  if (blockify && !compressed(status)) {
    try {
      ImmutableRangeMap<Long, BlockLocation> rangeMap = getBlockMap(status);
      for (Entry<Range<Long>, BlockLocation> l : rangeMap.asMapOfRanges().entrySet()) {
        work.add(new CompleteFileWork(getEndpointByteMap(new FileStatusWork(status, l.getValue().getOffset(), l.getValue().getLength())),
                l.getValue().getOffset(), l.getValue().getLength(), status));
      }
    } catch (IOException e) {
      logger.warn("failure while generating file work.", e);
      error = true;
    }
  }


  if (!blockify || error || compressed(status)) {
    work.add(new CompleteFileWork(getEndpointByteMap(new FileStatusWork(status)), 0, status.getLen(), status));
  }

  // This if-condition is specific for empty CSV file
  // For CSV files, the global variable blockify is set as true
  // And if this CSV file is empty, rangeMap would be empty also
  // Therefore, at the point before this if-condition, work would not be populated
  if(work.isEmpty()) {
    work.add(new CompleteFileWork(getEndpointByteMap(new FileStatusWork(status)), 0, 0, status));
  }

  return work;
}
项目:dremio-oss    文件:BlockMapBuilder.java   
private ImmutableRangeMap<Long,BlockLocation> getBlockMap(FileStatus status) throws IOException{
  ImmutableRangeMap<Long,BlockLocation> blockMap  = blockMapMap.get(status.getPath());
  if (blockMap == null) {
    blockMap = buildBlockMap(status);
  }
  return blockMap;
}
项目:dremio-oss    文件:TestAffinityCalculator.java   
@Test
public void testBuildRangeMap() {
  BlockLocation[] blocks = buildBlockLocations(new String[4], 256*1024*1024);
  long tA = System.nanoTime();
  ImmutableRangeMap.Builder<Long, BlockLocation> blockMapBuilder = new ImmutableRangeMap.Builder<>();
  for (BlockLocation block : blocks) {
    long start = block.getOffset();
    long end = start + block.getLength();
    Range<Long> range = Range.closedOpen(start, end);
    blockMapBuilder = blockMapBuilder.put(range, block);
  }
  ImmutableRangeMap<Long,BlockLocation> map = blockMapBuilder.build();
  long tB = System.nanoTime();
  System.out.println(String.format("Took %f ms to build range map", (tB - tA) / 1e6));
}
项目:turbine    文件:LineMap.java   
public static LineMap create(String source) {
  int last = 0;
  int line = 1;
  ImmutableRangeMap.Builder<Integer, Integer> builder = ImmutableRangeMap.builder();
  for (int idx = 0; idx < source.length(); idx++) {
    char ch = source.charAt(idx);
    switch (ch) {
        // handle CR line endings
      case '\r':
        // ...and CRLF
        if (idx + 1 < source.length() && source.charAt(idx + 1) == '\n') {
          idx++;
        }
        // falls through
      case '\n':
        builder.put(Range.closedOpen(last, idx + 1), line++);
        last = idx + 1;
        break;
      default:
        break;
    }
  }
  // no trailing newline
  if (last < source.length()) {
    builder.put(Range.closedOpen(last, source.length()), line++);
  }
  return new LineMap(source, builder.build());
}
项目:drill    文件:BlockMapBuilder.java   
private ImmutableRangeMap<Long,BlockLocation> getBlockMap(Path path) throws IOException{
  ImmutableRangeMap<Long,BlockLocation> blockMap  = blockMapMap.get(path);
  if(blockMap == null) {
    blockMap = buildBlockMap(path);
  }
  return blockMap;
}
项目:drill    文件:BlockMapBuilder.java   
private ImmutableRangeMap<Long,BlockLocation> getBlockMap(FileStatus status) throws IOException{
  ImmutableRangeMap<Long,BlockLocation> blockMap  = blockMapMap.get(status.getPath());
  if (blockMap == null) {
    blockMap = buildBlockMap(status);
  }
  return blockMap;
}
项目:drill    文件:TestAffinityCalculator.java   
@Test
public void testBuildRangeMap() {
  BlockLocation[] blocks = buildBlockLocations(new String[4], 256*1024*1024);
  long tA = System.nanoTime();
  ImmutableRangeMap.Builder<Long, BlockLocation> blockMapBuilder = new ImmutableRangeMap.Builder<Long,BlockLocation>();
  for (BlockLocation block : blocks) {
    long start = block.getOffset();
    long end = start + block.getLength();
    Range<Long> range = Range.closedOpen(start, end);
    blockMapBuilder = blockMapBuilder.put(range, block);
  }
  ImmutableRangeMap<Long,BlockLocation> map = blockMapBuilder.build();
  long tB = System.nanoTime();
  System.out.println(String.format("Took %f ms to build range map", (tB - tA) / 1e6));
}
项目:pdptw-dataset-generator    文件:DatasetGenerator.java   
Builder() {
  randomSeed = 0L;
  scaleLevels = ImmutableSet.of(DEFAULT_SCL);
  dynamismLevels = ImmutableSetMultimap.of(
    TimeSeriesType.POISSON_HOMOGENOUS, createDynRange(DEFAULT_DYN));
  dynamismRangeMap =
    ImmutableRangeMap.of(createDynRange(DEFAULT_DYN), DEFAULT_DYN);
  urgencyLevels = ImmutableSet.of(DEFAULT_URG);
  numInstances = DEFAULT_NUM_INSTANCES;
  numThreads = Runtime.getRuntime().availableProcessors();
  datasetDir = Paths.get("/");
  scenarioLengthHours = DEFAULT_SCENARIO_HOURS;
  scenarioLengthMs = DEFAULT_SCENARIO_LENGTH;
}
项目:pdptw-dataset-generator    文件:DatasetGenerator.java   
/**
 * 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;
}
项目:java-monitoring-client-library    文件:MutableDistribution.java   
@Override
public ImmutableRangeMap<Double, Long> intervalCounts() {
  return ImmutableRangeMap.copyOf(intervalCounts);
}
项目:java-monitoring-client-library    文件:Distribution.java   
/** Returns a histogram of the distribution's values. */
ImmutableRangeMap<Double, Long> intervalCounts();
项目:java-monitoring-client-library    文件:ImmutableDistribution.java   
@Override
public abstract ImmutableRangeMap<Double, Long> intervalCounts();
项目:java-monitoring-client-library    文件:EventMetricTest.java   
@Test
public void testRecord_updatesDistribution() {
  assertThat(metric.getTimestampedValues()).isEmpty();

  metric.recordMultiple(1.0, 1, Instant.ofEpochMilli(1337), ImmutableList.of("test_value1"));

  assertThat(metric.getTimestampedValues(Instant.ofEpochMilli(1338)))
      .containsExactly(
          MetricPoint.create(
              metric,
              ImmutableList.of("test_value1"),
              Instant.ofEpochMilli(1337),
              Instant.ofEpochMilli(1338),
              ImmutableDistribution.create(
                  1.0,
                  0.0,
                  1L,
                  ImmutableRangeMap.<Double, Long>builder()
                      .put(Range.lessThan(5.0), 1L)
                      .put(Range.atLeast(5.0), 0L)
                      .build(),
                  distributionFitter)));

  metric.record(10.0, "test_value1");

  assertThat(metric.getTimestampedValues(Instant.ofEpochMilli(1338)))
      .containsExactly(
          MetricPoint.create(
              metric,
              ImmutableList.of("test_value1"),
              Instant.ofEpochMilli(1337),
              Instant.ofEpochMilli(1338),
              ImmutableDistribution.create(
                  5.5,
                  40.5,
                  2L,
                  ImmutableRangeMap.<Double, Long>builder()
                      .put(Range.lessThan(5.0), 1L)
                      .put(Range.atLeast(5.0), 1L)
                      .build(),
                  distributionFitter)));
}
项目:java-monitoring-client-library    文件:EventMetricTest.java   
@Test
public void testRecord_multipleValues_updatesDistributions() {
  assertThat(metric.getTimestampedValues()).isEmpty();

  metric.recordMultiple(1.0, 3, Instant.ofEpochMilli(1337), ImmutableList.of("test_value1"));

  assertThat(metric.getTimestampedValues(Instant.ofEpochMilli(1338)))
      .containsExactly(
          MetricPoint.create(
              metric,
              ImmutableList.of("test_value1"),
              Instant.ofEpochMilli(1337),
              Instant.ofEpochMilli(1338),
              ImmutableDistribution.create(
                  1.0,
                  0,
                  3L,
                  ImmutableRangeMap.<Double, Long>builder()
                      .put(Range.lessThan(5.0), 3L)
                      .put(Range.atLeast(5.0), 0L)
                      .build(),
                  distributionFitter)));

  metric.recordMultiple(2.0, 5, Instant.ofEpochMilli(1337), ImmutableList.of("test_value1"));
  metric.recordMultiple(7.0, 10, Instant.ofEpochMilli(1337), ImmutableList.of("test_value2"));

  assertThat(metric.getTimestampedValues(Instant.ofEpochMilli(1338)))
      .containsExactly(
          MetricPoint.create(
              metric,
              ImmutableList.of("test_value1"),
              Instant.ofEpochMilli(1337),
              Instant.ofEpochMilli(1338),
              ImmutableDistribution.create(
                  1.625,
                  1.875,
                  8L,
                  ImmutableRangeMap.<Double, Long>builder()
                      .put(Range.lessThan(5.0), 8L)
                      .put(Range.atLeast(5.0), 0L)
                      .build(),
                  distributionFitter)),
          MetricPoint.create(
              metric,
              ImmutableList.of("test_value2"),
              Instant.ofEpochMilli(1337),
              Instant.ofEpochMilli(1338),
              ImmutableDistribution.create(
                  7.0,
                  0,
                  10L,
                  ImmutableRangeMap.<Double, Long>builder()
                      .put(Range.lessThan(5.0), 0L)
                      .put(Range.atLeast(5.0), 10L)
                      .build(),
                  distributionFitter)));
}
项目:java-monitoring-client-library    文件:EventMetricTest.java   
@Test
public void testResetAll_resetsAllValuesAndStartTimestamps() {
  metric.recordMultiple(3.0, 1, Instant.ofEpochMilli(1336), ImmutableList.of("foo"));
  metric.recordMultiple(5.0, 1, Instant.ofEpochMilli(1337), ImmutableList.of("moo"));

  assertThat(metric.getTimestampedValues(Instant.ofEpochMilli(1338)))
      .containsExactly(
          MetricPoint.create(
              metric,
              ImmutableList.of("foo"),
              Instant.ofEpochMilli(1336),
              Instant.ofEpochMilli(1338),
              ImmutableDistribution.create(
                  3.0,
                  0.0,
                  1L,
                  ImmutableRangeMap.<Double, Long>builder()
                      .put(Range.lessThan(5.0), 1L)
                      .put(Range.atLeast(5.0), 0L)
                      .build(),
                  distributionFitter)),
          MetricPoint.create(
              metric,
              ImmutableList.of("moo"),
              Instant.ofEpochMilli(1337),
              Instant.ofEpochMilli(1338),
              ImmutableDistribution.create(
                  5.0,
                  0,
                  1L,
                  ImmutableRangeMap.<Double, Long>builder()
                      .put(Range.lessThan(5.0), 0L)
                      .put(Range.atLeast(5.0), 1L)
                      .build(),
                  distributionFitter)));

  metric.reset(Instant.ofEpochMilli(1339));

  assertThat(metric.getTimestampedValues(Instant.ofEpochMilli(1340)))
      .containsExactly(
          MetricPoint.create(
              metric,
              ImmutableList.of("foo"),
              Instant.ofEpochMilli(1339),
              Instant.ofEpochMilli(1340),
              ImmutableDistribution.create(
                  0.0,
                  0.0,
                  0L,
                  ImmutableRangeMap.<Double, Long>builder()
                      .put(Range.lessThan(5.0), 0L)
                      .put(Range.atLeast(5.0), 0L)
                      .build(),
                  distributionFitter)),
          MetricPoint.create(
              metric,
              ImmutableList.of("moo"),
              Instant.ofEpochMilli(1339),
              Instant.ofEpochMilli(1340),
              ImmutableDistribution.create(
                  0.0,
                  0,
                  0L,
                  ImmutableRangeMap.<Double, Long>builder()
                      .put(Range.lessThan(5.0), 0L)
                      .put(Range.atLeast(5.0), 0L)
                      .build(),
                  distributionFitter)));
}
项目:java-monitoring-client-library    文件:EventMetricTest.java   
@Test
public void testReset_resetsValueAndStartTimestamp() {
  metric.recordMultiple(3.0, 1, Instant.ofEpochMilli(1336), ImmutableList.of("foo"));
  metric.recordMultiple(5.0, 1, Instant.ofEpochMilli(1337), ImmutableList.of("moo"));

  assertThat(metric.getTimestampedValues(Instant.ofEpochMilli(1338)))
      .containsExactly(
          MetricPoint.create(
              metric,
              ImmutableList.of("foo"),
              Instant.ofEpochMilli(1336),
              Instant.ofEpochMilli(1338),
              ImmutableDistribution.create(
                  3.0,
                  0.0,
                  1L,
                  ImmutableRangeMap.<Double, Long>builder()
                      .put(Range.lessThan(5.0), 1L)
                      .put(Range.atLeast(5.0), 0L)
                      .build(),
                  distributionFitter)),
          MetricPoint.create(
              metric,
              ImmutableList.of("moo"),
              Instant.ofEpochMilli(1337),
              Instant.ofEpochMilli(1338),
              ImmutableDistribution.create(
                  5.0,
                  0,
                  1L,
                  ImmutableRangeMap.<Double, Long>builder()
                      .put(Range.lessThan(5.0), 0L)
                      .put(Range.atLeast(5.0), 1L)
                      .build(),
                  distributionFitter)));

  metric.reset(Instant.ofEpochMilli(1339), ImmutableList.of("foo"));

  assertThat(metric.getTimestampedValues(Instant.ofEpochMilli(1340)))
      .containsExactly(
          MetricPoint.create(
              metric,
              ImmutableList.of("foo"),
              Instant.ofEpochMilli(1339),
              Instant.ofEpochMilli(1340),
              ImmutableDistribution.create(
                  0.0,
                  0.0,
                  0L,
                  ImmutableRangeMap.<Double, Long>builder()
                      .put(Range.lessThan(5.0), 0L)
                      .put(Range.atLeast(5.0), 0L)
                      .build(),
                  distributionFitter)),
          MetricPoint.create(
              metric,
              ImmutableList.of("moo"),
              Instant.ofEpochMilli(1337),
              Instant.ofEpochMilli(1340),
              ImmutableDistribution.create(
                  5.0,
                  0,
                  1L,
                  ImmutableRangeMap.<Double, Long>builder()
                      .put(Range.lessThan(5.0), 0L)
                      .put(Range.atLeast(5.0), 1L)
                      .build(),
                  distributionFitter)));
}