本文整理匯總了Java中com.google.common.collect.Range.intersection方法的典型用法代碼示例。如果您正苦於以下問題:Java Range.intersection方法的具體用法?Java Range.intersection怎麽用?Java Range.intersection使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.common.collect.Range
的用法示例。
在下文中一共展示了Range.intersection方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getEndpointByteMap
import com.google.common.collect.Range; //導入方法依賴的package包/類
/**
* For a given FileWork, calculate how many bytes are available on each on node endpoint
*
* @param work the FileWork to calculate endpoint bytes for
* @throws IOException
*/
public EndpointByteMap getEndpointByteMap(FileWork work) throws IOException {
Stopwatch watch = Stopwatch.createStarted();
ImmutableRangeMap<Long,BlockLocation> blockMap = getBlockMap(work.getStatus());
EndpointByteMapImpl endpointByteMap = new EndpointByteMapImpl();
long start = work.getStart();
long end = start + work.getLength();
Range<Long> rowGroupRange = Range.closedOpen(start, end);
// Find submap of ranges that intersect with the rowGroup
ImmutableRangeMap<Long,BlockLocation> subRangeMap = blockMap.subRangeMap(rowGroupRange);
// Iterate through each block in this submap and get the host for the block location
for (Map.Entry<Range<Long>,BlockLocation> block : subRangeMap.asMapOfRanges().entrySet()) {
String[] hosts;
Range<Long> blockRange = block.getKey();
try {
hosts = block.getValue().getHosts();
} catch (IOException ioe) {
throw new RuntimeException("Failed to get hosts for block location", ioe);
}
Range<Long> intersection = rowGroupRange.intersection(blockRange);
long bytes = intersection.upperEndpoint() - intersection.lowerEndpoint();
// For each host in the current block location, add the intersecting bytes to the corresponding endpoint
for (String host : hosts) {
NodeEndpoint endpoint = getNodeEndpoint(host);
if (endpoint != null) {
endpointByteMap.add(endpoint, bytes);
} else {
logger.debug("Failure finding SabotNode running on host {}. Skipping affinity to that host.", host);
}
}
}
logger.debug("FileWork group ({},{}) max bytes {}", work.getStatus().getPath(), work.getStart(), endpointByteMap.getMaxBytes());
logger.debug("Took {} ms to set endpoint bytes", watch.stop().elapsed(TimeUnit.MILLISECONDS));
return endpointByteMap;
}