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.eclipse.xtext.util.formallang.FollowerFunctionImpl.java
protected Iterable<E> orderedIterable(Iterable<E> elements) { return direction == Direction.L2R ? elements : Lists.reverse(toList(elements)); }
From source file:com.addthis.codec.jackson.Jackson.java
public static IOException maybeUnwrapPath(String pathToSkip, IOException cause) { if ((pathToSkip != null) && (cause instanceof JsonMappingException)) { JsonMappingException mappingException = (JsonMappingException) cause; List<JsonMappingException.Reference> paths = mappingException.getPath(); if (!paths.isEmpty()) { Iterator<String> pathIterator = dotSplitter.split(pathToSkip).iterator(); Iterator<JsonMappingException.Reference> refIterator = paths.iterator(); while (pathIterator.hasNext()) { String pathToSkipPart = pathIterator.next(); if (!refIterator.hasNext()) { return cause; }//from w w w. ja va 2s .c o m String nextRefField = refIterator.next().getFieldName(); if (!pathToSkipPart.equals(nextRefField)) { return cause; } } JsonMappingException unwrapped = new JsonMappingException(rootMessage(mappingException), mappingException.getLocation(), mappingException.getCause()); if (refIterator.hasNext()) { List<JsonMappingException.Reference> remainingRefs = Lists.newArrayList(refIterator); for (JsonMappingException.Reference reference : Lists.reverse(remainingRefs)) { unwrapped.prependPath(reference); } } return unwrapped; } } return cause; }
From source file:com.eucalyptus.cloud.run.AdmissionControl.java
private static void rollbackAllocations(Allocation allocInfo, List<ResourceAllocator> finished, Exception e) { for (ResourceAllocator rollback : Lists.reverse(finished)) { try {/* w ww .j a v a2 s.co m*/ rollback.fail(allocInfo, e); } catch (Exception e1) { LOG.debug(e1, e1); } } }
From source file:max.hubbard.bettershops.Menus.ShopMenus.Trading.java
@Override public void draw(final Player p, final int page, final Object... obj) { inv.clear();/*w ww. jav a 2s. c om*/ ItemStack item = new ItemStack(Material.STAINED_GLASS_PANE, 1, shop.getFrameColor()); ItemMeta m = item.getItemMeta(); m.setDisplayName(" "); item.setItemMeta(m); for (int i = 0; i < 18; i++) { inv.setItem(i, item); } ItemStack info = new ItemStack(Material.NAME_TAG); ItemMeta infoMeta = info.getItemMeta(); infoMeta.setDisplayName(Language.getString("Trades", "Trades")); infoMeta.setLore(Arrays.asList(Language.getString("Trades", "TradesLore"))); info.setItemMeta(infoMeta); ItemStack add = new ItemStack(Material.STAINED_GLASS_PANE, 1, (byte) 5); ItemMeta addMeta = add.getItemMeta(); addMeta.setDisplayName(Language.getString("Trades", "AddTrade")); addMeta.setLore(Arrays.asList(Language.getString("Trades", "AddLore"))); add.setItemMeta(addMeta); ClickableItem addClick = new ClickableItem(new ShopItemStack(add), inv, p); addClick.addLeftClickAction(new LeftClickAction() { @Override public void onAction(InventoryClickEvent e) { final AnvilManager man = new AnvilManager(p); Bukkit.getScheduler().runTaskAsynchronously(Bukkit.getPluginManager().getPlugin("BetterShops"), new Runnable() { @Override public void run() { String na = man.call(); if (CreateShop.isAlphaNumeric(na)) { if (TradeManager.getTrade(na) == null) { Trade tr = new Trade(na, shop, new ArrayList<ItemStack>(), 0, new ArrayList<ItemStack>(), 0, false); TradeManager.ps.put(p.getUniqueId(), tr); shop.getMenu(MenuType.TRADE_MANAGER).draw(p, page, tr, tr); } else { p.sendMessage(Language.getString("Messages", "Prefix") + Language.getString("Messages", "NameTaken")); draw(p, page, obj); } } else { p.sendMessage(Language.getString("Messages", "Prefix") + Language.getString("Messages", "ImproperName")); draw(p, page, obj); } } }); } }); ItemStack back = new ItemStack(Material.ARROW); ItemMeta backMeta = back.getItemMeta(); backMeta.setDisplayName(Language.getString("MainGUI", "BackArrow")); back.setItemMeta(backMeta); ClickableItem backClick = new ClickableItem(new ShopItemStack(back), inv, p); backClick.addLeftClickAction(new LeftClickAction() { @Override public void onAction(InventoryClickEvent e) { shop.getMenu(MenuType.OWNER_BUYING).draw(p, page, obj); } }); ItemStack arrow = new ItemStack(Material.ARROW); ItemMeta arrowMeta = arrow.getItemMeta(); arrowMeta.setDisplayName(Language.getString("MainGUI", "NextPage")); arrow.setItemMeta(arrowMeta); ClickableItem arrowClick = new ClickableItem(new ShopItemStack(arrow), inv, p); arrowClick.addLeftClickAction(new LeftClickAction() { @Override public void onAction(InventoryClickEvent e) { draw(p, page + 1, obj); } }); ItemStack barrow = new ItemStack(Material.ARROW); ItemMeta barrowMeta = barrow.getItemMeta(); barrowMeta.setDisplayName(Language.getString("MainGUI", "PreviousPage")); barrow.setItemMeta(barrowMeta); ClickableItem barrowClick = new ClickableItem(new ShopItemStack(barrow), inv, p); barrowClick.addLeftClickAction(new LeftClickAction() { @Override public void onAction(InventoryClickEvent e) { draw(p, page - 1, obj); } }); if (page > 1) { inv.setItem(1, barrow); } inv.setItem(0, back); inv.setItem(4, info); inv.setItem(7, add); int maxPage = (int) Math.ceil((double) (shop.getHistory().getAllTransactions().size()) / 36); if (maxPage == 0) { maxPage = 1; } if (page != maxPage) { inv.setItem(8, arrow); } int j = 0; if (page > 1) { j = 36 * (page - 1); } int k = 0; if (TradeManager.getTrades(shop) != null) { k = TradeManager.getTrades(shop).size(); } if (page != maxPage) { k = k - (j + (TradeManager.getTrades(shop).size() - 36)); } List<Trade> list = TradeManager.getTrades(shop); List<Trade> l = Lists.reverse(list); if (list.size() > 0) { for (int i = j; i < k; i++) { final Trade trans = l.get(i); ItemStack it = trans.getIcon(); ItemMeta sk = it.getItemMeta(); sk.setDisplayName(Language.getString("Trades", "TradeId") + trans.getId()); if (trans.isTraded()) { sk.setLore(Arrays.asList(Language.getString("Trades", "Collect"))); } it.setItemMeta(sk); if (inv.firstEmpty() > 0) inv.setItem(inv.firstEmpty(), it); ClickableItem tradeClick = new ClickableItem(new ShopItemStack(it), inv, p); if (!trans.isTraded()) { tradeClick.addLeftClickAction(new LeftClickAction() { @Override public void onAction(InventoryClickEvent e) { shop.getMenu(MenuType.TRADE_MANAGER).draw(p, page, trans, trans); } }); } else { tradeClick.addLeftClickAction(new LeftClickAction() { @Override public void onAction(InventoryClickEvent e) { for (ItemStack it : trans.getRecievingItems()) { int amt = it.getAmount(); it.setAmount(1); Stocks.addItemsToInventory(it, p, amt); } TradeManager.removeTrade(trans, shop); draw(p, page); } }); } } } new BukkitRunnable() { @Override public void run() { p.openInventory(inv); } }.runTask(Bukkit.getPluginManager().getPlugin("BetterShops")); }
From source file:org.apache.calcite.jdbc.CalciteSchema.java
/** Returns the path of an object in this schema. */ public List<String> path(String name) { final List<String> list = new ArrayList<>(); if (name != null) { list.add(name);/*from w w w . j ava 2 s . c om*/ } for (CalciteSchema s = this; s != null; s = s.parent) { if (s.parent != null || !s.name.equals("")) { // Omit the root schema's name from the path if it's the empty string, // which it usually is. list.add(s.name); } } return ImmutableList.copyOf(Lists.reverse(list)); }
From source file:com.haulmont.cuba.core.sys.AppProperties.java
private void getValuesFromAppComponents(String key, List<String> values) { int index;//from w ww. ja v a 2s . c o m for (AppComponent component : Lists.reverse(appComponents.getComponents())) { String compValue = component.getProperty(key); if (StringUtils.isNotEmpty(compValue)) { index = 0; for (String valuePart : split(compValue)) { if (!values.contains(valuePart)) { values.add(index, valuePart); index++; } } if (!component.isAdditiveProperty(key)) { // we found overwrite, stop iteration break; } } } }
From source file:org.opencms.ade.configuration.CmsADEConfigData.java
/** * Generic method to merge lists of named configuration objects.<p> * /*w ww. j a v a 2 s . c o m*/ * The lists are merged such that the configuration objects from the child list rise to the front of the result list, * and two configuration objects will be merged themselves if they share the same name.<p> * * For example, if we have two lists of configuration objects:<p> * * parent: A1, B1, C1<p> * child: D2, B2<p> * * then the resulting list will look like:<p> * * D2, B3, A1, C1<p> * * where B3 is the result of merging B1 and B2.<p> * * @param <C> the type of configuration object * @param parentConfigs the parent configurations * @param childConfigs the child configurations * @return the merged configuration object list */ protected static <C extends I_CmsConfigurationObject<C>> List<C> combineConfigurationElements( List<C> parentConfigs, List<C> childConfigs) { List<C> result = new ArrayList<C>(); Map<String, C> map = new LinkedHashMap<String, C>(); if (parentConfigs != null) { for (C parent : Lists.reverse(parentConfigs)) { map.put(parent.getKey(), parent); } } if (childConfigs == null) { childConfigs = Collections.emptyList(); } for (C child : Lists.reverse(childConfigs)) { String childKey = child.getKey(); if (child.isDisabled()) { map.remove(childKey); } else { C parent = map.get(childKey); map.remove(childKey); C newValue; if (parent != null) { newValue = parent.merge(child); } else { newValue = child; } map.put(childKey, newValue); } } result = new ArrayList<C>(map.values()); Collections.reverse(result); // those multiple "reverse" calls may a bit confusing. They are there because on the one hand we want to keep the // configuration items from one configuration in the same order as they are defined, on the other hand we want // configuration items from a child configuration to rise to the top of the configuration items. // so for example, if the parent configuration has items with the keys A,B,C,E // and the child configuration has items with the keys C,B,D // we want the items of the combined configuration in the order C,B,D,A,E return result; }
From source file:org.eclipse.acceleo.internal.ide.ui.builders.AcceleoBuilder.java
/** * {@inheritDoc}// w w w. ja va 2 s.c o m * * @see org.eclipse.core.resources.IncrementalProjectBuilder#build(int, java.util.Map, * org.eclipse.core.runtime.IProgressMonitor) */ @Override @SuppressWarnings("rawtypes") protected IProject[] build(int kind, Map arguments, IProgressMonitor monitor) throws CoreException { IProject project = getProject(); if (project == null || !project.isAccessible()) { return new IProject[] {}; } this.mappedProjects.clear(); monitor.subTask( AcceleoUIMessages.getString("AcceleoBuilder.StartingBuild", project.getName(), Integer.valueOf(0))); //$NON-NLS-1$ long currentTimeMillis = System.currentTimeMillis(); // Generate all Acceleo Java Services modules List<IFile> javaFiles = this.members(getProject(), "java"); //$NON-NLS-1$ for (IFile iFile : javaFiles) { IJavaElement iJavaElement = JavaCore.create(iFile); if (iJavaElement instanceof ICompilationUnit) { ICompilationUnit iCompilationUnit = (ICompilationUnit) iJavaElement; if (JavaServicesUtils.isAcceleoJavaServicesClass(iCompilationUnit)) { JavaServicesUtils.generateAcceleoServicesModule(iCompilationUnit, monitor); } } } monitor.subTask(AcceleoUIMessages.getString("AcceleoBuilder.ComputeAccessibleEcores", Long //$NON-NLS-1$ .valueOf(System.currentTimeMillis() - currentTimeMillis))); IJavaProject javaProject = JavaCore.create(project); Set<AcceleoProjectClasspathEntry> entries = this.computeProjectClassPath(javaProject); File projectRoot = project.getLocation().toFile(); org.eclipse.acceleo.internal.parser.compiler.AcceleoProject acceleoProject = new org.eclipse.acceleo.internal.parser.compiler.AcceleoProject( projectRoot, entries); acceleoProject = this.computeProjectDependencies(acceleoProject, javaProject); monitor.subTask(AcceleoUIMessages.getString("AcceleoBuilder.LoadAccessibleEcores", Long //$NON-NLS-1$ .valueOf(System.currentTimeMillis() - currentTimeMillis))); // Check that all ".ecore" models in accessible projects have been loaded. AcceleoProject aProject = new AcceleoProject(project); List<IProject> accessibleProjects = new ArrayList<IProject>(); accessibleProjects = aProject.getRecursivelyAccessibleProjects(); for (IProject iProject : Lists.reverse(accessibleProjects)) { List<IFile> members = this.members(iProject, IAcceleoConstants.ECORE_FILE_EXTENSION); for (IFile iFile : members) { URI uri = URI.createPlatformResourceURI(iFile.getFullPath().toString(), true); AcceleoPackageRegistry.INSTANCE.registerEcorePackages(uri.toString(), AcceleoDynamicMetamodelResourceSetImpl.DYNAMIC_METAMODEL_RESOURCE_SET); } } monitor.subTask(AcceleoUIMessages.getString("AcceleoBuilder.ComputeAccessibleAcceleoModules", Long //$NON-NLS-1$ .valueOf(System.currentTimeMillis() - currentTimeMillis))); List<URI> accessibleOutputFiles = AcceleoProject.computeAcceleoModuleInRequiredPlugins(project); acceleoProject.addDependencies(Sets.newHashSet(accessibleOutputFiles)); AcceleoBuilderSettings settings = new AcceleoBuilderSettings(project); String resourceKind = settings.getResourceKind(); boolean useBinaryResources = !AcceleoBuilderSettings.BUILD_XMI_RESOURCE.equals(resourceKind); boolean usePlatformResourcePath = AcceleoBuilderSettings.COMPILATION_PLATFORM_RESOURCE .equals(settings.getCompilationKind()); Set<File> mainFiles = new LinkedHashSet<File>(); this.lastState = this.getLastState(this.getProject()); monitor.subTask(AcceleoUIMessages.getString("AcceleoBuilder.CompilationStart", Long.valueOf(System //$NON-NLS-1$ .currentTimeMillis() - currentTimeMillis))); if (kind == IncrementalProjectBuilder.FULL_BUILD) { // Full build -> build all mainFiles.addAll( buildAll(acceleoProject, project, useBinaryResources, usePlatformResourcePath, monitor)); } else { if (this.lastState == null) { // No state -> build all mainFiles.addAll( buildAll(acceleoProject, project, useBinaryResources, usePlatformResourcePath, monitor)); } else if (kind == IncrementalProjectBuilder.INCREMENTAL_BUILD || kind == IncrementalProjectBuilder.AUTO_BUILD) { mainFiles.addAll(this.incrementalBuild(acceleoProject, project, useBinaryResources, usePlatformResourcePath, monitor)); } else if (kind == IncrementalProjectBuilder.CLEAN_BUILD) { acceleoProject.clean(); this.cleanAcceleoMarkers(project); } } monitor.subTask(AcceleoUIMessages.getString("AcceleoBuilder.BuildFileNotCompiled", Long //$NON-NLS-1$ .valueOf(System.currentTimeMillis() - currentTimeMillis))); // Ensure that we didn't forget to build a file out of the dependency graph of the file(s) // currently // built, this can occur if two files are not related at all and we force the build of only one of // those files. Set<File> fileNotCompiled = acceleoProject.getFileNotCompiled(); for (File fileToBuild : fileNotCompiled) { org.eclipse.acceleo.internal.parser.compiler.AcceleoParser acceleoParser = new org.eclipse.acceleo.internal.parser.compiler.AcceleoParser( acceleoProject, useBinaryResources, usePlatformResourcePath); Set<File> builtFiles = acceleoParser.buildFile(fileToBuild, BasicMonitor.toMonitor(monitor)); this.addAcceleoMarkers(builtFiles, acceleoParser); mainFiles.addAll(acceleoParser.getMainFiles()); } // Launch the build of the MANIFEST.MF, Java launcher, build.acceleo etc. List<IFile> filesWithMainTag = new ArrayList<IFile>(); for (File mainFile : mainFiles) { IFile workspaceFile = ResourcesPlugin.getWorkspace().getRoot() .getFileForLocation(new Path(mainFile.getAbsolutePath())); filesWithMainTag.add(workspaceFile); } if (filesWithMainTag.size() > 0) { monitor.subTask(AcceleoUIMessages.getString("AcceleoBuilder.GeneratingAcceleoFiles", Long //$NON-NLS-1$ .valueOf(System.currentTimeMillis() - currentTimeMillis))); CreateRunnableAcceleoOperation createRunnableAcceleoOperation = new CreateRunnableAcceleoOperation( new AcceleoProject(project), filesWithMainTag); createRunnableAcceleoOperation.run(monitor); } monitor.subTask(AcceleoUIMessages.getString("AcceleoBuilder.RefreshingProjects", Long.valueOf(System //$NON-NLS-1$ .currentTimeMillis() - currentTimeMillis))); // Refresh all the projects potentially containing files. Set<org.eclipse.acceleo.internal.parser.compiler.AcceleoProject> projectsToRefresh = Sets .newHashSet(acceleoProject); projectsToRefresh.addAll(acceleoProject.getProjectDependencies()); projectsToRefresh.addAll(acceleoProject.getDependentProjects()); for (org.eclipse.acceleo.internal.parser.compiler.AcceleoProject projectToRefresh : projectsToRefresh) { IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects(); for (IProject iProject : projects) { if (iProject.isAccessible() && projectToRefresh.getProjectRoot().equals(iProject.getLocation().toFile())) { iProject.refreshLocal(IResource.DEPTH_INFINITE, monitor); } } } monitor.subTask(AcceleoUIMessages.getString("AcceleoBuilder.GenerateBuildFiles", Long.valueOf(System //$NON-NLS-1$ .currentTimeMillis() - currentTimeMillis))); generateAcceleoBuildFile(monitor); monitor.done(); return accessibleProjects.toArray(new IProject[accessibleProjects.size()]); }
From source file:co.cask.cdap.logging.write.LogLocation.java
/** * Return closeable iterator of {@link LogEvent} * @param logFilter filter for filtering log events * @param fromTimeMs start timestamp in millis * @param maxEvents max events to return * @return closeable iterator of previous log events *//*from w w w. j av a 2s .co m*/ @SuppressWarnings("WeakerAccess") public Collection<LogEvent> readLogPrev(Filter logFilter, long fromTimeMs, final int maxEvents) throws IOException { DataFileReader<GenericRecord> dataFileReader = createReader(); try { if (!dataFileReader.hasNext()) { return ImmutableList.of(); } List<List<LogEvent>> logSegments = Lists.newArrayList(); List<LogEvent> logSegment; int count = 0; // Calculate skipLen based on fileLength long length = location.length(); LOG.trace("Got file length {}", length); long skipLen = length / 10; if (skipLen > DEFAULT_SKIP_LEN || skipLen <= 0) { skipLen = DEFAULT_SKIP_LEN; } // For open file, endPosition sync marker is unknown so start from file length and read up to the actual EOF dataFileReader.sync(length); long finalSync = dataFileReader.previousSync(); logSegment = readToEndSyncPosition(dataFileReader, logFilter, fromTimeMs, -1); if (!logSegment.isEmpty()) { logSegments.add(logSegment); count = count + logSegment.size(); } LOG.trace("Read logevents {} from position {}", count, finalSync); long startPosition = finalSync; long endPosition = startPosition; long currentSync; while (startPosition > 0 && count < maxEvents) { // Skip to sync position less than current sync position startPosition = skipToPosition(dataFileReader, startPosition, endPosition, skipLen); currentSync = dataFileReader.previousSync(); logSegment = readToEndSyncPosition(dataFileReader, logFilter, fromTimeMs, endPosition); if (!logSegment.isEmpty()) { logSegments.add(logSegment); count = count + logSegment.size(); } LOG.trace("Read logevents {} from position {} to endPosition {}", count, currentSync, endPosition); endPosition = currentSync; } int skip = count >= maxEvents ? count - maxEvents : 0; return Lists.newArrayList(Iterables.skip(Iterables.concat(Lists.reverse(logSegments)), skip)); } finally { try { dataFileReader.close(); } catch (IOException e) { LOG.error("Got exception while closing log file {}", location, e); } } }
From source file:org.sosy_lab.cpachecker.util.refinement.UseDefRelation.java
private void buildRelation(ARGPath path) { PathIterator iterator = path.reversePathIterator(); while (iterator.hasNext()) { CFAEdge edge = iterator.getOutgoingEdge(); if (edge.getEdgeType() == CFAEdgeType.MultiEdge) { for (CFAEdge singleEdge : Lists.reverse(((MultiEdge) edge).getEdges())) { updateUseDefRelation(iterator.getAbstractState(), singleEdge); }/*from w w w . j av a 2s.com*/ } else { updateUseDefRelation(iterator.getAbstractState(), edge); } // stop the traversal once a fix-point is reached if (hasContradictingAssumeEdgeBeenHandled && unresolvedUses.isEmpty()) { break; } iterator.advance(); } }