Java Collections.sort Examples

Java Collections.sort - 30 examples found. These are the top rated real world Java examples of java.util.Collections.sort extracted from open source projects. You can rate examples to help us improve the quality of examples.
  /**
   * Refresh the local cache of Flags by loading all enabled Flags from the database Also refresh
   * the privilege cache Note that flags and tags must be eagerly loaded for this to work
   */
  private void refreshCache() {
    // get the enabled flags and all tags for the flag and tag caches
    flagCache = dao.getAllEnabledFlags();
    tagCache = getAllTags();

    // alphabetize the flags, and sort by by priority ranking so that result sets are returned that
    // way
    Collections.sort(flagCache, new FlagAlphaComparator());
    Collections.sort(flagCache, new FlagPriorityComparator());

    // get the privileges associate with the patient flags default user for the privileges cache
    try {
      Context.addProxyPrivilege("View Users");
      String username =
          Context.getAdministrationService().getGlobalProperty("patientflags.username");
      User user = Context.getUserService().getUserByUsername(username);

      if (user != null) {
        if (user.isSuperUser()) { // need to explicitly get all privileges if user is a super user
          privilegeCache = Context.getUserService().getAllPrivileges();
        } else {
          privilegeCache = user.getPrivileges();
        }
      } else {
        privilegeCache = null;
      }
    } finally {
      Context.removeProxyPrivilege("View Users");
    }

    // set the initialized flag to true
    isInitialized = true;
  }
 private List<SchemaTransaction> generateTableTransactions(
     Database sourceDatabase, Database shadowDatabase) {
   List<SchemaTransaction> schemaTransactionList = new ArrayList<SchemaTransaction>();
   if (shadowDatabase == null) {
     for (Table table : sourceDatabase.getTableList()) {
       schemaTransactionList.add(new SchemaTransaction(table, TransactionType.INSERT));
       schemaTransactionList.addAll(generateColumnTransactions(table, null));
     }
   } else {
     Collections.sort(sourceDatabase.getTableList());
     Collections.sort(shadowDatabase.getTableList());
     for (Table table : sourceDatabase.getTableList()) {
       if (!shadowDatabase.getTableList().contains(table)) {
         table.setDatabase(shadowDatabase);
         schemaTransactionList.add(new SchemaTransaction(table, TransactionType.INSERT));
         schemaTransactionList.addAll(generateColumnTransactions(table, null));
       } else {
         Table shadowTable =
             shadowDatabase.getTableList().get(shadowDatabase.getTableList().indexOf(table));
         if (!table.getPk().equals(shadowTable.getPk())) {
           table.setId(shadowTable.getId());
           schemaTransactionList.add(new SchemaTransaction(table, TransactionType.UPDATE));
         }
         schemaTransactionList.addAll(generateColumnTransactions(table, shadowTable));
       }
     }
     for (Table table : shadowDatabase.getTableList()) {
       if (!sourceDatabase.getTableList().contains(table)) {
         schemaTransactionList.add(new SchemaTransaction(table, TransactionType.DELETE));
       }
     }
   }
   return schemaTransactionList;
 }
Example #3
0
  /**
   * Given a new LimitOrder, it will replace and old matching limit order in the orderbook or simply
   * get added. Finally, it is sorted.
   *
   * @param limitOrder
   */
  public void update(LimitOrder limitOrder) {

    if (limitOrder.getType().equals(OrderType.ASK)) {

      Iterator<LimitOrder> it = asks.iterator();
      while (it.hasNext()) {
        LimitOrder order = it.next();
        if (order.getLimitPrice().compareTo(limitOrder.getLimitPrice())
            == 0) { // they are equal. found it!
          it.remove();
          break;
        }
      }
      asks.add(limitOrder); // just add it
      Collections.sort(asks); // finally sort

    } else {

      Iterator<LimitOrder> it = bids.iterator();
      while (it.hasNext()) {
        LimitOrder order = it.next();
        if (order.getLimitPrice().compareTo(limitOrder.getLimitPrice())
            == 0) { // they are equal. found it!
          it.remove();
          break;
        }
      }
      bids.add(limitOrder); // just add it
      Collections.sort(bids); // finally sort
    }
  }
  private static void checkResult(
      String[] fileNames,
      final ArrayList<PsiFile> filesList,
      int[] starts,
      final IntArrayList startsList,
      int[] ends,
      final IntArrayList endsList) {
    List<SearchResult> expected = new ArrayList<SearchResult>();
    for (int i = 0; i < fileNames.length; i++) {
      String fileName = fileNames[i];
      expected.add(
          new SearchResult(
              fileName, i < starts.length ? starts[i] : -1, i < ends.length ? ends[i] : -1));
    }

    List<SearchResult> actual = new ArrayList<SearchResult>();
    for (int i = 0; i < filesList.size(); i++) {
      PsiFile psiFile = filesList.get(i);
      actual.add(
          new SearchResult(
              psiFile.getName(),
              i < starts.length ? startsList.get(i) : -1,
              i < ends.length ? endsList.get(i) : -1));
    }

    Collections.sort(expected);
    Collections.sort(actual);

    assertEquals("Usages don't match", expected, actual);
  }
Example #5
0
  /**
   * Prints the genetics of this Brain to a String.
   *
   * @return a String representation of the underlying neural network
   */
  public String toString() {
    // TODO: Make this and DNA use Braincraft.listToString()
    // First line
    String output = "genomestart " + ID + "\n";

    // Node list
    ArrayList<NNode> nodes = new ArrayList<NNode>();
    nodes.addAll(nodemap.values());
    Collections.sort(nodes);
    output += Braincraft.listToString(nodes);

    // Gene list
    Set<Gene> genes = new HashSet<Gene>();
    for (ArrayList<Gene> arl : connections.values()) {
      for (Gene g : arl) {
        genes.add(g);
      }
    }
    ArrayList<Gene> allgenes = new ArrayList<Gene>();
    allgenes.addAll(genes);
    Collections.sort(allgenes);
    output += Braincraft.listToString(allgenes);

    // Last line
    output += "genomeend" + "\n";

    return output;
  }
  private void initParams() {
    WebElement dateSlot = getDriver().findElement(By.className("v-datecellslot"));
    int dateSlotWidth = dateSlot.getSize().getWidth();
    noOverlapWidth = dateSlotWidth;
    oneOverlapWidth = dateSlotWidth / 2;
    twoOverlapsWidth = dateSlotWidth / 3;

    Comparator<WebElement> startTimeComparator =
        new Comparator<WebElement>() {
          @Override
          public int compare(WebElement e1, WebElement e2) {
            int e1Top = e1.getLocation().getY();
            int e2Top = e2.getLocation().getY();
            return e1Top - e2Top;
          }
        };

    List<WebElement> eventElements =
        getDriver().findElements(By.className("v-calendar-event-content"));
    Collections.sort(eventElements, startTimeComparator);
    firstEvent = eventElements.get(0);
    secondEvent = eventElements.get(1);
    thirdEvent = eventElements.get(2);

    List<WebElement> resizeBottomElements =
        getDriver().findElements(By.className("v-calendar-event-resizebottom"));
    Collections.sort(resizeBottomElements, startTimeComparator);
    firstEventBottomResize = resizeBottomElements.get(0);
    secondEventBottomResize = resizeBottomElements.get(1);
    thirdEventBottomResize = resizeBottomElements.get(2);
  }