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:com.opengamma.analytics.financial.schedule.QuarterlyScheduleCalculator.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 w w . j a v a 2s. c o m*/ final List<LocalDate> dates = new ArrayList<LocalDate>(); if (fromEnd) { LocalDate date = endDate; int i = 3; while (!date.isBefore(startDate)) { dates.add(date); date = generateRecursive ? date.minus(Period.ofMonths(3)) : endDate.minus(Period.ofMonths(i)); i += 3; } Collections.reverse(dates); return dates.toArray(EMPTY_LOCAL_DATE_ARRAY); } LocalDate date = startDate; int i = 3; while (!date.isAfter(endDate)) { dates.add(date); date = generateRecursive ? date.plus(Period.ofMonths(3)) : startDate.plus(Period.ofMonths(i)); i += 3; } return dates.toArray(EMPTY_LOCAL_DATE_ARRAY); }
From source file:com.opengamma.analytics.financial.schedule.SemiAnnualScheduleCalculator.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 w w. j a v a2s . c o m*/ final List<LocalDate> dates = new ArrayList<LocalDate>(); if (fromEnd) { LocalDate date = endDate; int i = 6; while (!date.isBefore(startDate)) { dates.add(date); date = generateRecursive ? date.minus(Period.ofMonths(6)) : endDate.minus(Period.ofMonths(i)); i += 6; } Collections.reverse(dates); return dates.toArray(EMPTY_LOCAL_DATE_ARRAY); } LocalDate date = startDate; int i = 6; while (!date.isAfter(endDate)) { dates.add(date); date = generateRecursive ? date.plus(Period.ofMonths(6)) : startDate.plus(Period.ofMonths(i)); i += 6; } return dates.toArray(EMPTY_LOCAL_DATE_ARRAY); }
From source file:org.javelin.sws.ext.utils.NamespaceUtils.java
/** * Converts package name to URL for namespace according to JAXB/JAX-WS conventions with separate domain and path fragments * // w ww . j a v a 2 s.c o m * @param pkg * @param domainComponentCount number of package components to be converted into domain part of URL. If zero than entire package will be a domain * @return */ public static String packageNameToNamespace(Package pkg, int domainComponentCount) { Assert.notNull(pkg, "Package should not be null"); Assert.isTrue(domainComponentCount != 1, "The domain part should not consist of one component. It may be zero or more than 1."); List<String> elements = new ArrayList<String>(Arrays.asList(pkg.getName().split("\\."))); if (domainComponentCount > 0) { List<String> domain = elements.subList(0, domainComponentCount); List<String> path = elements.subList(domainComponentCount, elements.size()); Collections.reverse(domain); return "http://" + StringUtils.collectionToDelimitedString(domain, ".") + "/" + StringUtils.collectionToDelimitedString(path, "/"); } else { Collections.reverse(elements); return "http://" + StringUtils.collectionToDelimitedString(elements, ".") + "/"; } }
From source file:com.opengamma.web.analytics.blotter.BeanTraverser.java
BeanTraverser(BeanVisitorDecorator... decorators) { _decorators = Arrays.asList(decorators); // first decorator in the list should be on the outside, need to reverse before wrapping Collections.reverse(_decorators); }
From source file:com.byteowls.jopencage.model.JOpenCageResponse.java
public void orderResultByConfidence() { Collections.sort(this.results); Collections.reverse(this.results); }
From source file:de.fhg.iais.asc.sipmaker.SipMakerKey.java
public static SipMakerKey fromTrunk(String metadataFormat, List<String> subFormats) { if (StringUtils.isEmpty(metadataFormat)) { throw new IllegalArgumentException("Metadata format may not be empty"); }//w w w. ja v a 2s . c o m String current = metadataFormat; List<String> result = new ArrayList<String>(); result.add(current); for (String dir : subFormats) { if (!StringUtils.isEmpty(dir)) { current = current.concat(File.separator).concat(dir); result.add(current); } } Collections.reverse(result); result = Collections.unmodifiableList(result); return new SipMakerKey(result, ""); }
From source file:info.magnolia.vaadin.periscope.result.SupplierUtil.java
/** * Highlight (using HTML tags) all occurrences of a query string, ignoring case. * * @param text Text in which parts should be highlighted * @param query Parts to highlight/*from w w w.ja va 2 s .co m*/ * @return Highlighted string */ public static String highlight(final String text, final String query) { if (StringUtils.isBlank(query)) { return text; } final List<Integer> startIndices = allIndicesOf(text, query); final List<Integer> endIndices = startIndices.stream().map(i -> i + query.length()).collect(toList()); // we run back to front to not mess up indices when inserting tags Collections.reverse(startIndices); Collections.reverse(endIndices); Queue<Integer> startQueue = new LinkedList<>(startIndices); Queue<Integer> endQueue = new LinkedList<>(endIndices); StringBuilder highlighted = new StringBuilder(text); while (!startQueue.isEmpty() || !endQueue.isEmpty()) { final Integer startCandidate = startQueue.peek(); final Integer endCandidate = endQueue.peek(); if (startCandidate != null && (endCandidate == null || startCandidate > endCandidate)) { highlighted.insert(startCandidate, "<strong>"); startQueue.poll(); } else { highlighted.insert(endCandidate, "</strong>"); endQueue.poll(); } } return highlighted.toString(); }
From source file:com.sec.ose.osi.util.tools.Tools.java
public static ArrayList<String> sortByValue(final HashMap<String, Integer> map) { ArrayList<String> key = new ArrayList<String>(); key.addAll(map.keySet());/* w w w . j a v a 2 s . com*/ Collections.sort(key, new Comparator<Object>() { public int compare(Object o1, Object o2) { Integer v1 = map.get(o1); Integer v2 = map.get(o2); return v1.compareTo(v2); } }); Collections.reverse(key); return key; }
From source file:com.app.controller.SearchResultController.java
@RequestMapping(value = "/search_query_results", method = RequestMethod.GET, produces = "application/json") public @ResponseBody List<SearchResult> getSearchQueryResults(int searchQueryId) throws DatabaseConnectionException, SQLException { List<SearchResult> searchResults = SearchResultUtil.getSearchQueryResults(searchQueryId); Collections.reverse(searchResults); return searchResults; }
From source file:com.haulmont.cuba.desktop.DesktopResources.java
public DesktopResources(List<String> roots, Resources resources) { this.resources = resources; this.roots = new ArrayList<>(roots); Collections.reverse(this.roots); }