本文整理汇总了Java中com.google.common.collect.Range类的典型用法代码示例。如果您正苦于以下问题:Java Range类的具体用法?Java Range怎么用?Java Range使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Range类属于com.google.common.collect包,在下文中一共展示了Range类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: saveTo
import com.google.common.collect.Range; //导入依赖的package包/类
public void saveTo(ByteSink sink) throws IOException {
final PrintWriter out = new PrintWriter(sink.asCharSink(Charsets.UTF_8).openBufferedStream());
out.println(docIdToBannedRegions.size());
for (final Map.Entry<Symbol, ImmutableRangeSet<Integer>> entry : docIdToBannedRegions
.entrySet()) {
out.println(entry.getKey());
final List<String> parts = Lists.newArrayList();
for (final Range<Integer> r : entry.getValue().asRanges()) {
// we know by construction these ranges are bounded above and below
parts.add(String.format("%d-%d", r.lowerEndpoint(), r.upperEndpoint()));
}
out.println(StringUtils.SpaceJoiner.join(parts));
}
out.close();
}
示例2: testAllocationOrderDoesNotOverFillWithMultipleSizesAndWeights
import com.google.common.collect.Range; //导入依赖的package包/类
@Test
public void testAllocationOrderDoesNotOverFillWithMultipleSizesAndWeights() {
PreFillQueue allocationOrder = bitmapPreFiller.generateAllocationOrder(new PreFillType[] {
new PreFillType.Builder(DEFAULT_BITMAP_WIDTH, DEFAULT_BITMAP_HEIGHT)
.setConfig(defaultBitmapConfig).setWeight(4).build(),
new PreFillType.Builder(DEFAULT_BITMAP_WIDTH / 2, DEFAULT_BITMAP_HEIGHT)
.setConfig(defaultBitmapConfig).build(),
new PreFillType.Builder(DEFAULT_BITMAP_WIDTH, DEFAULT_BITMAP_HEIGHT / 3)
.setConfig(defaultBitmapConfig).setWeight(3).build() });
int byteSize = 0;
while (!allocationOrder.isEmpty()) {
PreFillType current = allocationOrder.remove();
byteSize +=
Util.getBitmapByteSize(current.getWidth(), current.getHeight(), current.getConfig());
}
assertThat(byteSize).isIn(Range.atMost(poolSize + cacheSize));
}
示例3: testAllocationOrderDoesNotOverFillWithMultipleSizes
import com.google.common.collect.Range; //导入依赖的package包/类
@Test
public void testAllocationOrderDoesNotOverFillWithMultipleSizes() {
PreFillQueue allocationOrder = bitmapPreFiller.generateAllocationOrder(
new PreFillType.Builder(DEFAULT_BITMAP_WIDTH, DEFAULT_BITMAP_HEIGHT)
.setConfig(defaultBitmapConfig).build(),
new PreFillType.Builder(DEFAULT_BITMAP_WIDTH / 2, DEFAULT_BITMAP_HEIGHT)
.setConfig(defaultBitmapConfig).build(),
new PreFillType.Builder(DEFAULT_BITMAP_WIDTH, DEFAULT_BITMAP_HEIGHT / 2)
.setConfig(defaultBitmapConfig).build());
long byteSize = 0;
while (!allocationOrder.isEmpty()) {
PreFillType current = allocationOrder.remove();
byteSize +=
Util.getBitmapByteSize(current.getWidth(), current.getHeight(), current.getConfig());
}
assertThat(byteSize).isIn(Range.atMost(poolSize + cacheSize));
}
示例4: getSplitsRange
import com.google.common.collect.Range; //导入依赖的package包/类
public static FindByRange<DatasetSplitId> getSplitsRange(DatasetConfig datasetConfig) {
final String datasetId = datasetConfig.getId().getId();
Range<String> range = getSplitStringRange(datasetConfig);
final DatasetSplitId start = new DatasetSplitId(datasetId, range.lowerEndpoint());
final DatasetSplitId end = new DatasetSplitId(datasetId, range.upperEndpoint());
return new FindByRange<DatasetSplitId>()
.setStart(start, true)
.setEnd(end, false);
}
示例5: add
import com.google.common.collect.Range; //导入依赖的package包/类
public void add(double value, long numSamples) {
checkArgument(numSamples >= 0, "numSamples must be non-negative");
checkDouble(value);
// having numSamples = 0 works as expected (does nothing) even if we let it continue, but we
// can short-circuit it by returning early.
if (numSamples == 0) {
return;
}
Map.Entry<Range<Double>, Long> entry = intervalCounts.getEntry(value);
intervalCounts.put(entry.getKey(), entry.getValue() + numSamples);
this.count += numSamples;
// Update mean and sumOfSquaredDeviation using Welford's method
// See Knuth, "The Art of Computer Programming", Vol. 2, page 232, 3rd edition
double delta = value - mean;
mean += delta * numSamples / count;
sumOfSquaredDeviation += delta * (value - mean) * numSamples;
}
示例6: testAdd_positiveThenNegativeValue
import com.google.common.collect.Range; //导入依赖的package包/类
@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());
}
示例7: buildBlockMap
import com.google.common.collect.Range; //导入依赖的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;
}
示例8: intRange
import com.google.common.collect.Range; //导入依赖的package包/类
@Test
public void intRange() throws Exception {
Entropy e = new MutableEntropy(SEED);
Range<Integer> range = Range.closedOpen(-5, 5);
Multiset<Integer> distribution = HashMultiset.create();
// Choose 1k values and check that they are in the range
for(int i = 0; i < 10000; i++) {
final int value = e.randomInt(range);
assertContains(range, value);
distribution.add(value);
e.advance();
}
// Assert that each of the 10 values was chosen ~1000 times
Ranges.forEach(range, value -> {
assertEquals(1000D, distribution.count(value), 50D);
});
}
示例9: QuoteFilter
import com.google.common.collect.Range; //导入依赖的package包/类
private QuoteFilter(Map<Symbol, ImmutableRangeSet<Integer>> docIdToBannedRegions) {
this.docIdToBannedRegions = ImmutableMap.copyOf(docIdToBannedRegions);
for (RangeSet<Integer> rs : docIdToBannedRegions.values()) {
for (final Range<Integer> r : rs.asRanges()) {
checkArgument(r.hasLowerBound());
checkArgument(r.hasUpperBound());
checkArgument(r.lowerEndpoint() >= 0);
}
}
// these ensure we can serialize safely
for (Symbol sym : docIdToBannedRegions.keySet()) {
final String s = sym.toString();
checkArgument(!s.isEmpty(), "Document IDs may not be empty");
checkArgument(!CharMatcher.WHITESPACE.matchesAnyOf(s),
"Document IDs may not contain whitespace: %s", s);
}
}
示例10: testQuotedRegionComputation
import com.google.common.collect.Range; //导入依赖的package包/类
@Test
public void testQuotedRegionComputation() throws IOException {
final Map<String, ImmutableRangeSet<Integer>> testCases = ImmutableMap.of(
"Foo <quote>bar <quote>baz</quote> <quote>meep</quote></quote> blah <quote>another</quote>",
ImmutableRangeSet.<Integer>builder().add(Range.closed(4, 60)).add(Range.closed(67, 88))
.build(),
"<quote>lalala</quote>", ImmutableRangeSet.of(Range.closed(0, 20)),
"No quotes!", ImmutableRangeSet.<Integer>of());
for (final Map.Entry<String, ImmutableRangeSet<Integer>> entry : testCases.entrySet()) {
final Symbol docid = Symbol.from("dummy");
final QuoteFilter reference =
QuoteFilter.createFromBannedRegions(ImmutableMap.of(docid, entry.getValue()));
final QuoteFilter computed = QuoteFilter.createFromOriginalText(ImmutableMap.of(docid,
CharSource.wrap(entry.getKey())));
assertEquals(reference, computed);
}
}
示例11: testTableWithTransitiveInds
import com.google.common.collect.Range; //导入依赖的package包/类
@Test
public void testTableWithTransitiveInds(DataAccessObject dataAccessObject) throws AlgorithmExecutionException {
// GIVEN
Attribute attributeA = new Attribute(new ColumnIdentifier(TABLE_NAME, "a"), Range.closed(1, 3), INTEGER);
Attribute attributeB = new Attribute(new ColumnIdentifier(TABLE_NAME, "b"), Range.closed(3, 4), INTEGER);
Attribute attributeC = new Attribute(new ColumnIdentifier(TABLE_NAME, "c"), Range.closed(1, 3), INTEGER);
Attribute attributeD = new Attribute(new ColumnIdentifier(TABLE_NAME, "d"), Range.closed(1, 4), INTEGER);
ImmutableList<Attribute> attributes = ImmutableList.of(attributeA, attributeB, attributeC, attributeD);
TableInfo tableInfo = new TableInfo(TABLE_NAME, attributes);
InclusionDependency indAC = toInd(attributeA.getColumnIdentifier(), attributeC.getColumnIdentifier());
InclusionDependency indAD = toInd(attributeA.getColumnIdentifier(), attributeD.getColumnIdentifier());
InclusionDependency indCA = toInd(attributeC.getColumnIdentifier(), attributeA.getColumnIdentifier());
InclusionDependency indCD = toInd(attributeC.getColumnIdentifier(), attributeD.getColumnIdentifier());
InclusionDependency indBD = toInd(attributeB.getColumnIdentifier(), attributeD.getColumnIdentifier());
ImmutableSet<InclusionDependency> validInds = ImmutableSet.of(indAC, indAD, indCA, indCD, indBD);
when(dataAccessObject.isValidUIND(any(InclusionDependency.class)))
.thenAnswer(invocation -> validInds.contains(invocation.<InclusionDependency>getArgument(0)));
// WHEN
when(dataAccessObject.getTableInfo(TABLE_NAME)).thenReturn(tableInfo);
bellBrockhausen.execute();
// THEN
assertThat(resultReceiver.getReceivedResults()).containsExactlyInAnyOrder(toArray(validInds));
}
开发者ID:HPI-Information-Systems,项目名称:AdvancedDataProfilingSeminar,代码行数:27,代码来源:BellBrockhausenTest.java
示例12: refillRetentions
import com.google.common.collect.Range; //导入依赖的package包/类
private void refillRetentions() {
result.ranges.clear();
int counter = 0;
final int valuesMaxIndex = ageRetentionMap.values().size() - 1;
final List<Map.Entry<Integer, Integer>> entryList = ageRetentionMap.entrySet()
.stream()
.sorted(Map.Entry.comparingByKey())
.collect(Collectors.toList());
for (Map.Entry<Integer, Integer> retention : entryList) {
final Integer age = retention.getKey();
final Integer precision = retention.getValue();
final boolean isLast = (counter == valuesMaxIndex);
if (!isLast) {
final Integer nextAge = entryList.get(counter + 1).getKey();
result.ranges.put(Range.closedOpen(age, nextAge), precision);
} else {
result.ranges.put(Range.atLeast(age), precision);
}
counter++;
}
}
示例13: matches
import com.google.common.collect.Range; //导入依赖的package包/类
public boolean matches(DrillFileSystem fs, FileStatus status) throws IOException{
if (ranges.isEmpty()) {
return false;
}
final Range<Long> fileRange = Range.closedOpen( 0L, status.getLen());
try (FSDataInputStream is = fs.open(status.getPath())) {
for(RangeMagics rMagic : ranges) {
Range<Long> r = rMagic.range;
if (!fileRange.encloses(r)) {
continue;
}
int len = (int) (r.upperEndpoint() - r.lowerEndpoint());
byte[] bytes = new byte[len];
is.readFully(r.lowerEndpoint(), bytes);
for (byte[] magic : rMagic.magics) {
if (Arrays.equals(magic, bytes)) {
return true;
}
}
}
}
return false;
}
示例14: parseChildList
import com.google.common.collect.Range; //导入依赖的package包/类
public List<T> parseChildList(Element parent, Range<Integer> count) throws InvalidXMLException {
final List<T> list = parseChildren(parent).collect(Collectors.toList());
if(count.contains(list.size())) return list;
final Optional<Integer> min = Ranges.minimum(count), max = Ranges.maximum(count);
if(!max.isPresent()) {
throw new InvalidXMLException("Expected " + min.get() + " or more child elements", parent);
} else if(!min.isPresent()) {
throw new InvalidXMLException("Expected no more than " + max.get() + " child elements", parent);
} else if(min.equals(max)) {
throw new InvalidXMLException("Expected exactly " + min.get() + " child elements", parent);
} else {
throw new InvalidXMLException("Expected between " + min.get() + " and " + max.get() + " child elements", parent);
}
}
示例15: testNewProxy_goodMethodWithNotEnoughTime
import com.google.common.collect.Range; //导入依赖的package包/类
public void testNewProxy_goodMethodWithNotEnoughTime() throws Exception {
SampleImpl target = new SampleImpl(9999);
Sample proxy = service.newProxy(target, Sample.class, NOT_ENOUGH_MS, MILLISECONDS);
Stopwatch stopwatch = Stopwatch.createStarted();
try {
proxy.sleepThenReturnInput("x");
fail("no exception thrown");
} catch (UncheckedTimeoutException expected) {
}
assertThat(stopwatch.elapsed(MILLISECONDS)).isIn(Range.closed(NOT_ENOUGH_MS, DELAY_MS * 2));
// Is it still computing away anyway?
assertThat(target.finished).isFalse();
MILLISECONDS.sleep(ENOUGH_MS);
assertThat(target.finished).isFalse();
}