List of usage examples for java.util Comparator Comparator
Comparator
From source file:com.redsqirl.dynamictable.UnselectableTable.java
public void sort(final Integer index) { logger.info("Sort " + index); if (index == null || index < 0 || index >= columnIds.size()) { return;// w ww. j a v a 2 s. c o m } if (index.equals(indexOrdered)) { order *= -1; } else { indexOrdered = index; order = 1; } final Integer ord = order; Collections.sort(rows, new Comparator<Comparable[]>() { @SuppressWarnings("unchecked") @Override public int compare(Comparable[] o1, Comparable[] o2) { if (o1[index] == null) { return o2[index] == null ? 0 : -ord; } else if (o2[index] == null) { return ord; } return ord * o1[index].compareTo(o2[index]); } }); }
From source file:com.elogiclab.vosao.plugin.FlickrUtils.java
public static void signParams(List<NameValuePair> params, String apiSecret) { Collections.sort(params, new Comparator<NameValuePair>() { @Override//w w w . ja va 2s.c o m public int compare(NameValuePair t, NameValuePair t1) { return t.getName().compareTo(t1.getName()); } }); StringBuilder stringToEncode = new StringBuilder(); stringToEncode.append(apiSecret); for (NameValuePair nameValuePair : params) { stringToEncode.append(nameValuePair.getName()); stringToEncode.append(nameValuePair.getValue()); } System.out.println(stringToEncode); String stringEncoded = digest(stringToEncode.toString()); params.add(new BasicNameValuePair("api_sig", stringEncoded)); }
From source file:com.quartercode.classmod.extra.def.DefaultFunctionInvocation.java
/** * Creates a new default function invocation for the given {@link Function}. * The required data is taken from the given {@link Function} object. * This constructor also takes the available {@link FunctionExecutor}s and sorts them so they * // w w w. j a va 2s. co m * @param source The {@link Function} the default function invocation is used by. */ public DefaultFunctionInvocation(Function<R> source) { this.source = source; // Specify the list type for using this as a queue later on // We need a list here for sorting the executors LinkedList<FunctionExecutorContext<R>> executors = new LinkedList<FunctionExecutorContext<R>>(); for (FunctionExecutorContext<R> executor : source.getExecutors()) { if (isExecutorInvocable(executor)) { executors.add(executor); } } Collections.sort(executors, new Comparator<FunctionExecutorContext<R>>() { @Override public int compare(FunctionExecutorContext<R> o1, FunctionExecutorContext<R> o2) { return ((Integer) o2.getValue(Prioritized.class, "value")) .compareTo((Integer) o1.getValue(Prioritized.class, "value")); } }); remainingExecutors = executors; }
From source file:com.gu.management.logging.Log4JManagerServlet.java
private List<Logger> sortLoggers(Enumeration<Logger> currentLoggers) { List<Logger> loggers = new ArrayList<Logger>(); while (currentLoggers.hasMoreElements()) { loggers.add(currentLoggers.nextElement()); }/*from w w w .ja va2 s . c om*/ Collections.sort(loggers, new Comparator<Logger>() { @Override public int compare(Logger logger1, Logger logger2) { return logger1.getName().compareTo(logger2.getName()); } }); return loggers; }
From source file:io.servicecomb.foundation.common.utils.Log4jUtils.java
private static String genFileContext(List<Resource> resList, Properties properties) throws IOException { List<Entry<Object, Object>> entryList = properties.entrySet().stream() .sorted(new Comparator<Entry<Object, Object>>() { @Override//from ww w. j a va 2s. c o m public int compare(Entry<Object, Object> o1, Entry<Object, Object> o2) { return o1.getKey().toString().compareTo(o2.getKey().toString()); } }).collect(Collectors.toList()); StringBuilder sb = new StringBuilder(); for (Resource res : resList) { sb.append("#").append(res.getURL().getPath()).append("\n"); } for (Entry<Object, Object> entry : entryList) { sb.append(entry.getKey()).append("=").append(entry.getValue()).append("\n"); } return sb.toString(); }
From source file:ca.ualberta.cs.expenseclaim.dao.ExpenseClaimDao.java
private void save(Context context) { Collections.sort(claimList, new Comparator<ExpenseClaim>() { @Override/*from w w w .j a v a2 s . c o m*/ public int compare(ExpenseClaim lhs, ExpenseClaim rhs) { return lhs.getStartDate().compareTo(rhs.getStartDate()); } }); File file = new File(context.getFilesDir(), FILENAME); PrintWriter writer = null; try { writer = new PrintWriter(file); for (ExpenseClaim c : claimList) { JSONObject jo = new JSONObject(); jo.put("id", c.getId()); jo.put("name", c.getName()); jo.put("description", c.getDescription()); jo.put("startDate", c.getStartDate().getTime()); jo.put("endDate", c.getEndDate().getTime()); jo.put("status", c.getStatus()); writer.println(jo.toString()); } } catch (Exception e) { e.printStackTrace(); } finally { if (writer != null) { writer.close(); } } }
From source file:io.gameover.utilities.pixeleditor.Frame.java
public List<Pair<Integer, Integer>> extractColors() { Map<Integer, Integer> m = new HashMap<>(); for (int i = 0; i < argb.length; i++) { for (int j = 0; j < argb[0].length; j++) { int c = argb[i][j]; if (!m.containsKey(c)) { m.put(c, 1);//from www . j a v a 2 s .c o m } else { m.put(c, m.get(c) + 1); } } } List<Pair<Integer, Integer>> ret = new ArrayList<>(); for (Integer k : m.keySet()) { ret.add(Pair.of(k, m.get(k))); } Collections.sort(ret, new Comparator<Pair<Integer, Integer>>() { @Override public int compare(Pair<Integer, Integer> o1, Pair<Integer, Integer> o2) { return o2.getValue() - o1.getValue(); } }); return ret; }
From source file:Service.MessageServiceImpl.java
/** * Rcupre les messages envoys par une personne l'utilisateur * * @param idUser l'id de l'utilisateur//from w w w.ja v a 2 s . c o m * @param idPersonne l'id de la personne qui a envoy les messages * @return un string des messages formats */ @Override public String getMessagesSinglePersonne(int idUser, int idPersonne) { List<MessagesEntity> messages = messagesDAO.findByPersonne(idPersonne, idUser); Collections.sort(messages, new Comparator<MessagesEntity>() { @Override public int compare(MessagesEntity o1, MessagesEntity o2) { return o2.getDate().compareTo(o1.getDate()); } }); Collections.reverse(messages); String message = ""; for (MessagesEntity me : messages) { SimpleDateFormat messageDate = new SimpleDateFormat("dd,MM,yyyy 'a' HH:mm:ss "); String date; date = messageDate.format(me.getDate()); message += "<div class=\"message col-lg-offset-1 col-lg-10 col-lg-offset-1\">"; // Conteneur du statut message += "<div class=\"row rowMessage\">"; message += "<div class=\"message\">"; message += me.getEmetteur().getPrenom() + " " + me.getEmetteur().getNom(); message += "</div>"; message += "</div>"; message += "<div class=\"row rowMessage messageText\">"; message += "<div class=\"message\">"; // Conteneur du texte du statut message += me.getTexte(); message += "</div>"; message += "</div>"; message += "<div class=\"row rowMessage\">"; message += "<div class=\"date\">Envoy le " + date + "</div>"; message += "</div>"; message += "</div>"; } return message; }
From source file:edu.kit.dama.ui.repo.components.ShareObjectComponent.java
/** * Setup the component by obtaining all users from the database and place * them in the list according to their current share status regarding * pObject./*from w w w. j a v a 2 s . c om*/ * * @param pObject The object for which the sharing information should be * changed. */ public final void setup(DigitalObject pObject) { object = pObject; shareList.removeAllItems(); IMetaDataManager mdm = MetaDataManagement.getMetaDataManagement().getMetaDataManager(); mdm.setAuthorizationContext(AuthorizationContext.factorySystemContext()); List<UserId> authorizedUsers = new LinkedList<>(); try { //obtain all users List<UserData> users = mdm.find(UserData.class); //sort alphabetically by user names Collections.sort(users, new Comparator<UserData>() { @Override public int compare(UserData o1, UserData o2) { return o1.getFullname().compareToIgnoreCase(o2.getFullname()); } }); //add all users to the left side for (UserData user : users) { shareList.addItem(user.getDistinguishedName()); shareList.setItemCaption(user.getDistinguishedName(), user.getFullname() + " (" + user.getEmail() + ")"); } //obtain a list of all users authorized to access the object authorizedUsers = ResourceServiceLocal.getSingleton().getAuthorizedUsers( pObject.getSecurableResourceId(), Role.MEMBER, AuthorizationContext.factorySystemContext()); } catch (EntityNotFoundException | UnauthorizedAccessAttemptException ex) { LOGGER.error("Failed to setup sharing component for object with resource id " + object.getSecurableResourceId(), ex); } finally { mdm.close(); } //transform the list of authorized users into a set for setting the selection value Set<String> select = new TreeSet<>(); for (UserId userId : authorizedUsers) { select.add(userId.getStringRepresentation()); } //select all authorized users to be located in the "shared with" part of the list shareList.setValue(select); }