@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());
}
@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,1L)
.put(Range.closedOpen(3.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,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;
}
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> blockMapBuilder = new ImmutableRangeMap.Builder<>();
for (BlockLocation block : blocks) {
long start = block.getoffset();
long end = start + block.getLength();
Range<Long> range = Range.closedOpen(start,blockMap);
context.stop();
return blockMap;
}
项目:drill
文件:BlockMapBuilder.java
/**
* Builds a mapping of block locations to file byte range
*/
private ImmutableRangeMap<Long,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());
}
@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);
}
@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,0L)
.put(Range.closedOpen(3.0,1L)
.build());
}
@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,0L)
.build());
}
@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,2L)
.put(Range.atLeast(5.0),0L)
.build());
}
@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());
}
@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,1L)
.build());
}
@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());
}
@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,0L)
.build());
}
@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,0L)
.put(Range.closedOpen(1.0,1L)
.build());
}
@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,0L)
.build());
}
@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,0L)
.build());
}
@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,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)),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)),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;
}
@Test
public void testbuildrangeMap() {
BlockLocation[] blocks = buildBlockLocations(new String[4],256*1024*1024);
long tA = System.nanoTime();
ImmutableRangeMap.Builder<Long,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> l : rangeMap.asMapOfRanges().entrySet()) {
work.add(new CompleteFileWork(getEndpointByteMap(new FileStatusWork(status,l.getValue().getLength())),status));
}
} catch (IOException e) {
logger.warn("failure while generating file work.",status));
}
// This if-condition is specific for empty CSV file
// For CSV files,status));
}
return work;
}
项目:dremio-oss
文件:BlockMapBuilder.java
private ImmutableRangeMap<Long,BlockLocation> blockMap = blockMapMap.get(status.getPath());
if (blockMap == null) {
blockMap = buildBlockMap(status);
}
return blockMap;
}
@Test
public void testbuildrangeMap() {
BlockLocation[] blocks = buildBlockLocations(new String[4],(tB - tA) / 1e6));
}
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> blockMap = blockMapMap.get(path);
if(blockMap == null) {
blockMap = buildBlockMap(path);
}
return blockMap;
}
项目:drill
文件:BlockMapBuilder.java
private ImmutableRangeMap<Long,BlockLocation> blockMap = blockMapMap.get(status.getPath());
if (blockMap == null) {
blockMap = buildBlockMap(status);
}
return blockMap;
}
@Test
public void testbuildrangeMap() {
BlockLocation[] blocks = buildBlockLocations(new String[4],(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;
}
@Override
public ImmutableRangeMap<Double,Long> intervalCounts() {
return ImmutableRangeMap.copyOf(intervalCounts);
}
/** Returns a histogram of the distribution's values. */
ImmutableRangeMap<Double,Long> intervalCounts();
@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(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,Immutabledistribution.create(
5.5,40.5,2L,1L)
.build(),distributionFitter)));
}
项目:java-monitoring-client-library
文件:EventMetricTest.java
@Test
public void testRecord_multipleValues_updatesdistributions() {
assertthat(metric.getTimestampedValues()).isEmpty();
metric.recordMultiple(1.0,3,3L,3L)
.put(Range.atLeast(5.0),distributionFitter)));
metric.recordMultiple(2.0,5,ImmutableList.of("test_value1"));
metric.recordMultiple(7.0,10,ImmutableList.of("test_value2"));
assertthat(metric.getTimestampedValues(Instant.ofEpochMilli(1338)))
.containsExactly(
MetricPoint.create(
metric,Immutabledistribution.create(
1.625,1.875,8L,8L)
.put(Range.atLeast(5.0),distributionFitter)),MetricPoint.create(
metric,ImmutableList.of("test_value2"),Immutabledistribution.create(
7.0,10L,0L)
.put(Range.atLeast(5.0),10L)
.build(),distributionFitter)));
}
项目:java-monitoring-client-library
文件:EventMetricTest.java
@Test
public void testResetAll_resetsAllValuesAndStartTimestamps() {
metric.recordMultiple(3.0,Instant.ofEpochMilli(1336),ImmutableList.of("foo"));
metric.recordMultiple(5.0,ImmutableList.of("moo"));
assertthat(metric.getTimestampedValues(Instant.ofEpochMilli(1338)))
.containsExactly(
MetricPoint.create(
metric,ImmutableList.of("foo"),Immutabledistribution.create(
3.0,ImmutableList.of("moo"),Immutabledistribution.create(
5.0,distributionFitter)));
metric.reset(Instant.ofEpochMilli(1339));
assertthat(metric.getTimestampedValues(Instant.ofEpochMilli(1340)))
.containsExactly(
MetricPoint.create(
metric,Instant.ofEpochMilli(1339),Instant.ofEpochMilli(1340),Immutabledistribution.create(
0.0,0L,distributionFitter)));
}
项目:java-monitoring-client-library
文件:EventMetricTest.java
@Test
public void testReset_resetsValueAndStartTimestamp() {
metric.recordMultiple(3.0,distributionFitter)));
metric.reset(Instant.ofEpochMilli(1339),ImmutableList.of("foo"));
assertthat(metric.getTimestampedValues(Instant.ofEpochMilli(1340)))
.containsExactly(
MetricPoint.create(
metric,distributionFitter)));
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。