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:cz.muni.fi.mir.db.service.impl.ApplicationRunServiceImpl.java
@Override @Transactional(readOnly = true)//from w w w .j av a 2 s . c om public List<ApplicationRun> getAllApplicationRunsFromRange(int start, int end, boolean reversed) { if (reversed) { List<ApplicationRun> result = applicationRunDAO.getAllApplicationRunsFromRange(start, end); Collections.reverse(result); return result; } else { return applicationRunDAO.getAllApplicationRunsFromRange(start, end); } }
From source file:com.charts.SixMonthChart.java
protected OHLCDataItem[] getData(YStockQuote currentStock) throws ParseException { ArrayList<OHLCDataItem> dataItems = new ArrayList<OHLCDataItem>(); DateFormat df;//from w w w. j av a 2 s .co m if (currentStock instanceof Index) df = new SimpleDateFormat("y-MM-dd"); else df = new SimpleDateFormat("d-MM-yy"); String sixMonthDate = df.format(DayRange.six_month); ArrayList<String> historicalData = currentStock.get_historical_data(); int length = historicalData.size(); for (int i = 1; i < length; i++) { String[] data = historicalData.get(i).split(","); Date date = df.parse(data[0]); double open = Double.parseDouble(data[1]); double high = Double.parseDouble(data[2]); double low = Double.parseDouble(data[3]); double close = Double.parseDouble(data[4]); this.close.add(new Day(date), close); double volume; try { volume = Double.parseDouble(data[5]); } catch (NumberFormatException nfe) { volume = 0; } if (data[0].equals(sixMonthDate)) { break; } OHLCDataItem item = new OHLCDataItem(date, open, high, low, close, volume); dataItems.add(item); } Collections.reverse(dataItems); OHLCDataItem[] OHLCData = dataItems.toArray(new OHLCDataItem[dataItems.size()]); return OHLCData; }
From source file:com.bigdata.dastor.thrift.server.DastorThriftServer.java
public List<ColumnOrSuperColumn> thriftifyColumns(Collection<IColumn> columns, boolean reverseOrder) { ArrayList<ColumnOrSuperColumn> thriftColumns = new ArrayList<ColumnOrSuperColumn>(columns.size()); for (IColumn column : columns) { if (column.isMarkedForDelete()) { continue; }//ww w .jav a 2 s . c om Column thrift_column = new Column(column.name(), column.value(), column.timestamp()); thriftColumns.add(createColumnOrSuperColumn_Column(thrift_column)); } // we have to do the reversing here, since internally we pass results around in ColumnFamily // objects, which always sort their columns in the "natural" order // TODO this is inconvenient for direct users of StorageProxy if (reverseOrder) Collections.reverse(thriftColumns); return thriftColumns; }
From source file:com.charts.OneMonthChart.java
protected OHLCDataItem[] getData(YStockQuote currentStock) throws ParseException { ArrayList<OHLCDataItem> dataItems = new ArrayList<OHLCDataItem>(); DateFormat df;/*from w w w . j av a 2s . co m*/ if (currentStock instanceof Index) df = new SimpleDateFormat("y-MM-dd"); else df = new SimpleDateFormat("d-MM-yy"); String oneMonthDate = df.format(DayRange.one_month); ArrayList<String> historicalData = currentStock.get_historical_data(); int length = historicalData.size(); for (int i = 1; i < length; i++) { String[] data = historicalData.get(i).split(","); Date date = df.parse(data[0]); double open = Double.parseDouble(data[1]); double high = Double.parseDouble(data[2]); double low = Double.parseDouble(data[3]); double close = Double.parseDouble(data[4]); this.close.addOrUpdate(new Day(date), close); double volume; try { volume = Double.parseDouble(data[5]); } catch (NumberFormatException nfe) { volume = 0; } if (data[0].equals(oneMonthDate)) { break; } OHLCDataItem item = new OHLCDataItem(date, open, high, low, close, volume); dataItems.add(item); } Collections.reverse(dataItems); OHLCDataItem[] OHLCData = dataItems.toArray(new OHLCDataItem[dataItems.size()]); return OHLCData; }
From source file:ar.com.fdvs.dj.core.layout.ClassicLayoutManager.java
/** * *///from w ww. j av a 2 s. c o m protected void applyHeaderAutotexts() { if (getReport().getAutoTexts() == null) return; /** * Apply the autotext in footer if any */ JRDesignBand headerband = (JRDesignBand) getDesign().getPageHeader(); if (headerband == null) { headerband = new JRDesignBand(); getDesign().setPageHeader(headerband); } ArrayList positions = new ArrayList(); positions.add(HorizontalBandAlignment.LEFT); positions.add(HorizontalBandAlignment.CENTER); positions.add(HorizontalBandAlignment.RIGHT); ArrayList autotexts = new ArrayList(getReport().getAutoTexts()); Collections.reverse(autotexts); int totalYoffset = findTotalOffset(positions, autotexts, AutoText.POSITION_HEADER); LayoutUtils.moveBandsElemnts(totalYoffset, headerband); for (Iterator iterator = positions.iterator(); iterator.hasNext();) { HorizontalBandAlignment currentAlignment = (HorizontalBandAlignment) iterator.next(); int yOffset = 0; for (Iterator iter = getReport().getAutoTexts().iterator(); iter.hasNext();) { AutoText text = (AutoText) iter.next(); if (text.getPosition() == AutoText.POSITION_HEADER && text.getAlignment().equals(currentAlignment)) { CommonExpressionsHelper.add(yOffset, (DynamicJasperDesign) getDesign(), this, headerband, text); yOffset += text.getHeight().intValue(); } } } /** END */ }
From source file:jp.ikedam.jenkins.plugins.extensible_choice_parameter.FilenameChoiceListProvider.java
/** * List files from passed parameters./* ww w. j a v a 2 s .c o m*/ * * @param baseDir * @param includePattern * @param excludePattern * @param scanType * @param reverseOrder * @return */ protected static List<String> getFileList(File baseDir, String includePattern, String excludePattern, ScanType scanType, boolean reverseOrder) { if (baseDir == null || !baseDir.exists() || !baseDir.isDirectory()) { return new ArrayList<String>(0); } if (StringUtils.isBlank(includePattern)) { return new ArrayList<String>(0); } if (scanType == null) { scanType = ScanType.File; } DirectoryScanner ds = new DirectoryScanner(); ds.setBasedir(baseDir); ds.setIncludes(includePattern.split("\\s*,(?:\\s*,)*\\s*")); if (!StringUtils.isBlank(excludePattern)) { ds.setExcludes(excludePattern.split("\\s*,(?:\\s*,)*\\s*")); } ds.scan(); List<String> ret = null; switch (scanType) { case FileAndDirectory: { ret = new ArrayList<String>(ds.getIncludedDirsCount() + ds.getIncludedFilesCount()); for (String file : ds.getIncludedFiles()) { ret.add(file); } for (String dir : ds.getIncludedDirectories()) { ret.add(dir); } Collections.sort(ret); break; } case Directory: { ret = Arrays.asList(ds.getIncludedDirectories()); break; } default: { // case File: ret = Arrays.asList(ds.getIncludedFiles()); break; } } if (reverseOrder) { try { Collections.reverse(ret); } catch (UnsupportedOperationException _) { // ret is immutable. ret = new ArrayList<String>(ret); Collections.reverse(ret); } } return ret; }
From source file:edu.depaul.armada.dao.ContainerLogDaoHibernate.java
/** * Returns a List<Metric> from all of the containers with a specified ID, within a * a particular amount of time, and with an average of a specified field. * @param containerId long//www . j av a2 s .c om * @param periodCount int * @param fieldToAverage String * @return List<Metric> */ @Override public List<Metric> findWithContainerIdAndPeriod(long containerId, int periodCount, String fieldToAverage) { List<Metric> metrics = new ArrayList<Metric>(periodCount); Calendar cal = Calendar.getInstance(); for (int i = 0; i < periodCount; i++) { Date end = cal.getTime(); int hour = cal.get(Calendar.HOUR_OF_DAY); cal.add(Calendar.HOUR_OF_DAY, -1); Date start = cal.getTime(); Criteria criteria = newCriteria(); criteria.createAlias("container", "container"); criteria.add(Restrictions.eq("container.id", containerId)); criteria.add(Restrictions.le("timestamp", end)); criteria.add(Restrictions.gt("timestamp", start)); // we don't want overlap here criteria.setProjection(Projections.avg(fieldToAverage)); Object result = criteria.uniqueResult(); int count = (result == null) ? 0 : ((Double) result).intValue(); Metric temp = new Metric(); temp.setHour(hour); temp.setValue(count); metrics.add(temp); } Collections.reverse(metrics); // we want the current time to be the last hour return metrics; }
From source file:org.dspace.services.sessions.SessionRequestServiceImpl.java
/** * List this session's interceptors./*www. j av a 2 s . com*/ * * @param reverse return the list in reverse order? * @return the current list of interceptors in the correct order */ private List<RequestInterceptor> getInterceptors(boolean reverse) { ArrayList<RequestInterceptor> l = new ArrayList<RequestInterceptor>(this.interceptorsMap.values()); OrderedServiceComparator comparator = new OrderedServiceComparator(); Collections.sort(l, comparator); if (reverse) { Collections.reverse(l); } return l; }
From source file:com.liato.bankdroid.banking.banks.Statoil.java
@Override public void update() throws BankException, LoginException { super.update(); if (username == null || password == null || username.length() == 0 || password.length() == 0) { throw new LoginException(res.getText(R.string.invalid_username_password).toString()); }/*from ww w .ja v a2 s . co m*/ urlopen = login(); Matcher matcher; try { if (!"https://applications.sebkort.com/nis/stse/main.do".equals(urlopen.getCurrentURI())) { response = urlopen.open("https://applications.sebkort.com/nis/stse/main.do"); } matcher = reAccounts.matcher(response); /* * Capture groups: * GROUP EXAMPLE DATA * 1: amount 10 579,43 * */ if (matcher.find()) { Account account = new Account("Kpgrns", Helpers.parseBalance(matcher.group(1)), "3"); account.setType(Account.OTHER); accounts.add(account); } if (matcher.find()) { Account account = new Account("Saldo", Helpers.parseBalance(matcher.group(1)), "2"); account.setType(Account.OTHER); accounts.add(account); } if (matcher.find()) { Account account = new Account("Disponibelt belopp", Helpers.parseBalance(matcher.group(1)), "1"); account.setType(Account.CCARD); accounts.add(account); balance = balance.add(Helpers.parseBalance(matcher.group(1))); } Collections.reverse(accounts); if (accounts.isEmpty()) { throw new BankException(res.getText(R.string.no_accounts_found).toString()); } } catch (ClientProtocolException e) { throw new BankException(e.getMessage()); } catch (IOException e) { throw new BankException(e.getMessage()); } finally { super.updateComplete(); } }
From source file:net.sourceforge.fenixedu.presentationTier.Action.commons.ChooseExecutionYearDispatchAction.java
private List transformIntoLabels(List executionYearList) { List executionYearsLabels = new ArrayList(); CollectionUtils.collect(executionYearList, new Transformer() { @Override//from www . ja v a 2 s. c o m public Object transform(Object input) { InfoExecutionDegree infoExecutionDegree = (InfoExecutionDegree) input; LabelValueBean labelValueBean = new LabelValueBean( infoExecutionDegree.getInfoExecutionYear().getYear(), infoExecutionDegree.getExternalId().toString()); return labelValueBean; } }, executionYearsLabels); Collections.sort(executionYearsLabels, new BeanComparator("label")); Collections.reverse(executionYearsLabels); return executionYearsLabels; }