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:de.thischwa.pmcms.view.context.object.Utils.java
/** * Reverse the order of a {@link Collection}. It's null-save. If the desired {@link Collection} is null or empty, * an empty one will returned.//from www. jav a2 s. c om * @param <T> * @param col The collection to reverse. Could be null or empty. * * @return An empty collection if the desired one was empty or null, or the desired collection with the reversed order. */ public static <T> Collection<T> reverseCollection(Collection<T> col) { if (CollectionUtils.isEmpty(col)) return new ArrayList<T>(); ArrayList<T> arrayList = new ArrayList<T>(col); Collections.reverse(arrayList); return arrayList; }
From source file:biomine.bmvis2.crawling.Databases.java
public static Collection<String> getDatabases() { if (dbs != null) return dbs; try {// ww w . j a v a2 s . c o m String url = WebConstants.BIOMINE_URL + "stats/index.cgi?json_action=getdbs"; String cont = URLUtils.getURLContents(new URL(url)); Object arr = JSONValue.parse(cont); if (arr instanceof JSONArray) { JSONArray jarr = (JSONArray) arr; dbs = new ArrayList(); for (Object dbo : jarr) { JSONObject jdb = (JSONObject) dbo; Object no = jdb.get("name"); if (no != null) dbs.add(no.toString()); } Collections.reverse(dbs); return dbs; } } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ClassCastException e) { // TODO: handle exception } return Collections.EMPTY_LIST; }
From source file:com.tilab.ca.sse.core.util.SSEUtils.java
public static Map sortIntegersMap(Map passedMap) { LOG.debug("[sortHashMapIntegers] - BEGIN"); List mapKeys = new ArrayList(passedMap.keySet()); List mapValues = new ArrayList(passedMap.values()); Collections.sort(mapValues);/*w w w. j ava 2 s . co m*/ Collections.reverse(mapValues); Collections.sort(mapKeys); Map sortedMap = new LinkedHashMap(); Iterator valueIt = mapValues.iterator(); while (valueIt.hasNext()) { Object val = valueIt.next(); Iterator keyIt = mapKeys.iterator(); while (keyIt.hasNext()) { Object key = keyIt.next(); String comp1 = passedMap.get(key).toString(); String comp2 = val.toString(); if (comp1.equals(comp2)) { passedMap.remove(key); mapKeys.remove(key); sortedMap.put((Integer) key, (Integer) val); break; } } } LOG.debug("[sortHashMapIntegers] - END"); return sortedMap; }
From source file:net.fabricmc.installer.util.MavenHandler.java
public static void load(String mavenServerURL, String packageName, String jarName) throws IOException, ParserConfigurationException, SAXException, XmlPullParserException { String baseMavenMeta = IOUtils.toString(new URL( mavenServerURL + "/" + packageName.replace('.', '/') + "/" + jarName + "/maven-metadata.xml"), "UTF-8"); Metadata metadata = new MetadataXpp3Reader().read(new StringReader(baseMavenMeta)); latestVersion = metadata.getVersioning().getRelease(); versions = metadata.getVersioning().getVersions(); Collections.reverse(versions); }
From source file:com.opengamma.analytics.financial.schedule.WeeklyScheduleCalculator.java
public LocalDate[] getSchedule(final LocalDate startDate, final LocalDate endDate, final boolean fromEnd) { Validate.notNull(startDate, "start date"); Validate.notNull(endDate, "end date"); Validate.isTrue(startDate.isBefore(endDate) || startDate.equals(endDate)); final List<LocalDate> dates = new ArrayList<LocalDate>(); if (fromEnd) { LocalDate date = endDate; while (!date.isBefore(startDate)) { dates.add(date);/*from w w w . ja v a 2 s.c o m*/ date = date.minusDays(7); } Collections.reverse(dates); return dates.toArray(EMPTY_LOCAL_DATE_ARRAY); } LocalDate date = startDate; while (!date.isAfter(endDate)) { dates.add(date); date = date.plusDays(7); } return dates.toArray(EMPTY_LOCAL_DATE_ARRAY); }
From source file:com.opengamma.analytics.financial.schedule.AnnualScheduleCalculator.java
@Override public LocalDate[] getSchedule(final LocalDate startDate, final LocalDate endDate, final boolean fromEnd, final boolean generateRecursive) { Validate.notNull(startDate, "start date"); Validate.notNull(endDate, "end date"); Validate.isTrue(startDate.isBefore(endDate) || startDate.equals(endDate)); if (startDate.equals(endDate)) { return new LocalDate[] { startDate }; }/* www . j a v a2 s . c o m*/ final List<LocalDate> dates = new ArrayList<LocalDate>(); if (fromEnd) { LocalDate date = endDate; int i = 1; while (!date.isBefore(startDate)) { dates.add(date); date = generateRecursive ? date.minus(Period.ofYears(1)) : endDate.minus(Period.ofYears(i++)); } Collections.reverse(dates); return dates.toArray(EMPTY_LOCAL_DATE_ARRAY); } LocalDate date = startDate; int i = 1; while (!date.isAfter(endDate)) { dates.add(date); date = generateRecursive ? date.plus(Period.ofYears(1)) : startDate.plus(Period.ofYears(i++)); } return dates.toArray(EMPTY_LOCAL_DATE_ARRAY); }
From source file:com.opengamma.analytics.financial.schedule.EndOfMonthAnnualScheduleCalculator.java
public LocalDate[] getSchedule(final LocalDate startDate, final LocalDate endDate, final boolean fromEnd) { Validate.notNull(startDate, "start date"); Validate.notNull(endDate, "end date"); final LocalDate[] monthly = EOM_CALCULATOR.getSchedule(startDate, endDate); final List<LocalDate> result = new ArrayList<LocalDate>(); if (fromEnd) { for (int i = monthly.length - 1; i >= 0; i -= 12) { result.add(monthly[i]);//from w w w . j a v a2 s . c o m } Collections.reverse(result); return result.toArray(EMPTY_LOCAL_DATE_ARRAY); } for (int i = 0; i < monthly.length; i += 12) { result.add(monthly[i]); } return result.toArray(EMPTY_LOCAL_DATE_ARRAY); }
From source file:com.opengamma.analytics.financial.schedule.MonthlyScheduleCalculator.java
@Override public LocalDate[] getSchedule(final LocalDate startDate, final LocalDate endDate, final boolean fromEnd, final boolean generateRecursive) { Validate.notNull(startDate, "start date"); Validate.notNull(endDate, "end date"); Validate.isTrue(startDate.isBefore(endDate) || startDate.equals(endDate)); if (startDate.equals(endDate)) { return new LocalDate[] { startDate }; }//from w ww .j ava 2 s. c o m final List<LocalDate> dates = new ArrayList<LocalDate>(); if (fromEnd) { LocalDate date = endDate; int i = 1; while (!date.isBefore(startDate)) { dates.add(date); date = generateRecursive ? date.minus(Period.ofMonths(1)) : endDate.minus(Period.ofMonths(i++)); } Collections.reverse(dates); return dates.toArray(EMPTY_LOCAL_DATE_ARRAY); } LocalDate date = startDate; int i = 1; while (!date.isAfter(endDate)) { dates.add(date); date = generateRecursive ? date.plus(Period.ofMonths(1)) : startDate.plus(Period.ofMonths(i++)); } return dates.toArray(EMPTY_LOCAL_DATE_ARRAY); }
From source file:com.opengamma.analytics.financial.schedule.EndOfMonthQuarterlyScheduleCalculator.java
public LocalDate[] getSchedule(final LocalDate startDate, final LocalDate endDate, final boolean fromEnd) { Validate.notNull(startDate, "start date"); Validate.notNull(endDate, "end date"); final LocalDate[] monthly = EOM_CALCULATOR.getSchedule(startDate, endDate); final List<LocalDate> result = new ArrayList<LocalDate>(); if (fromEnd) { for (int i = monthly.length - 1; i >= 0; i -= 3) { result.add(monthly[i]);/*w ww.java2 s . co m*/ } Collections.reverse(result); return result.toArray(EMPTY_LOCAL_DATE_ARRAY); } for (int i = 0; i < monthly.length; i += 3) { result.add(monthly[i]); } return result.toArray(EMPTY_LOCAL_DATE_ARRAY); }
From source file:com.opengamma.analytics.financial.schedule.EndOfMonthSemiAnnualScheduleCalculator.java
public LocalDate[] getSchedule(final LocalDate startDate, final LocalDate endDate, final boolean fromEnd) { Validate.notNull(startDate, "start date"); Validate.notNull(endDate, "end date"); final LocalDate[] monthly = EOM_CALCULATOR.getSchedule(startDate, endDate); final List<LocalDate> result = new ArrayList<LocalDate>(); if (fromEnd) { for (int i = monthly.length - 1; i >= 0; i -= 6) { result.add(monthly[i]);/* ww w . j av a 2s. co m*/ } Collections.reverse(result); return result.toArray(EMPTY_LOCAL_DATE_ARRAY); } for (int i = 0; i < monthly.length; i += 6) { result.add(monthly[i]); } return result.toArray(EMPTY_LOCAL_DATE_ARRAY); }