Java Collections.reverse Examples

Java Collections.reverse - 30 examples found. These are the top rated real world Java examples of java.util.Collections.reverse extracted from open source projects. You can rate examples to help us improve the quality of examples.
Example #1
0
  /**
   * This function expects to receive a list ordered by number (Ascending) and version (Descending)
   *
   * @param guides
   * @return The latest version for the guides
   */
  private List getLatestVersions(List guides) {
    List result = new ArrayList();
    Integer numberAux = null;

    Collections.reverse(guides);

    Iterator iterator = guides.iterator();
    while (iterator.hasNext()) {
      Guide guide = (Guide) iterator.next();

      if ((numberAux == null) || (numberAux.intValue() != guide.getNumber().intValue())) {
        numberAux = guide.getNumber();
        InfoGuide infoGuide =
            InfoGuideWithPersonAndExecutionDegreeAndContributor.newInfoFromDomain(guide);

        List infoReimbursementGuides = new ArrayList();
        if (guide.getReimbursementGuides() != null) {
          Iterator iter = guide.getReimbursementGuides().iterator();
          while (iter.hasNext()) {
            ReimbursementGuide reimbursementGuide = (ReimbursementGuide) iter.next();
            InfoReimbursementGuide infoReimbursementGuide =
                InfoReimbursementGuide.newInfoFromDomain(reimbursementGuide);
            infoReimbursementGuides.add(infoReimbursementGuide);
          }
        }
        infoGuide.setInfoReimbursementGuides(infoReimbursementGuides);
        result.add(infoGuide);
      }
    }
    Collections.reverse(result);
    return result;
  }
Example #2
0
  /**
   * Reduces segment list to the smallest number of segments by joining connected segments. Empty
   * segments are removed.
   *
   * <p>Iff segment reversal is allowed, segments are joined even if they are connected head-to-head
   * or tail-to-tail. In such a case, we first reverse the vertices of one of the segments so that
   * they are joined head-to-tail, then append as usual.
   *
   * <p>Allowing segment reversal sacrifices any hope of use a segment's winding direction to infer
   * which side its interior is on, but helps with data in which winding direction is meaningless to
   * begin with.
   */
  private static void joinConnectedSegments(
      List<List<LandVertex>> segments, boolean allowSegmentReversal) {
    int joinlessLoopsRemaining = segments.size();
    while (joinlessLoopsRemaining > 0) {
      List<LandVertex> base = segments.remove(0);
      if (base.isEmpty()) {
        joinlessLoopsRemaining--;
        continue;
      }

      boolean anyJoins = false;
      for (Iterator<List<LandVertex>> i = segments.iterator(); i.hasNext(); ) {
        List<LandVertex> extension = i.next();

        if (extension.get(0).equals(base.get(base.size() - 1))) {
          base.addAll(extension);
          i.remove();
          anyJoins = true;
        } else if (allowSegmentReversal
            && extension.get(extension.size() - 1).equals(base.get(base.size() - 1))) {
          Collections.reverse(extension);
          base.addAll(extension);
          i.remove();
          anyJoins = true;
        } else if (allowSegmentReversal && extension.get(0).equals(base.get(0))) {
          Collections.reverse(base);
          base.addAll(extension);
          i.remove();
          anyJoins = true;
        }
      }
      segments.add(base);
      joinlessLoopsRemaining = (anyJoins ? segments.size() : joinlessLoopsRemaining - 1);
    }
  }
 /**
  * Returns the normalized form of the URI, using the given multiple candidates (this means that
  * more than 2 modules had a matching name).
  *
  * @param uri The URI that is to be normalized.
  * @param candidateURIs URIs of the modules that can potentially be a match for <code>uri</code>.
  * @return the normalized form
  */
 private URI findBestMatchFor(URI uri, Set<URI> candidateURIs) {
   URI normalized = null;
   final Iterator<URI> candidatesIterator = candidateURIs.iterator();
   final List<String> referenceSegments = Arrays.asList(uri.segments());
   Collections.reverse(referenceSegments);
   int highestEqualFragments = 0;
   while (candidatesIterator.hasNext()) {
     final URI next = candidatesIterator.next();
     int equalFragments = 0;
     final List<String> candidateSegments = Arrays.asList(next.segments());
     Collections.reverse(candidateSegments);
     for (int i = 0; i < Math.min(candidateSegments.size(), referenceSegments.size()); i++) {
       if (candidateSegments.get(i) == referenceSegments.get(i)) {
         equalFragments++;
       } else {
         break;
       }
     }
     if (equalFragments > highestEqualFragments) {
       highestEqualFragments = equalFragments;
       normalized = next;
     }
   }
   return normalized;
 }
  private synchronized void sort(PyObject cmp, PyObject key, boolean reverse) {
    gListAllocatedStatus = -1;

    int size = list.size();
    final ArrayList<KV> decorated = new ArrayList<KV>(size);
    for (PyObject value : list) {
      decorated.add(new KV(key.__call__(value), value));
    }
    list.clear();
    KVComparator c = new KVComparator(this, cmp);
    if (reverse) {
      Collections.reverse(decorated); // maintain stability of sort by reversing first
    }
    Collections.sort(decorated, c);
    if (reverse) {
      Collections.reverse(decorated);
    }
    if (list instanceof ArrayList) {
      ((ArrayList) list).ensureCapacity(size);
    }
    for (KV kv : decorated) {
      list.add(kv.value);
    }
    gListAllocatedStatus = __len__();
  }
Example #5
0
 private String mergePathLists(List<String> basePathSteps, List<String> filePathSteps) {
   Collections.reverse(basePathSteps);
   Collections.reverse(filePathSteps);
   List<String> result = new ArrayList<String>(basePathSteps);
   int i = 0;
   while (i < filePathSteps.size() && filePathSteps.get(i).equals("..")) {
     result.remove(result.size() - 1);
     i++;
   }
   for (int j = i; j < filePathSteps.size(); j++) {
     result.add(filePathSteps.get(j));
   }
   StringBuilder resultPath = new StringBuilder();
   for (int k = 0; k < result.size(); k++) {
     resultPath.append(result.get(k));
     if (k != result.size() - 1) {
       resultPath.append(File.separator);
     }
   }
   String resultString = resultPath.toString();
   if (!resultString.startsWith(SEPARATOR)) {
     resultString = SEPARATOR + resultString;
   }
   return resultString;
 }
Example #6
0
  public synchronized void initOrderList(@NotNull JSONArray orderArray) {

    synchronized (OrderListLock) {
      finishedOrderList = new ArrayList<OrderData>();
      unfinishedOrderList = new ArrayList<OrderData>();

      for (int i = 0; i < orderArray.length(); i++) {
        OrderData orderData = null;
        try {
          orderData = new OrderData(orderArray.getJSONObject(i));

          if (orderData.getStatus() == 0
              || orderData.getStatus() == 1
              || orderData.getStatus() == 2
              || orderData.getStatus() == 5) continue;

          if (orderData.getTradedVolume() > 0) {
            finishedOrderList.add(orderData);
          }
          if (orderData.getTradedVolume() < orderData.getOriginVolume()) {
            unfinishedOrderList.add(orderData);
          }

        } catch (JSONException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      }

      Collections.reverse(finishedOrderList);
      Collections.reverse(unfinishedOrderList);
    }
  }