本文整理汇总了Java中com.google.common.collect.Iterables.getLast方法的典型用法代码示例。如果您正苦于以下问题:Java Iterables.getLast方法的具体用法?Java Iterables.getLast怎么用?Java Iterables.getLast使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.collect.Iterables
的用法示例。
在下文中一共展示了Iterables.getLast方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addBodyIfNecessary
import com.google.common.collect.Iterables; //导入方法依赖的package包/类
private void addBodyIfNecessary(
ForStatement.Builder builder,
List<Trees.Expression> params,
Iterable<? extends Trees.TemplatePart> bodyParts) {
// body goes as one special parameter, don't handle other mismatches
if (Iterables.isEmpty(bodyParts)) {
return;
}
Preconditions.checkState(inlinable.declaration().parameters().size() == params.size() + 1);
Trees.Parameter lastParameter = Iterables.getLast(inlinable.declaration().parameters());
LetStatement.Builder letBuilder = LetStatement.builder()
.addAllParts(bodyParts)
.declaration(InvokableDeclaration.builder()
.name(remappedIdentifier(lastParameter.name()))
.build());
remapped.add(lastParameter.name());
builder.addParts(letBuilder.build());
}
示例2: extractOutputTypes
import com.google.common.collect.Iterables; //导入方法依赖的package包/类
protected static List<DataType> extractOutputTypes(List<Symbol> outputs, List<Projection> projections) {
Projection lastProjection = Iterables.getLast(projections, null);
if (lastProjection == null) {
return Symbols.extractTypes(outputs);
} else {
return Symbols.extractTypes(lastProjection.outputs());
}
}
示例3: name
import com.google.common.collect.Iterables; //导入方法依赖的package包/类
@Default
Optional<String> name() {
if (signature().isEmpty()) {
return Optional.absent();
}
Term last = Iterables.getLast(signature());
if (last.isWordOrNumber() && !last.is("static")) {
return Optional.of(last.toString());
}
return Optional.absent();
}
示例4: getCompletions
import com.google.common.collect.Iterables; //导入方法依赖的package包/类
@Override
public Iterator<String> getCompletions(ArgumentContext context) {
String textSoFar = context.text;
List<String> sections = COMMA_SPLITTER.splitToList(textSoFar);
String lastSection = Iterables.getLast(sections);
String prependText = String.join(",", sections.subList(0, sections.size() - 1));
Iterator<String> integer = Iterators.transform(delegate.getCompletions(context.withText(lastSection)), prependText::concat);
if (textSoFar.isEmpty() || textSoFar.endsWith(",") || textSoFar.codePoints().filter(cp -> cp == ',').count() >= (dimensions - 1)) {
return integer;
}
return Iterators.concat(integer, Iterators.transform(COMMA.iterator(), textSoFar::concat));
}
示例5: toString
import com.google.common.collect.Iterables; //导入方法依赖的package包/类
/**
* Generates a "name"=value string; the total number of retrieved datapoints will be printed
* <p/> if a datapoint map is defined, and it is not empty, the last value will also be printed
*/
@Override
public String toString() {
StringBuilder sb = new StringBuilder().append('"').append(metric()).append('"');
// print information about the datapoints (if data is available)
if (!datapoints().isEmpty()) {
String lastValue = Iterables.getLast(datapoints().values());
sb.append('=').append(lastValue);
}
sb.append(" (").append(datapoints().size()).append(" data points)");
return sb.toString();
}
示例6: apply
import com.google.common.collect.Iterables; //导入方法依赖的package包/类
@Override
@SuppressFBWarnings(value = "DE_MIGHT_IGNORE", justification = "Any exceptions are to be ignored")
public T apply(final Iterable<T> input) {
if (null == input) {
throw new IllegalArgumentException("Input cannot be null");
}
try {
return Iterables.getLast(input, null);
} finally {
CloseableUtil.close(input);
}
}
示例7: onFailure
import com.google.common.collect.Iterables; //导入方法依赖的package包/类
@Override
public void onFailure(Throwable t) {
if (t instanceof UserRecordFailedException) {
Attempt last = Iterables.getLast(((UserRecordFailedException) t).getResult().getAttempts());
throw new DataException("Kinesis Producer was not able to publish data - " + last.getErrorCode() + "-"
+ last.getErrorMessage());
}
throw new DataException("Exception during Kinesis put", t);
}
示例8: answer
import com.google.common.collect.Iterables; //导入方法依赖的package包/类
@Override
public HealthResponse answer(InvocationOnMock invocation) {
URI uri = invocation.getArgumentAt(0, URI.class);
List<String> pathSegments = UriComponentsBuilder.fromUri(uri).build().getPathSegments();
String status = Iterables.getLast(pathSegments);
if ("EXCEPTION".equals(status)) {
throw new RestClientException("simulated exception");
}
return HealthResponse.builder().status(new Status(status)).build();
}
示例9: getLastSnapshot
import com.google.common.collect.Iterables; //导入方法依赖的package包/类
public Optional<ConfigSnapshot> getLastSnapshot() {
ConfigSnapshot last = Iterables.getLast(snapshots, null);
return last == null ? Optional.<ConfigSnapshot>absent() : Optional.of(last);
}
示例10: newOwner
import com.google.common.collect.Iterables; //导入方法依赖的package包/类
@Override
public String newOwner(String currentOwner, Collection<String> viableCandidates) {
return Iterables.getLast(viableCandidates);
}
示例11: getModState
import com.google.common.collect.Iterables; //导入方法依赖的package包/类
public ModState getModState(ModContainer selectedMod)
{
return Iterables.getLast(modStates.get(selectedMod.getModId()), ModState.AVAILABLE);
}
示例12: simpleName
import com.google.common.collect.Iterables; //导入方法依赖的package包/类
String simpleName() {
return Iterables.getLast(Splitter.on('.').splitToList(qualifiedName));
}
示例13: parse
import com.google.common.collect.Iterables; //导入方法依赖的package包/类
public static Stream<Pair<String, String>> parse(String[] args)
{
String full = String.join(" ", args);
StringReader reader = new StringReader(full);
StreamTokenizer tokenizer = new StreamTokenizer(reader);
tokenizer.resetSyntax();
tokenizer.wordChars(0, Integer.MAX_VALUE);
tokenizer.whitespaceChars(0, ' ');
tokenizer.quoteChar('"');
List<String> parsed = new ArrayList<>();
List<String> raw = new ArrayList<>();
int last_tt = StreamTokenizer.TT_EOF;
int lastIndex = 0;
try
{
while (tokenizer.nextToken() != StreamTokenizer.TT_EOF)
{
int idx = Math.min(index(reader), full.length());
String arg = tokenizer.sval;
String argRaw = full.substring(lastIndex, idx);
parsed.add(arg);
raw.add(tokenizer.ttype != '\"' ? argRaw.trim() : argRaw);
lastIndex = idx;
last_tt = tokenizer.ttype;
}
}
catch (IOException e)
{
// Should never happen
MCOpts.logger.error("Error reading string", e);
}
reader.close();
if (args.length > 0 && args[args.length - 1].length() == 0)
{
String lastRaw = raw.size() > 0 ? Iterables.getLast(raw) : null;
// Are we in an open quote?
if (!(last_tt == '\"' && (lastRaw == null || lastRaw.charAt(lastRaw.length() - 1) != '\"')))
{
// We are currently writing a new param
parsed.add("");
raw.add("");
}
}
return IntStream.range(0, parsed.size())
.mapToObj(i -> Pair.of(raw.get(i), parsed.get(i)));
}
示例14: applyThreshold
import com.google.common.collect.Iterables; //导入方法依赖的package包/类
/**
* Check for the input points, compare each with threshold, if it continue
* to pass the threshold for the critical/warn/info duration time period, change
* its the value to be critical/warn/info, otherwise, it's ok
*/
List<Transmutation> applyThreshold(List<Transmutation> points) {
// nothing to do
if (points.isEmpty()) {
return null;
}
Transmutation lastPoint = Iterables.getLast(points);
ZonedDateTime lastPointTS = lastPoint.time();
// get the timestamp for the critical, warning, info durations
// if the millisecond unit is not supported, it will throw UnsupportedTemporalTypeException
ZonedDateTime infoDurationTS = lastPointTS.minus(infoDurationMillis(), ChronoUnit.MILLIS);
ZonedDateTime warnDurationTS = lastPointTS.minus(warnDurationMillis(), ChronoUnit.MILLIS);
ZonedDateTime criticalDurationTS = lastPointTS.minus(criticalDurationMillis(), ChronoUnit.MILLIS);
ListIterator<Transmutation> iter = points.listIterator(points.size());
boolean matchThreshold = true;
boolean atWarningLevel = false;
boolean atInfoLevel = false;
while (iter.hasPrevious() && matchThreshold) {
Transmutation result = iter.previous();
ZonedDateTime pointTS = result.time();
Number value = result.value();
matchThreshold = type().matches(value, threshold());
if (matchThreshold) {
if (pointTS.compareTo(criticalDurationTS) <= 0) {
return Collections.singletonList(appendMessage(changeValue(result, CRIT.value()), CRIT.code(), threshold(), criticalDurationMillis()));
} else if (pointTS.compareTo(warnDurationTS) <= 0) {
atWarningLevel = true;
} else if (pointTS.compareTo(infoDurationTS) <= 0) {
atInfoLevel = true;
}
} else {
if (pointTS.compareTo(warnDurationTS) <= 0) {
return Collections.singletonList(appendMessage(changeValue(result, WARN.value()), WARN.code(), threshold(), warnDurationMillis()));
} else if (pointTS.compareTo(infoDurationTS) <= 0) {
return Collections.singletonList(appendMessage(changeValue(result, INFO.value()), INFO.code(), threshold(), warnDurationMillis()));
} else {
return Collections.singletonList(changeValue(result, OK.value())); // OK status
}
}
}
// critical, warning or info duration value is longer than available input time series
return atWarningLevel
? Collections.singletonList(appendMessage(changeValue(lastPoint, WARN.value()), WARN.code(), threshold(), warnDurationMillis()))
: (atInfoLevel
? Collections.singletonList(appendMessage(changeValue(lastPoint, INFO.value()), INFO.code(), threshold(), warnDurationMillis()))
: Collections.singletonList(changeValue(lastPoint, OK.value())));
}
示例15: getSuffix
import com.google.common.collect.Iterables; //导入方法依赖的package包/类
public String getSuffix()
{
return Iterables.getLast(parts);
}