List of usage examples for com.google.common.collect Lists reverse
@CheckReturnValue public static <T> List<T> reverse(List<T> list)
From source file:org.apache.hive.testutils.HiveTestEnvSetup.java
@Override protected void after() { try {/*from w ww. j a v a2 s . c o m*/ for (IHiveTestRule p : Lists.reverse(parts)) { p.afterClass(testEnvContext); } } catch (Exception e) { throw new RuntimeException("test-subsystem error", e); } }
From source file:org.jboss.hal.processor.EsDocProcessor.java
private String comment(Element element, String padding) { List<String> parameters = new ArrayList<>(); String comment = elementUtils.getDocComment(element); if (comment != null) { // process comment line by line List<String> lines = stream(Splitter.on('\n').trimResults().split(comment).spliterator(), false) // not supported by ESDoc .filter(line -> !(line.contains("@author") || line.contains("@version"))) // process @param and @return in methods .map(line -> {// w ww.j a va 2s . com String result = line; if (element instanceof ExecutableElement) { ExecutableElement method = (ExecutableElement) element; if (line.startsWith(PARAM_TAG)) { String paramType; String lineWithoutParam = line.substring(PARAM_TAG.length()); VariableElement parameter = getParameter(method, parameters.size()); if (parameter != null) { EsParam esParam = parameter.getAnnotation(EsParam.class); if (esParam != null) { paramType = esParam.value(); } else { paramType = simpleName(parameter.asType().toString()); } result = PARAM_TAG + " {" + paramType + "}" + lineWithoutParam; } parameters.add(line); // parameters++ } else if (line.startsWith(RETURN_TAG)) { String returnType; EsReturn esReturn = method.getAnnotation(EsReturn.class); if (esReturn != null) { returnType = esReturn.value(); } else { returnType = simpleName(method.getReturnType().toString()); } result = RETURN_TAG + " {" + returnType + "}" + line.substring(RETURN_TAG.length()); } } return result; }) // format comment and collect into list .map(line -> padding + " * " + line).collect(toList()); // remove trailing empty lines List<String> reversed = Lists.reverse(lines); for (Iterator<String> iterator = reversed.iterator(); iterator.hasNext();) { String line = iterator.next(); if (line.equals(padding + " * ")) { iterator.remove(); } else { break; } } if (reversed.isEmpty()) { comment = null; } else { // add first and last lines comment = Lists.reverse(reversed).stream().collect(joining("\n")); comment = "/**\n" + comment + "\n" + padding + " */"; } } return comment; }
From source file:org.cloudsmith.geppetto.ruby.jrubyparser.RubyRakefileTaskFinder.java
/** * @param root// w w w . j a va 2 s .c om * @return */ private boolean processCallNode(CallNode root, Map<String, String> resultMap) { String mName = root.getName(); try { if (mName.equals("new")) { List<String> receiver = constEvaluator.stringList(constEvaluator.eval(root.getReceiver())); boolean isRspec = receiver.equals(rspecTask); boolean isCucumber = !isRspec && receiver.equals(cucumberTask); if (isRspec || isCucumber) { // recognized as a task Node argsNode = getTaskNameNodeFromArgNode(root.getArgs()); List<String> nameList = constEvaluator.stringList(constEvaluator.eval(argsNode)); if (nameList.size() < 1) { if (isRspec) nameList = Lists.newArrayList("spec"); else nameList = Lists.newArrayList("cucumber"); } String taskName = Joiner.on(":").join(Iterables.concat(Lists.reverse(nameStack), nameList)); resultMap.put(taskName, lastDesc); // System.err.println("Added task: " + taskName + " with description: " + lastDesc); lastDesc = ""; // consumed } } } catch (RuntimeException e) { // Failed to handle some constant evaluation - not sure what, should not fail, could be // caused by faulty ruby code (syntax errors etc.) causing a strange model. // Should be handled elsewhere. return false; } return false; }
From source file:org.apache.nifi.processors.standard.CalculateRecordStats.java
protected Map filterBySize(Map<String, Integer> values, Integer limit, List<String> baseKeys) { Map<String, Integer> toFilter = values.entrySet().stream().filter(e -> !baseKeys.contains(e.getKey())) .collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue())); Map<String, Integer> retVal = values.entrySet().stream().filter((e -> baseKeys.contains(e.getKey()))) .collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue())); List<Map.Entry<String, Integer>> _flat = new ArrayList<>(toFilter.entrySet()); _flat.sort(Map.Entry.comparingByValue()); _flat = Lists.reverse(_flat); for (int index = 0; index < _flat.size() && index < limit; index++) { retVal.put(_flat.get(index).getKey(), _flat.get(index).getValue()); }/*from www .j av a 2s. co m*/ return retVal; }
From source file:org.ballerinalang.ballerina.openapi.convertor.service.OpenApiServiceMapper.java
/** * Creates tag openApi definition.//from www.j a v a2 s .c o m * * @param annotationExpression The ballerina annotation attribute value for tag. * @param openApi The openApi definition which the tags needs to be build on. */ private void createTagModel(BLangExpression annotationExpression, Swagger openApi) { if (null != annotationExpression) { List<Tag> tags = new LinkedList<>(); BLangArrayLiteral tagArray = (BLangArrayLiteral) annotationExpression; for (ExpressionNode expr : tagArray.getExpressions()) { List<BLangRecordKeyValue> tagList = ((BLangRecordLiteral) expr).getKeyValuePairs(); Map<String, BLangExpression> tagAttributes = ConverterUtils.listToMap(tagList); Tag tag = new Tag(); if (tagAttributes.containsKey(ConverterConstants.ATTR_NAME)) { tag.setName( ConverterUtils.getStringLiteralValue(tagAttributes.get(ConverterConstants.ATTR_NAME))); } if (tagAttributes.containsKey(ConverterConstants.ATTR_DESCRIPTION)) { tag.setDescription(ConverterUtils .getStringLiteralValue(tagAttributes.get(ConverterConstants.ATTR_DESCRIPTION))); } tags.add(tag); } openApi.setTags(Lists.reverse(tags)); } }
From source file:org.ballerinalang.ballerina.swagger.convertor.service.SwaggerServiceMapper.java
/** * Creates tag swagger definition./*ww w. j av a 2 s .co m*/ * * @param annotationExpression The ballerina annotation attribute value for tag. * @param swagger The swagger definition which the tags needs to be build on. */ private void createTagModel(BLangExpression annotationExpression, Swagger swagger) { if (null != annotationExpression) { List<Tag> tags = new LinkedList<>(); BLangArrayLiteral tagArray = (BLangArrayLiteral) annotationExpression; for (ExpressionNode expr : tagArray.getExpressions()) { List<BLangRecordKeyValue> tagList = ((BLangRecordLiteral) expr).getKeyValuePairs(); Map<String, BLangExpression> tagAttributes = ConverterUtils.listToMap(tagList); Tag tag = new Tag(); if (tagAttributes.containsKey(ConverterConstants.ATTR_NAME)) { tag.setName( ConverterUtils.getStringLiteralValue(tagAttributes.get(ConverterConstants.ATTR_NAME))); } if (tagAttributes.containsKey(ConverterConstants.ATTR_DESCRIPTION)) { tag.setDescription(ConverterUtils .getStringLiteralValue(tagAttributes.get(ConverterConstants.ATTR_DESCRIPTION))); } tags.add(tag); } swagger.setTags(Lists.reverse(tags)); } }
From source file:com.phone.cn.plugin.service.BaseTreeableService.java
/** * /*from w ww . j a va 2 s. co m*/ * * @param parentIds * @return */ @SuppressWarnings("unchecked") public List<M> findAncestor(String parentIds) { if (StringUtils.isEmpty(parentIds)) { return Collections.EMPTY_LIST; } String[] ids = StringUtils.tokenizeToStringArray(parentIds, "/"); return Lists.reverse( findAllWithNoPageNoSort(Searchable.newSearchable().addSearchFilter("id", SearchOperator.in, ids))); }
From source file:io.druid.java.util.common.lifecycle.Lifecycle.java
public void stop() { synchronized (handlers) { if (!started.compareAndSet(true, false)) { log.info("Already stopped and stop was called. Silently skipping"); return; }/* w ww.j a v a2s . c o m*/ List<Exception> exceptions = Lists.newArrayList(); for (Stage stage : Lists.reverse(stagesOrdered())) { final CopyOnWriteArrayList<Handler> stageHandlers = handlers.get(stage); final ListIterator<Handler> iter = stageHandlers.listIterator(stageHandlers.size()); while (iter.hasPrevious()) { final Handler handler = iter.previous(); try { handler.stop(); } catch (Exception e) { log.warn(e, "exception thrown when stopping %s", handler); exceptions.add(e); } } } if (!exceptions.isEmpty()) { throw Throwables.propagate(exceptions.get(0)); } } }
From source file:org.opencms.ade.configuration.CmsResourceTypeConfig.java
/** * Creates a folder and its parent folders if they don't exist.<p> * /*from w w w.j a v a 2 s . c om*/ * @param cms the CMS context to use * @param rootPath the folder root path * * @throws CmsException if something goes wrong */ public void createFolder(CmsObject cms, String rootPath) throws CmsException { cms.getRequestContext().setSiteRoot(""); List<String> parents = new ArrayList<String>(); String currentPath = rootPath; while (currentPath != null) { if (cms.existsResource(currentPath)) { break; } parents.add(currentPath); currentPath = CmsResource.getParentFolder(currentPath); } parents = Lists.reverse(parents); for (String parent : parents) { try { cms.createResource(parent, CmsResourceTypeFolder.getStaticTypeId()); try { cms.unlockResource(parent); } catch (CmsException e) { // may happen if parent folder is locked also if (LOG.isInfoEnabled()) { LOG.info(e); } } } catch (CmsVfsResourceAlreadyExistsException e) { // nop } } }
From source file:org.kuali.kra.protocol.actions.submit.ProtocolActionServiceImplBase.java
protected ProtocolSubmissionBase getSubmissionForAction(String actionTypeCode, ProtocolBase protocol) { if (ACTION_SUBMISSION_MAPPINGS.containsKey(actionTypeCode) && protocol.getProtocolSubmissions() != null) { for (ProtocolSubmissionBase submission : Lists.reverse(protocol.getProtocolSubmissions())) { if (submission.getSubmissionStatusCode().equals(ProtocolSubmissionStatus.PENDING) && ACTION_SUBMISSION_MAPPINGS.get(actionTypeCode) .equals(submission.getSubmissionTypeCode())) { return submission; }//from ww w. j av a 2 s . c o m } } return protocol.getProtocolSubmission(); }