本文整理汇总了Java中com.google.common.collect.ImmutableRangeMap.Builder方法的典型用法代码示例。如果您正苦于以下问题:Java ImmutableRangeMap.Builder方法的具体用法?Java ImmutableRangeMap.Builder怎么用?Java ImmutableRangeMap.Builder使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.collect.ImmutableRangeMap
的用法示例。
在下文中一共展示了ImmutableRangeMap.Builder方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildBlockMap
import com.google.common.collect.ImmutableRangeMap; //导入方法依赖的package包/类
/**
* 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;
}
示例2: getRangeMap
import com.google.common.collect.ImmutableRangeMap; //导入方法依赖的package包/类
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();
}
示例3: buildBlockMap
import com.google.common.collect.ImmutableRangeMap; //导入方法依赖的package包/类
/**
* 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;
}
示例4: create
import com.google.common.collect.ImmutableRangeMap; //导入方法依赖的package包/类
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());
}
示例5: chooseShuffledMaterial
import com.google.common.collect.ImmutableRangeMap; //导入方法依赖的package包/类
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);
}
示例6: testBuildRangeMap
import com.google.common.collect.ImmutableRangeMap; //导入方法依赖的package包/类
@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));
}
示例7: testBuildRangeMap
import com.google.common.collect.ImmutableRangeMap; //导入方法依赖的package包/类
@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));
}
示例8: create
import com.google.common.collect.ImmutableRangeMap; //导入方法依赖的package包/类
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());
}
示例9: testBuildRangeMap
import com.google.common.collect.ImmutableRangeMap; //导入方法依赖的package包/类
@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));
}