List of usage examples for com.google.common.collect Lists reverse
@CheckReturnValue public static <T> List<T> reverse(List<T> list)
From source file:com.metamx.common.lifecycle.Lifecycle.java
public void stop() { synchronized (handlers) { 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();/*from w w w. ja v a 2 s . co m*/ } catch (Exception e) { log.warn(e, "exception thrown when stopping %s", handler); exceptions.add(e); } } } started.set(false); if (!exceptions.isEmpty()) { throw Throwables.propagate(exceptions.get(0)); } } }
From source file:org.atteo.moonshine.services.ServicesImplementation.java
@Override public void close() { unregisterFromJMX();/* w w w. j ava 2 s .c om*/ stop(); for (LifeCycleListener listener : listeners) { listener.closing(); } for (ServiceWrapper service : Lists.reverse(services)) { service.close(); } if (logger != null) { logger.info("All services stopped"); } injector = null; }
From source file:com.searchcode.app.util.LoggerWrapper.java
public synchronized List<String> getApiLogs() { List<String> values = new ArrayList<>(); try {/*from w w w . j ava 2 s . c o m*/ values = new ArrayList(this.apiLog); values = Lists.reverse(values); } catch (ArrayIndexOutOfBoundsException ignored) { } return values; }
From source file:org.sosy_lab.cpachecker.util.predicates.matching.SmtAstMatcherImpl.java
protected SmtAstMatchResult matchFormulaChildrenInSequence(final Formula pRootFormula, final List<? extends Formula> pChildFormulas, final SmtAstPatternSelection pChildPatterns, final Optional<Multimap<String, Formula>> pBindingRestrictions, boolean pConsiderPatternsInReverse) { final LogicalConnection logic = pChildPatterns.getRelationship(); final Iterator<SmtAstPatternSelectionElement> pItPatternsInSequence; if (pConsiderPatternsInReverse) { pItPatternsInSequence = Lists.reverse(pChildPatterns.getPatterns()).iterator(); } else {//ww w. j a va 2 s.c o m pItPatternsInSequence = pChildPatterns.iterator(); } SmtAstMatchResultImpl result = new SmtAstMatchResultImpl(); result.setMatchingRootFormula(pRootFormula); if (logic.isDontCare()) { return wrapPositiveMatchResult(result, "Don't care"); } // Perform the matching recursively on the arguments Set<SmtAstPatternSelectionElement> argPatternsMatched = Sets.newHashSet(); for (Formula childFormula : pChildFormulas) { if (!pItPatternsInSequence.hasNext()) { break; } final SmtAstPatternSelectionElement argPattern = pItPatternsInSequence.next(); final SmtAstMatchResult functionArgumentResult; if (argPattern instanceof SmtAstPattern) { functionArgumentResult = internalPerform(pRootFormula, childFormula, (SmtAstPattern) argPattern, pBindingRestrictions); } else { functionArgumentResult = matchSelectionOnOneFormula(pRootFormula, childFormula, (SmtAstPatternSelection) argPattern, pBindingRestrictions); } if (functionArgumentResult.matches()) { argPatternsMatched.add(argPattern); result.putMatchingArgumentFormula(argPattern, childFormula); for (String boundVar : functionArgumentResult.getBoundVariables()) { for (Formula varBinding : functionArgumentResult.getVariableBindings(boundVar)) { result.putBoundVaribale(boundVar, varBinding); } } if (logic.isNone()) { return newMatchFailedResult("Match but NONE should!"); } } else if (logic.isAnd()) { return newMatchFailedResult("No match but ALL should!"); } } if (argPatternsMatched.isEmpty() && logic.isOr()) { return newMatchFailedResult("No match but ANY should!"); } if (argPatternsMatched.size() != pChildPatterns.getPatterns().size() && logic.isAnd()) { // assert false; // might be dead code return newMatchFailedResult("No match but ALL should!"); } return wrapPositiveMatchResult(result, "Last in matchFormulaChildrenInSequence"); }
From source file:ch.puzzle.itc.mobiliar.presentation.templateEdit.EditTemplateView.java
public void save() { boolean success = true; String errorMessage = "Was not able to save the template: "; try {/* w w w . j a v a 2s . com*/ // set the template to testing mode... template.setTesting(settings.isTestingMode()); if (template.isTesting()) { if (selectedStp != null) { template.setName(selectedStp.getStpName()); } else { throw new AMWException("No STP-name selected!"); } } if (template.getId() == null && !canAdd()) { throw new AMWException("No permission to create template!"); } else if (!canModifyTemplates()) { throw new AMWException("No permission to modify templates!"); } if (relationIdForTemplate != null) { templateEditor.saveTemplateForRelation(template, relationIdForTemplate, resourceId != null); } else if (resourceId == null) { templateEditor.saveTemplateForResourceType(template, resourceTypeId); } else { templateEditor.saveTemplateForResource(template, resourceId); } } catch (ResourceNotFoundException | ResourceTypeNotFoundException e) { GlobalMessageAppender.addErrorMessage(errorMessage + e.getMessage()); success = false; } catch (AMWException e) { GlobalMessageAppender.addErrorMessage(e); success = false; } if (success) { GlobalMessageAppender.addSuccessMessage("Template successfully saved."); revisionInformations = Lists.reverse(templateEditor.getTemplateRevisions(template.getId())); } }
From source file:com.addthis.codec.jackson.Jackson.java
public static JsonMappingException maybeImproveLocation(JsonLocation wrapLoc, JsonMappingException cause) { JsonLocation exLoc = cause.getLocation(); if (isRealLocation(wrapLoc) && !isRealLocation(exLoc)) { if (wrapLoc.getSourceRef() instanceof ConfigValue) { ConfigValue locRef = (ConfigValue) wrapLoc.getSourceRef(); List<JsonMappingException.Reference> paths = cause.getPath(); for (JsonMappingException.Reference path : paths) { if (locRef instanceof ConfigObject) { String fieldName = path.getFieldName(); ConfigObject locRefObject = (ConfigObject) locRef; if (locRefObject.containsKey(fieldName)) { locRef = locRefObject.get(fieldName); } else { break; }// www . j a v a 2s .c om } else if (locRef instanceof ConfigList) { int fieldIndex = path.getIndex(); ConfigList locRefList = (ConfigList) locRef; if ((fieldIndex >= 0) && (locRefList.size() > fieldIndex)) { locRef = locRefList.get(fieldIndex); } else { break; } } else { break; } } if (locRef != wrapLoc.getSourceRef()) { wrapLoc = fromConfigValue(locRef); } } List<JsonMappingException.Reference> paths = Lists.reverse(cause.getPath()); if (!paths.isEmpty()) { JsonMappingException withLoc = new JsonMappingException(rootMessage(cause), wrapLoc, cause); for (JsonMappingException.Reference path : paths) { withLoc.prependPath(path); } return withLoc; } else { return new JsonMappingException(rootMessage(cause), wrapLoc, cause); } } return cause; }
From source file:sg.atom.utils.execution.lifecycle.Lifecycle.java
public void stop() { synchronized (handlers) { 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();/* w w w . ja va 2s .co m*/ } catch (Exception e) { // log.warn(handler, "exception thrown when stopping %s", e); exceptions.add(e); } } } started.set(false); if (!exceptions.isEmpty()) { throw Throwables.propagate(exceptions.get(0)); } } }
From source file:com.android.ahat.AhatSnapshot.java
public Site getSite(int stackId, int depth) { Site site = mRootSite;//from w w w. ja v a 2 s . c o m StackTrace stack = mSnapshot.getStackTrace(stackId); if (stack != null) { StackFrame[] frames = getStackFrames(stack); if (frames != null) { List<StackFrame> path = Lists.reverse(Arrays.asList(frames)); if (depth >= 0) { path = path.subList(0, depth); } site = mRootSite.getChild(path.iterator()); } } return site; }
From source file:org.jetbrains.jet.lang.resolve.DescriptorUtils.java
@NotNull public static List<DeclarationDescriptor> getPathWithoutRootNsAndModule( @NotNull DeclarationDescriptor descriptor) { List<DeclarationDescriptor> path = Lists.newArrayList(); DeclarationDescriptor current = descriptor; while (true) { if (current instanceof NamespaceDescriptor && isRootNamespace((NamespaceDescriptor) current)) { return Lists.reverse(path); }/*from w w w. j a va2 s . c o m*/ path.add(current); current = current.getContainingDeclaration(); } }
From source file:de.iteratec.iteraplan.businesslogic.exchange.elasticmi.write.model.MiIteraplanDiffWriter.java
public boolean writeDifferences(MergeStrategy strategy) { LOGGER.info("Writing Diffs..."); this.relationshipSetter.setMergeStrategy(strategy); this.attributeValueSetter.setMergeStrategy(strategy); this.builtinPropertySetter.setMergeStrategy(strategy); //Explicitly put ISI and IF last for create, and first for delete List<RStructuredTypeExpression> orderedForCreate = StructuredTypeSortUtil .orderExistentially(rMetamodel.getStructuredTypes()); orderedForCreate.remove(rMetamodel.findStructuredTypeByPersistentName("InformationFlow")); orderedForCreate.remove(rMetamodel.findStructuredTypeByPersistentName("InformationSystemInterface")); orderedForCreate.add(rMetamodel.findStructuredTypeByPersistentName("InformationSystemInterface")); orderedForCreate.add(rMetamodel.findStructuredTypeByPersistentName("InformationFlow")); LOGGER.info("Step 1: create structured types..."); for (RStructuredTypeExpression type : orderedForCreate) { createObjectExpressions(modelDiff.getCreateDiffsForType(type), strategy); }//from www . j a v a 2 s .c o m LOGGER.info("Step 1 done."); LOGGER.info("Step 2: add relationships for sortal types..."); for (RStructuredTypeExpression type : orderedForCreate) { //Note: ordering does not matter here connectInstances(type, modelDiff.getCreateDiffsForType(type), strategy); } LOGGER.info("Step 2 done."); LOGGER.info("Step 4: update universal types..."); for (RStructuredTypeExpression type : orderedForCreate) { updateExistingObjectExpressions(type, modelDiff.getUpdateDiffsForType(type), strategy); } LOGGER.info("Step 4 done."); LOGGER.info("Step 5: delete structured types..."); List<RStructuredTypeExpression> orderedForDelete = Lists.reverse(orderedForCreate); for (RStructuredTypeExpression type : orderedForDelete) { deleteObjectExpressions(type, modelDiff.getDeleteDiffsForType(type), strategy); } LOGGER.info("Step 5 done."); //cleanup has been skipped during diff application, execute it now bbServiceLocator.getAllBBService().performCleanup(); LOGGER.info("All Diffs written."); return writeSuccess; }