本文整理匯總了Java中com.google.common.collect.Range.upperEndpoint方法的典型用法代碼示例。如果您正苦於以下問題:Java Range.upperEndpoint方法的具體用法?Java Range.upperEndpoint怎麽用?Java Range.upperEndpoint使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.common.collect.Range
的用法示例。
在下文中一共展示了Range.upperEndpoint方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: makeKToIJ
import com.google.common.collect.Range; //導入方法依賴的package包/類
/**
* Given an {@code InputOutput}, compute the map from tok indices to line ranges.
*
* @param put the {@code InputOutput}
* @param kN the number of tokens
* @return the map from {@link com.google.googlejavaformat.java.JavaInput.Tok} indices to line
* ranges in this {@code put}
*/
public static Map<Integer, Range<Integer>> makeKToIJ(InputOutput put, int kN) {
Map<Integer, Range<Integer>> map = new HashMap<>();
int ijN = put.getLineCount();
for (int ij = 0; ij <= ijN; ij++) {
Range<Integer> range = put.getRanges(ij).canonical(INTEGERS);
for (int k = range.lowerEndpoint(); k < range.upperEndpoint(); k++) {
if (map.containsKey(k)) {
map.put(k, Range.closedOpen(map.get(k).lowerEndpoint(), ij + 1));
} else {
map.put(k, Range.closedOpen(ij, ij + 1));
}
}
}
return map;
}
示例2: 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;
}
示例3: mergeRanges
import com.google.common.collect.Range; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public static List<KeyRange> mergeRanges(List<KeyRange> ranges) {
if (ranges == null || ranges.isEmpty() || ranges.size() == 1) {
return ranges;
}
Range merged = ranges
.stream()
.map(KeyRangeUtils::toRange)
.reduce(Range::span).get();
List<KeyRange> keyRanges = new ArrayList<>();
try {
Comparables.ComparableByteString lower =
(Comparables.ComparableByteString) merged.lowerEndpoint();
Comparables.ComparableByteString upper =
(Comparables.ComparableByteString) merged.upperEndpoint();
keyRanges.add(makeCoprocRange(lower.getByteString(), upper.getByteString()));
} catch (Exception ignored) {}
return keyRanges;
}
示例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: encodeTimeInterval
import com.google.common.collect.Range; //導入方法依賴的package包/類
private static TimeInterval encodeTimeInterval(Range<Instant> nativeInterval, Kind metricKind) {
TimeInterval encodedInterval =
new TimeInterval().setStartTime(nativeInterval.lowerEndpoint().toString());
Instant endTimestamp =
nativeInterval.isEmpty() && metricKind != Kind.GAUGE
? nativeInterval.upperEndpoint().plusMillis(1)
: nativeInterval.upperEndpoint();
return encodedInterval.setEndTime(endTimestamp.toString());
}
示例6: createWordLists
import com.google.common.collect.Range; //導入方法依賴的package包/類
private List<List<String>> createWordLists(List<String> words, Range<Integer> range) {
List<List<String>> wordsPermutated = Lists.newArrayList();
for (int i = range.lowerEndpoint(); i <= range.upperEndpoint(); i++) {
if (i > 0) {
LinkedList<String> currPermutationHead = createWordsPermutation(words, i, Ending.HEAD);
wordsPermutated.add(currPermutationHead);
LinkedList<String> currPermutationTail = createWordsPermutation(words, i, Ending.TAIL);
wordsPermutated.add(currPermutationTail);
}
LinkedList<String> currPermutationBoth = createWordsPermutation(words, i, Ending.BOTH);
wordsPermutated.add(currPermutationBoth);
}
return wordsPermutated;
}
示例7: format
import com.google.common.collect.Range; //導入方法依賴的package包/類
Collection<BaseComponent> format() {
final ImmutableList.Builder<BaseComponent> lines = ImmutableList.builder();
lines.add(new TranslatableComponent(
"matchQuota.matchCounts",
new Component(String.valueOf(matchesPlayed), ChatColor.AQUA),
new Component(String.valueOf(quota.maximum()), ChatColor.AQUA)
));
if(matchesRemaining() == 0) {
lines.add(new TranslatableComponent(
"matchQuota.nextMatch",
new Component(PeriodFormats.briefNaturalApproximate(now, earliestJoinTime), ChatColor.AQUA)
));
}
if(!quota.premium()) {
Range<Integer> premiumRange = getConfig().getPremiumMaximum();
if(premiumRange != null) {
if(premiumRange.upperEndpoint() == Integer.MAX_VALUE) {
lines.add(Links.shopPlug("shop.plug.rankedMatches.unlimited"));
} else {
BaseComponent premiumLimit = new Component(String.valueOf(premiumRange.upperEndpoint()), ChatColor.AQUA);
if(premiumRange.upperEndpoint().equals(premiumRange.lowerEndpoint())) {
lines.add(Links.shopPlug("shop.plug.rankedMatches.uniform", premiumLimit));
} else {
lines.add(Links.shopPlug("shop.plug.rankedMatches.upto", premiumLimit));
}
}
}
}
return lines.build();
}
示例8: parseRandom
import com.google.common.collect.Range; //導入方法依賴的package包/類
@MethodParser("random")
public Filter parseRandom(Element el) throws InvalidXMLException {
Node node = new Node(el);
Range<Double> chance;
try {
chance = Range.closedOpen(0d, XMLUtils.parseNumber(node, Double.class));
} catch(InvalidXMLException e) {
chance = XMLUtils.parseNumericRange(node, Double.class);
}
Range<Double> valid = Range.closed(0d, 1d);
if (valid.encloses(chance)) {
return proto.isNoOlderThan(ProtoVersions.EVENT_QUERIES) ? new RandomFilter(chance)
: new LegacyRandomFilter(chance);
} else {
double lower = chance.hasLowerBound() ? chance.lowerEndpoint() : Double.NEGATIVE_INFINITY;
double upper = chance.hasUpperBound() ? chance.upperEndpoint() : Double.POSITIVE_INFINITY;
double invalid;
if(!valid.contains(lower)) {
invalid = lower;
} else {
invalid = upper;
}
throw new InvalidXMLException("chance value (" + invalid + ") is not between 0 and 1", el);
}
}
示例9: describe
import com.google.common.collect.Range; //導入方法依賴的package包/類
/**
* Return an english phrase describing the given {@link Range} e.g.
*
* Range.all() -> "unbounded"
* Range.singleton(3) -> "3"
* Range.atLeast(3) -> "at least 3"
* Range.closedOpen(3, 7) -> "at least 3 and less than 7"
* Range.closed(3, 7) -> "between 3 and 7"
*/
public static String describe(Range<?> range) {
if(range.hasLowerBound() && range.hasUpperBound() && range.lowerBoundType() == BoundType.CLOSED && range.upperBoundType() == BoundType.CLOSED) {
if(range.lowerEndpoint().equals(range.upperEndpoint())) {
// singleton
return range.lowerEndpoint().toString();
} else {
// closed-closed
return "between " + range.lowerEndpoint() + " and " + range.upperEndpoint();
}
}
final List<String> parts = new ArrayList<>(2);
if(range.hasLowerBound()) {
parts.add((range.lowerBoundType() == BoundType.CLOSED ? "at least " : "more than ") + range.lowerEndpoint());
}
if(range.hasUpperBound()) {
parts.add((range.upperBoundType() == BoundType.CLOSED ? "at most " : "less than ") + range.upperEndpoint());
}
switch(parts.size()) {
case 0: return "unbounded";
case 1: return parts.get(0);
default: return parts.get(0) + " and " + parts.get(1);
}
}
示例10: expandToBreakableRegions
import com.google.common.collect.Range; //導入方法依賴的package包/類
/**
* Expand a token range to start and end on acceptable boundaries for re-formatting.
*
* @param iRange the {@link Range} of tokens
* @return the expanded token range
*/
private Range<Integer> expandToBreakableRegions(Range<Integer> iRange) {
// The original line range.
int loTok = iRange.lowerEndpoint();
int hiTok = iRange.upperEndpoint() - 1;
// Expand the token indices to formattable boundaries (e.g. edges of statements).
if (!partialFormatRanges.contains(loTok) || !partialFormatRanges.contains(hiTok)) {
return EMPTY_RANGE;
}
loTok = partialFormatRanges.rangeContaining(loTok).lowerEndpoint();
hiTok = partialFormatRanges.rangeContaining(hiTok).upperEndpoint();
return Range.closedOpen(loTok, hiTok + 1);
}
示例11: doBetweenSharding
import com.google.common.collect.Range; //導入方法依賴的package包/類
@Override
public Collection<String> doBetweenSharding(final Collection<String> dataSourceNames, final ShardingValue<Integer> shardingValue) {
Collection<String> result = new LinkedHashSet<>(dataSourceNames.size());
Range<Integer> range = shardingValue.getValueRange();
for (Integer i = range.lowerEndpoint(); i <= range.upperEndpoint(); i++) {
for (String each : dataSourceNames) {
if (each.endsWith(i % 2 + "")) {
result.add(each);
}
}
}
return result;
}
示例12: matches
import com.google.common.collect.Range; //導入方法依賴的package包/類
public boolean matches(FileSystemWrapper fs, FileStatus status) throws IOException{
if (ranges.isEmpty() || status.isDirectory()) {
return false;
}
// walk all the way down in the symlinks until a hard entry is reached
FileStatus current = status;
while (current.isSymlink()) {
current = fs.getFileStatus(status.getSymlink());
}
// if hard entry is not a file nor can it be a symlink then it is not readable simply deny matching.
if (!current.isFile()) {
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;
}
示例13: computeLocality
import com.google.common.collect.Range; //導入方法依賴的package包/類
private void computeLocality(ParquetMetadata footer) throws ExecutionSetupException {
try {
BlockMetaData block = footer.getBlocks().get(readEntry.getRowGroupIndex());
BlockLocation[] blockLocations = fs.getFileBlockLocations(new Path(readEntry.getPath()), block.getStartingPos(), block.getCompressedSize());
String localHost = InetAddress.getLocalHost().getCanonicalHostName();
List<Range<Long>> intersectingRanges = new ArrayList<>();
Range<Long> rowGroupRange = Range.openClosed(block.getStartingPos(), block.getStartingPos() + block.getCompressedSize());
for (BlockLocation loc : blockLocations) {
for (String host : loc.getHosts()) {
if (host.equals(localHost)) {
intersectingRanges.add(Range.closedOpen(loc.getOffset(), loc.getOffset() + loc.getLength()).intersection(rowGroupRange));
}
}
}
long totalIntersect = 0;
for (Range<Long> range : intersectingRanges) {
totalIntersect += (range.upperEndpoint() - range.lowerEndpoint());
}
if (totalIntersect < block.getCompressedSize()) {
context.getStats().addLongStat(Metric.NUM_REMOTE_READERS, 1);
} else {
context.getStats().addLongStat(Metric.NUM_REMOTE_READERS, 0);
}
} catch (IOException e) {
throw new ExecutionSetupException(e);
}
}
示例14: isViewportAboveContainer
import com.google.common.collect.Range; //導入方法依賴的package包/類
private boolean isViewportAboveContainer(Range<Integer> container, Range<Integer> viewport) {
return container.upperEndpoint() < viewport.lowerEndpoint();
}
示例15: needMaximum
import com.google.common.collect.Range; //導入方法依賴的package包/類
public static int needMaximum(Range<Integer> range) {
assertUpperBound(range);
return range.upperBoundType() == BoundType.CLOSED ? range.upperEndpoint()
: range.upperEndpoint() - 1;
}