List of usage examples for com.google.common.collect Iterables getLast
@Nullable public static <T> T getLast(Iterable<? extends T> iterable, @Nullable T defaultValue)
From source file:com.searchcode.app.util.SearchcodeLib.java
public String formatQueryStringAndDefault(String query) { String[] split = query.trim().split("\\s+"); List<String> stringList = new ArrayList<>(); String and = " AND "; String or = " OR "; String not = " NOT "; for (String term : split) { switch (term) { case "AND": if (Iterables.getLast(stringList, null) != null && !Iterables.getLast(stringList).equals(and)) { stringList.add(and);/*from www.j a va 2 s .c o m*/ } break; case "OR": if (Iterables.getLast(stringList, null) != null && !Iterables.getLast(stringList).equals(or)) { stringList.add(or); } break; case "NOT": if (Iterables.getLast(stringList, null) != null && !Iterables.getLast(stringList).equals(not)) { stringList.add(not); } break; default: if (Iterables.getLast(stringList, null) == null || Iterables.getLast(stringList).equals(and) || Iterables.getLast(stringList).equals(or) || Iterables.getLast(stringList).equals(not)) { stringList.add(" " + QueryParser.escape(term.toLowerCase()).replace("\\(", "(") .replace("\\)", ")").replace("\\*", "*") + " "); } else { stringList.add(and + QueryParser.escape(term.toLowerCase()).replace("\\(", "(") .replace("\\)", ")").replace("\\*", "*") + " "); } break; } } String temp = StringUtils.join(stringList, " "); return temp.trim(); }
From source file:org.apache.metron.common.stellar.shell.StellarShell.java
@Override public void complete(CompleteOperation completeOperation) { if (!completeOperation.getBuffer().isEmpty()) { String lastToken = Iterables.getLast(Splitter.on(" ").split(completeOperation.getBuffer()), null); if (lastToken != null && !lastToken.isEmpty()) { lastToken = lastToken.trim(); final String lastBit = lastToken; final boolean isDocRequest = isDoc(lastToken); if (isDocRequest) { lastToken = lastToken.substring(1); }//from w ww . j a v a2 s . com StellarExecutor.OperationType opType = StellarExecutor.OperationType.NORMAL; if (isDocRequest) { opType = StellarExecutor.OperationType.DOC; } else if (isMagic(lastToken)) { opType = StellarExecutor.OperationType.MAGIC; } Iterable<String> candidates = executor.autoComplete(lastToken, opType); if (candidates != null && !Iterables.isEmpty(candidates)) { completeOperation.setCompletionCandidates(Lists.newArrayList(Iterables.transform(candidates, s -> stripOff(completeOperation.getBuffer(), lastBit) + s))); } } } }
From source file:org.jfrog.hudson.plugins.artifactory.gradle.ArtifactoryGradleConfigurator.java
private Gradle getLastGradleBuild(AbstractProject project) { if (project instanceof Project) { List<Gradle> gradles = ActionableHelper.getBuilders((Project) project, Gradle.class); return Iterables.getLast(gradles, null); }// w w w . j a v a 2s . co m return null; }