List of usage examples for java.util Collections reverse
@SuppressWarnings({ "rawtypes", "unchecked" }) public static void reverse(List<?> list)
This method runs in linear time.
From source file:org.wallride.web.support.Pagination.java
public List<Pageable> getPageables(Pageable currentPageable, int interval) { List<Pageable> pageables = new ArrayList<>(); int start = page.getNumber() - interval; if (start < 0) { start = 0;//from w w w . ja v a 2s. c om } int end = page.getNumber() + interval; if (end > page.getTotalPages() - 1) { end = page.getTotalPages() - 1; } Pageable p; p = currentPageable; for (int i = getCurrentPageNumber(); i > start; i--) { p = p.previousOrFirst(); pageables.add(p); } Collections.reverse(pageables); pageables.add(currentPageable); p = currentPageable; for (int i = getCurrentPageNumber(); i < end; i++) { p = p.next(); pageables.add(p); } return pageables; }
From source file:lineage2.gameserver.skills.effects.EffectDispelEffects.java
/** * Method onStart.//from www .j a v a2 s . c o m */ @Override public void onStart() { List<Effect> _musicList = new ArrayList<>(); List<Effect> _buffList = new ArrayList<>(); for (Effect e : _effected.getEffectList().getAllEffects()) { if (_dispelType.equals("cancellation")) { if (!e.isOffensive() && !e.getSkill().isToggle() && e.isCancelable()) { if (e.getSkill().isMusic()) { _musicList.add(e); } else { _buffList.add(e); } } } else if (_dispelType.equals("bane")) { if (!e.isOffensive() && ArrayUtils.contains(_stackTypes, e.getStackType()) && e.isCancelable()) { _buffList.add(e); } } else if (_dispelType.equals("cleanse")) { if (e.isOffensive() && e.isCancelable()) { _buffList.add(e); } } } List<Effect> _effectList = new ArrayList<>(); Collections.reverse(_musicList); Collections.reverse(_buffList); _effectList.addAll(_musicList); _effectList.addAll(_buffList); if (_effectList.isEmpty()) { return; } double prelimChance, eml, dml, cancel_res_multiplier = _effected.calcStat(Stats.CANCEL_RESIST, 0, null, null); int buffTime, negated = 0; for (Effect e : _effectList) { if (negated < _negateCount) { eml = e.getSkill().getMagicLevel(); dml = getSkill().getMagicLevel() - (eml == 0 ? _effected.getLevel() : eml); buffTime = e.getTimeLeft(); cancel_res_multiplier = 1 - (cancel_res_multiplier * .01); prelimChance = ((2. * dml) + _cancelRate + (buffTime / 120)) * cancel_res_multiplier; if (Rnd.chance(calcSkillChanceLimits(prelimChance, _effector.isPlayable()))) { negated++; _effected.sendPacket(new SystemMessage2(SystemMsg.THE_EFFECT_OF_S1_HAS_BEEN_REMOVED) .addSkillName(e.getSkill().getId(), e.getSkill().getLevel())); e.exit(); } } } }
From source file:com.mirth.connect.client.ui.dependencies.ChannelDependenciesWarningDialog.java
private void initComponents(final ChannelTask task, Set<ChannelDependency> dependencies, final Set<String> selectedChannelIds, Set<String> additionalChannelIds) throws ChannelDependencyException { additionalChannelIds.removeAll(selectedChannelIds); final OrderedChannels orderedChannels = ChannelDependencyUtil.getOrderedChannels(dependencies, new HashSet<String>(CollectionUtils.union(selectedChannelIds, additionalChannelIds))); final List<Set<String>> orderedChannelIds = orderedChannels.getOrderedIds(); if (task.isForwardOrder()) { Collections.reverse(orderedChannelIds); }//from w w w . j a v a 2 s. c o m descriptionLabel = new JLabel( "<html>There are additional channels in the dependency chain.<br/><b>Bolded</b> channels will be " + task.getFuturePassive() + " in the following order:</html>"); channelsPane = new JTextPane(); channelsPane.setContentType("text/html"); HTMLEditorKit editorKit = new HTMLEditorKit(); StyleSheet styleSheet = editorKit.getStyleSheet(); styleSheet.addRule("div {font-family:\"Tahoma\";font-size:11;text-align:top}"); channelsPane.setEditorKit(editorKit); channelsPane.setEditable(false); channelsPane.setBackground(getBackground()); setTextPane(task, orderedChannels, orderedChannelIds, selectedChannelIds, false); descriptionScrollPane = new JScrollPane(channelsPane); includeCheckBox = new JCheckBox(WordUtils.capitalize(task.toString()) + " " + additionalChannelIds.size() + " additional channel" + (additionalChannelIds.size() == 1 ? "" : "s")); includeCheckBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { setTextPane(task, orderedChannels, orderedChannelIds, selectedChannelIds, includeCheckBox.isSelected()); } }); okButton = new JButton("OK"); okButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { result = JOptionPane.OK_OPTION; dispose(); } }); cancelButton = new JButton("Cancel"); cancelButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { result = JOptionPane.CANCEL_OPTION; dispose(); } }); }
From source file:com.uber.hoodie.cli.commands.CommitsCommand.java
@CliCommand(value = "commits show", help = "Show the commits") public String showCommits(@CliOption(key = { "limit" }, mandatory = false, help = "Limit commits", unspecifiedDefaultValue = "10") final Integer limit) throws IOException { HoodieActiveTimeline activeTimeline = HoodieCLI.tableMetadata.getActiveTimeline(); HoodieTimeline timeline = activeTimeline.getCommitsAndCompactionsTimeline().filterCompletedInstants(); List<HoodieInstant> commits = timeline.getInstants().collect(Collectors.toList()); String[][] rows = new String[commits.size()][]; Collections.reverse(commits); for (int i = 0; i < commits.size(); i++) { HoodieInstant commit = commits.get(i); HoodieCommitMetadata commitMetadata = HoodieCommitMetadata .fromBytes(timeline.getInstantDetails(commit).get()); rows[i] = new String[] { commit.getTimestamp(), NumericUtils.humanReadableByteCount(commitMetadata.fetchTotalBytesWritten()), String.valueOf(commitMetadata.fetchTotalFilesInsert()), String.valueOf(commitMetadata.fetchTotalFilesUpdated()), String.valueOf(commitMetadata.fetchTotalPartitionsWritten()), String.valueOf(commitMetadata.fetchTotalRecordsWritten()), String.valueOf(commitMetadata.fetchTotalUpdateRecordsWritten()), String.valueOf(commitMetadata.fetchTotalWriteErrors()) }; }/*w ww. j av a 2s.c om*/ return HoodiePrintHelper.print(new String[] { "CommitTime", "Total Written (B)", "Total Files Added", "Total Files Updated", "Total Partitions Written", "Total Records Written", "Total Update Records Written", "Total Errors" }, rows); }
From source file:it.cnr.icar.eric.client.ui.thin.OutputExceptions.java
/** * Find a string which should provide most information about a Throwable. * * @param t Throwable of interest/*from w ww . j a v a 2 s . com*/ * @param forLog If true, return more information; going into log * @return String message describing original cause for t */ private static String getCause(Throwable t, boolean forLog) { // Find all causes for this exception ArrayList<Throwable> causes = new ArrayList<Throwable>(); while (null != t) { causes.add(t); t = t.getCause(); } Collections.reverse(causes); // Work backwards through the causes to find the original // (hopefully most informative) detail string Iterator<Throwable> iter = causes.iterator(); String msg = null; while (iter.hasNext() && null == msg) { t = iter.next(); if (null != t.getMessage()) { // Detail string exists if (forLog) { // Always get class information as well msg = t.toString(); } else { msg = goodMessage(t); } } } // No detail found, use class information about root cause if (null == msg) { msg = (causes.get(0)).toString(); } return msg; }
From source file:com.betel.flowers.web.bean.RegistroExportacionBean.java
@PostConstruct public void init() { this.nuevo = new RegistroExportacion(); this.nuevo.setUsername("usertest");//usertest this.selected = new RegistroExportacion(); this.gerated = Boolean.TRUE; this.operarios = Boolean.TRUE; this.registrosExportacion = new ArrayList<>(); this.barcodeList = new ArrayList<>(); this.rendiminetoServiceList = new Rendimientos(); this.registrosExportacionG = this.registroExportacionService.obtenerLista(); if (this.registrosExportacionG == null) { this.registrosExportacionG = new ArrayList<>(); } else {/* w w w . j av a 2 s .com*/ Collections.reverse(this.registrosExportacionG); this.loadBarcodeList(); } }
From source file:gov.nih.nci.cagwas.web.test.CagwasActionTest.java
/** * Uses the caGWAS DTO to retrieve the list of available studies. These are * used in the tests to make sure every study is searched. *//*from ww w . j a v a 2s . c o m*/ private static void populateStudies() { studyIds = new ArrayList<Long>(); StudyCriteria studyCrit = new StudyCriteria(); try { FindingsManager manager = (FindingsManager) SpringContext.getBean("findingsManager"); SearchStudyHelper studyHelp = new SearchStudyHelper(); List<String> studyIdList = new ArrayList<String>(); studyIdList.add("1"); Collection<String> studyNames = studyHelp.retrieveStudyNames(studyIdList); ArrayList<LabelValueBean> studyVersionsList = new ArrayList<LabelValueBean>(); studyNamesList = new ArrayList<LabelValueBean>(); studyVersionMap = new HashMap<String, List<LabelValueBean>>(); for (String studyName : studyNames) { studyNamesList.add(new LabelValueBean(studyName, studyName)); Collection<Study> studies = studyHelp.retrieveStudies(studyName); for (Study s : studies) { studyVersionsList.add(new LabelValueBean(s.getVersion(), String.valueOf(s.getId()))); } Collections.sort(studyVersionsList); Collections.reverse(studyVersionsList); studyVersionMap.put(studyName, studyVersionsList); } studyObjs = manager.getStudies(studyCrit); if ((studyObjs != null) && (studyObjs.size() > 0)) { for (Study study : studyObjs) { studyIds.add(study.getId()); } } else assertTrue(false); } catch (Exception e) { e.printStackTrace(); assertTrue(false); } }
From source file:jav.correctionBackend.parser.WagnerFischer.java
private void backtrack() { for (int i = ocr.size(), j = gt.size(); i > 0 || j > 0;) { MinArg minArg = setTrace(i, j);//from ww w .j av a2s . co m i = minArg.i; j = minArg.j; } Collections.reverse(trace); }
From source file:com.github.jknack.handlebars.internal.Partial.java
@Override public void merge(final Context context, final Writer writer) throws IOException { TemplateLoader loader = handlebars.getLoader(); try {/* ww w. j av a 2s .c o m*/ LinkedList<TemplateSource> invocationStack = context.data(Context.INVOCATION_STACK); TemplateSource source = loader.sourceAt(path); if (exists(invocationStack, source.filename())) { TemplateSource caller = invocationStack.removeLast(); Collections.reverse(invocationStack); final String message; final String reason; if (invocationStack.isEmpty()) { reason = String.format("infinite loop detected, partial '%s' is calling itself", source.filename()); message = String.format("%s:%s:%s: %s", caller.filename(), line, column, reason); } else { reason = String.format("infinite loop detected, partial '%s' was previously loaded", source.filename()); message = String.format("%s:%s:%s: %s\n%s", caller.filename(), line, column, reason, "at " + join(invocationStack, "\nat ")); } HandlebarsError error = new HandlebarsError(caller.filename(), line, column, reason, text(), message); throw new HandlebarsException(error); } if (indent != null) { source = partial(source, indent); } Template template = handlebars.compile(source); if (this.context == null || this.context.equals("this")) { template.apply(context, writer); } else { template.apply(Context.newContext(context, context.get(this.context)), writer); } } catch (IOException ex) { String reason = String.format("The partial '%s' could not be found", loader.resolve(path)); String message = String.format("%s:%s:%s: %s", filename, line, column, reason); HandlebarsError error = new HandlebarsError(filename, line, column, reason, text(), message); throw new HandlebarsException(error); } }
From source file:net.doubledoordev.backend.server.FileManager.java
public Collection<File> makeBreadcrumbs() { LinkedList<File> list = new LinkedList<>(); File crumb = file;//w w w . j a v a2 s . c om while (!crumb.equals(serverFolder)) { list.add(crumb); crumb = crumb.getParentFile(); } list.add(serverFolder); Collections.reverse(list); return list; }