本文整理了Java中com.google.common.collect.Range.lowerEndpoint
方法的一些代码示例,展示了Range.lowerEndpoint
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Range.lowerEndpoint
方法的具体详情如下:
包路径:com.google.common.collect.Range
类名称:Range
方法名:lowerEndpoint
[英]Returns the lower endpoint of this range.
[中]返回此范围的下限。
代码示例来源:origin: Graylog2/graylog2-server
@Override
public void serialize(Range range, JsonGenerator jgen, SerializerProvider provider) throws IOException {
jgen.writeStartObject();
final Integer lower = (Integer) range.lowerEndpoint();
final Integer upper = (Integer) range.upperEndpoint();
jgen.writeNumberField("start", lower);
jgen.writeNumberField("length", upper - lower);
jgen.writeEndObject();
}
}
代码示例来源:origin: google/error-prone
@Override
public int compare(Range<Integer> o1, Range<Integer> o2) {
return ComparisonChain.start()
.compare(o1.lowerEndpoint(), o2.lowerEndpoint(), Ordering.natural().reverse())
.compare(o1.upperEndpoint(), o2.upperEndpoint(), Ordering.natural().reverse())
.result();
}
};
代码示例来源:origin: spotify/helios
@Override
public AllocatedPort call() throws Exception {
final int port = ThreadLocalRandom.current().nextInt(dockerPortRange.lowerEndpoint(),
dockerPortRange.upperEndpoint());
return temporaryPorts.tryAcquire("docker-probe", port);
}
});
代码示例来源:origin: GoogleContainerTools/jib
private static void checkNumericSystemProperty(String property, Range<Integer> validRange) {
String value = System.getProperty(property);
if (value == null) {
return;
}
int parsed;
try {
parsed = Integer.parseInt(value);
} catch (NumberFormatException ex) {
throw new NumberFormatException(property + " must be an integer: " + value);
}
if (validRange.hasLowerBound() && validRange.lowerEndpoint() > parsed) {
throw new NumberFormatException(
property + " cannot be less than " + validRange.lowerEndpoint() + ": " + value);
} else if (validRange.hasUpperBound() && validRange.upperEndpoint() < parsed) {
throw new NumberFormatException(
property + " cannot be greater than " + validRange.upperEndpoint() + ": " + value);
}
}
代码示例来源:origin: google/google-java-format
public static String applyReplacements(String input, List<Replacement> replacements) {
replacements = new ArrayList<>(replacements);
replacements.sort(comparing((Replacement r) -> r.getReplaceRange().lowerEndpoint()).reversed());
StringBuilder writer = new StringBuilder(input);
for (Replacement replacement : replacements) {
writer.replace(
replacement.getReplaceRange().lowerEndpoint(),
replacement.getReplaceRange().upperEndpoint(),
replacement.getReplacementString());
}
return writer.toString();
}
代码示例来源:origin: google/error-prone
private static SuggestedFix wrapInCodeTag(Range<Integer> containingPre) {
return SuggestedFix.builder()
.replace(containingPre.lowerEndpoint(), containingPre.lowerEndpoint(), "{@code ")
.replace(containingPre.upperEndpoint(), containingPre.upperEndpoint(), "}")
.build();
}
}
代码示例来源:origin: prestodb/presto
@Override
public Range<Long> visitLimit(LimitNode node, Void context)
{
Range<Long> sourceCardinalityRange = node.getSource().accept(this, null);
long upper = node.getCount();
if (sourceCardinalityRange.hasUpperBound()) {
upper = min(sourceCardinalityRange.upperEndpoint(), node.getCount());
}
long lower = min(upper, sourceCardinalityRange.lowerEndpoint());
return Range.closed(lower, upper);
}
}
代码示例来源:origin: google/google-java-format
/** Applies replacements to the given string. */
private static JavaInput applyReplacements(
JavaInput javaInput, TreeRangeMap<Integer, String> replacementMap) throws FormatterException {
// process in descending order so the replacement ranges aren't perturbed if any replacements
// differ in size from the input
Map<Range<Integer>, String> ranges = replacementMap.asDescendingMapOfRanges();
if (ranges.isEmpty()) {
return javaInput;
}
StringBuilder sb = new StringBuilder(javaInput.getText());
for (Entry<Range<Integer>, String> entry : ranges.entrySet()) {
Range<Integer> range = entry.getKey();
sb.replace(range.lowerEndpoint(), range.upperEndpoint(), entry.getValue());
}
return new JavaInput(sb.toString());
}
}
代码示例来源:origin: square/wire
public final String toSchema() {
StringBuilder builder = new StringBuilder();
appendDocumentation(builder, documentation());
builder.append("reserved ");
ImmutableList<Object> value = values();
for (int i = 0; i < value.size(); i++) {
if (i > 0) builder.append(", ");
Object reservation = value.get(i);
if (reservation instanceof String) {
builder.append('"').append(reservation).append('"');
} else if (reservation instanceof Integer) {
builder.append(reservation);
} else if (reservation instanceof Range) {
Range<Integer> range = (Range<Integer>) reservation;
builder.append(range.lowerEndpoint()).append(" to ").append(range.upperEndpoint());
} else {
throw new AssertionError();
}
}
return builder.append(";\n").toString();
}
}
代码示例来源:origin: google/error-prone
private void checkOverlaps(Replacement replacement) {
Range<Integer> replacementRange = replacement.range();
Collection<Replacement> overlap =
overlaps.subRangeMap(replacementRange).asMapOfRanges().values();
checkArgument(
overlap.isEmpty(),
"%s overlaps with existing replacements: %s",
replacement,
Joiner.on(", ").join(overlap));
Set<Integer> containedZeroLengthRangeStarts =
zeroLengthRanges.subSet(
replacementRange.lowerEndpoint(),
/* fromInclusive= */ false,
replacementRange.upperEndpoint(),
/* toInclusive= */ false);
checkArgument(
containedZeroLengthRangeStarts.isEmpty(),
"%s overlaps with existing zero-length replacements: %s",
replacement,
Joiner.on(", ").join(containedZeroLengthRangeStarts));
overlaps.put(replacementRange, replacement);
if (replacementRange.isEmpty()) {
zeroLengthRanges.add(replacementRange.lowerEndpoint());
}
}
代码示例来源:origin: google/google-java-format
public RangeSet<Integer> characterRangesToTokenRanges(Collection<Range<Integer>> characterRanges)
throws FormatterException {
RangeSet<Integer> tokenRangeSet = TreeRangeSet.create();
for (Range<Integer> characterRange0 : characterRanges) {
Range<Integer> characterRange = characterRange0.canonical(DiscreteDomain.integers());
tokenRangeSet.add(
characterRangeToTokenRange(
characterRange.lowerEndpoint(),
characterRange.upperEndpoint() - characterRange.lowerEndpoint()));
}
return tokenRangeSet;
}
}
代码示例来源:origin: google/google-java-format
/**
* Given an {@code InputOutput}, compute the map from tok indices to line ranges.
*
* @param put the {@code InputOutput}
* @return the map from {@code com.google.googlejavaformat.java.JavaInput.Tok} indices to line
* ranges in this {@code put}
*/
public static Map<Integer, Range<Integer>> makeKToIJ(InputOutput put) {
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;
}
代码示例来源:origin: google/google-java-format
private static Range<Integer> offsetRange(Range<Integer> range, int offset) {
range = range.canonical(DiscreteDomain.integers());
return Range.closedOpen(range.lowerEndpoint() + offset, range.upperEndpoint() + offset);
}
代码示例来源:origin: spotify/helios
protected AgentMain startDefaultAgent(final String host, final String... args)
throws Exception {
final String stateDir = agentStateDirs.resolve(host).toString();
final List<String> argsList = Lists.newArrayList(
"-vvvv",
"--no-log-setup",
"--no-http",
"--name", host,
"--docker=" + DOCKER_HOST.host(),
"--zk", zk.connectString(),
"--zk-session-timeout", "100",
"--zk-connection-timeout", "100",
"--zk-enable-acls",
"--zk-acl-master-user", MASTER_USER,
"--zk-acl-master-digest", MASTER_DIGEST,
"--zk-acl-agent-user", AGENT_USER,
"--zk-acl-agent-password", AGENT_PASSWORD,
"--state-dir", stateDir,
"--domain", "",
"--port-range="
+ dockerPortRange.lowerEndpoint() + ":"
+ dockerPortRange.upperEndpoint()
);
argsList.addAll(asList(args));
return startAgent(argsList.toArray(new String[argsList.size()]));
}
代码示例来源:origin: google/google-java-format
/**
* 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);
}
代码示例来源:origin: apache/pulsar
long getNumIndividualDeletedEntriesToSkip(long numEntries) {
long totalEntriesToSkip = 0;
long deletedMessages = 0;
lock.readLock().lock();
try {
PositionImpl startPosition = markDeletePosition;
PositionImpl endPosition = null;
for (Range<PositionImpl> r : individualDeletedMessages.asRanges()) {
endPosition = r.lowerEndpoint();
if (startPosition.compareTo(endPosition) <= 0) {
Range<PositionImpl> range = Range.openClosed(startPosition, endPosition);
long entries = ledger.getNumberOfEntries(range);
if (totalEntriesToSkip + entries >= numEntries) {
break;
}
totalEntriesToSkip += entries;
deletedMessages += ledger.getNumberOfEntries(r);
startPosition = r.upperEndpoint();
} else {
if (log.isDebugEnabled()) {
log.debug("[{}] deletePosition {} moved ahead without clearing deleteMsgs {} for cursor {}",
ledger.getName(), markDeletePosition, r.lowerEndpoint(), name);
}
}
}
} finally {
lock.readLock().unlock();
}
return deletedMessages;
}
代码示例来源:origin: apache/kylin
public static String formatTsRange(Range<Long> tsRange) {
if (tsRange == null)
return null;
StringBuilder sb = new StringBuilder();
if (tsRange.hasLowerBound()) {
if (tsRange.lowerBoundType() == BoundType.CLOSED) {
sb.append("[");
} else {
sb.append("(");
}
sb.append(DateFormat.formatToTimeStr(tsRange.lowerEndpoint()));
} else {
sb.append("(-∞");
}
sb.append("~");
if (tsRange.hasUpperBound()) {
sb.append(DateFormat.formatToTimeStr(tsRange.upperEndpoint()));
if (tsRange.upperBoundType() == BoundType.CLOSED) {
sb.append("]");
} else {
sb.append(")");
}
} else {
sb.append("+∞)");
}
return sb.toString();
}
代码示例来源:origin: google/guava
&& range.hasUpperBound()) {
checkArgument(
map.comparator().compare(range.lowerEndpoint(), range.upperEndpoint()) <= 0,
"map is using a custom comparator which is inconsistent with the natural ordering.");
range.lowerEndpoint(),
range.lowerBoundType() == BoundType.CLOSED,
range.upperEndpoint(),
range.upperBoundType() == BoundType.CLOSED);
} else if (range.hasLowerBound()) {
return map.tailMap(range.lowerEndpoint(), range.lowerBoundType() == BoundType.CLOSED);
} else if (range.hasUpperBound()) {
return map.headMap(range.upperEndpoint(), range.upperBoundType() == BoundType.CLOSED);
代码示例来源:origin: google/guava
&& range.hasUpperBound()) {
checkArgument(
set.comparator().compare(range.lowerEndpoint(), range.upperEndpoint()) <= 0,
"set is using a custom comparator which is inconsistent with the natural ordering.");
range.lowerEndpoint(),
range.lowerBoundType() == BoundType.CLOSED,
range.upperEndpoint(),
range.upperBoundType() == BoundType.CLOSED);
} else if (range.hasLowerBound()) {
return set.tailSet(range.lowerEndpoint(), range.lowerBoundType() == BoundType.CLOSED);
} else if (range.hasUpperBound()) {
return set.headSet(range.upperEndpoint(), range.upperBoundType() == BoundType.CLOSED);
代码示例来源:origin: google/google-java-format
private static TextRange toTextRange(Range<Integer> range) {
checkState(
range.lowerBoundType().equals(BoundType.CLOSED)
&& range.upperBoundType().equals(BoundType.OPEN));
return new TextRange(range.lowerEndpoint(), range.upperEndpoint());
}
}
内容来源于网络,如有侵权,请联系作者删除!