List of usage examples for java.util Collections reverseOrder
@SuppressWarnings("unchecked") public static <T> Comparator<T> reverseOrder(Comparator<T> cmp)
From source file:org.alfresco.integrations.google.docs.service.GoogleDocsServiceImpl.java
public boolean hasConcurrentEditors(NodeRef nodeRef) throws GoogleDocsAuthenticationException, GoogleDocsRefreshTokenException, GoogleDocsServiceException { log.debug(//from w ww .ja v a2 s .c o m "Check for Concurrent Editors (Edits that have occured in the last " + idleThreshold + " seconds)"); DriveOperations driveOperations = getDriveOperations(getConnection()); String resourceID = nodeService.getProperty(nodeRef, GoogleDocsModel.PROP_RESOURCE_ID).toString(); boolean concurrentChange = false; try { List<FileRevision> fileRevisionList = driveOperations .getRevisions(resourceID.substring(resourceID.lastIndexOf(':') + 1)); if (fileRevisionList.size() > 1) { log.debug("Revisions Found"); Collections.sort(fileRevisionList, Collections.reverseOrder(new FileRevisionComparator())); // Find any revisions occurring within the last 'idleThreshold' // seconds List<FileRevision> workingList = new ArrayList<FileRevision>(); Calendar bufferTime = Calendar.getInstance(); bufferTime.add(Calendar.SECOND, -idleThreshold); for (FileRevision entry : fileRevisionList) { if (entry.getModifiedDate().after(new Date(bufferTime.getTimeInMillis()))) { workingList.add(entry); } else { // once we past 'idleThreshold' seconds get out of here break; } } // If there any revisions that occurred within the last // 'idleThreshold' seconds of time.... if (workingList.size() > 0) { log.debug("Revisions within threshhold found"); // Filter the current user from the list for (int i = workingList.size() - 1; i >= 0; i--) { FileRevision fileRevision = workingList.get(i); String name = getGoogleUserProfile().getName(); // if there is no author -- the entry is the initial // creation if (fileRevision.getLastModifyingUserName() != null) { if (fileRevision.getLastModifyingUserName().equals(name)) { workingList.remove(i); } } else { workingList.remove(i); } } } // Are there are changes by other users within the last // 'idleThreshold' seconds if (workingList.size() > 0) { log.debug("Revisions not made by current user found."); concurrentChange = true; } } else { String name = getGoogleUserProfile().getName(); // if the authors list is empty -- the author was the original // creator and it is the initial copy if (fileRevisionList.get(0).getLastModifyingUserName() != null) { if (!fileRevisionList.get(0).getLastModifyingUserName().equals(name)) { Calendar bufferTime = Calendar.getInstance(); bufferTime.add(Calendar.SECOND, -idleThreshold); if (fileRevisionList.get(0).getModifiedDate() .before(new Date(bufferTime.getTimeInMillis()))) { log.debug("Revisions not made by current user found."); concurrentChange = true; } } } } } catch (HttpStatusCodeException hsce) { throw new GoogleDocsServiceException(hsce.getMessage(), hsce.getStatusCode().value()); } log.debug("Concurrent Edits: " + concurrentChange); return concurrentChange; }
From source file:com.tesora.dve.tools.aitemplatebuilder.AiTemplateBuilder.java
/** * Handles collocation special cases.//from w ww .jav a 2 s .c o m * * 1. A table is being referenced on a single column group. * * a) The table is referenced by two or more unique column groups from a * single table. * The solution which preserves collocation is to make the * table and all the tables it points at Broadcast. * * b) The table has unique foreign and target column groups. In other words, * the table is being pointed at and points on two or more unique column * groups. * The only solution is making the pointed tables * and all their descendants Broadcast. * * 2. A table is being referenced on two or more unique column groups. The * only solution in this case is making the table and all the tables it * points at Broadcast. * * * NOTE: Basic one-to-one collocation cases: * * a) Range -> Broadcast: always collocated * b) Range -> Range: collocated only if in the same range. * c) Broadcast -> Range: make the referenced table Broadcast (a), or * colocate the two tables on the same range (b). * * NOTE: Same rules hold for self-referencing relationships (table with a * foreign key into itself). */ private void resolveForeignCollocationConflicts(final Collection<TableStats> tables, final boolean isRowWidthWeightingEnabled) throws PEException { log("Resolving FK collocation..."); /* * Make sure there are no Broadcast -> Range relationships (c) by making * both tables Range or Broadcast if cannot range (user defined). */ for (final TableStats table : tables) { if (table.getTableDistributionModel() instanceof Range) { for (final TableStats childTable : table.getReferencingForeignTables()) { if (childTable.getTableDistributionModel() instanceof Broadcast) { if (!childTable.hasDistributionModelFreezed()) { final Set<TableStats> affectedTables = makeBackwardTableTreeRange(childTable); log("FK forced range: range table '" + table.getFullTableName() + "' is referenced by a broadcast table '" + childTable.getFullTableName() + "'. Had to range '" + affectedTables.size() + "' table(s).", MessageSeverity.ALERT); } else { final Set<TableStats> forcedBroadcastTables = makeForwardTableTreeBroadcast(childTable); log("FK forced broadcast: Could not range table '" + childTable.getFullTableName() + "' (user defined). Had to broadcast '" + forcedBroadcastTables.size() + "' table(s) with total size of '" + CorpusStats.computeTotalSizeKb(forcedBroadcastTables) + "KB'", MessageSeverity.WARNING); forcedBroadcastTables.addAll(forcedBroadcastTables); } } } } } /* * Now, we should have only Range -> Broadcast (a) and Range -> Range * (b) relationships. */ final SortedSet<TableStats> forcedBroadcastTables = new TreeSet<TableStats>( Collections.reverseOrder(new TableSizeComparator(isRowWidthWeightingEnabled))); /* Resolve the special cases. */ for (final TableStats table : tables) { /* * Here we handle only the Range -> Range (b) case. * Range -> Broadcast (a) is always collocated and we never change * the parent table's model to anything other than Broadcast. */ if (!table.hasDistributionModelFreezed() && (table.getTableDistributionModel() instanceof Range)) { final Set<Set<TableColumn>> uniqueTargetColumnGroups = table.getUniqueTargetColumnGroups(); if (uniqueTargetColumnGroups.size() == 1) { // Case (1) /* Case (1a) */ final Set<ForeignRelationship> backwardRelationships = table.getBackwardRelationships(); for (@SuppressWarnings("unused") final Set<TableColumn> targetColumnGroup : uniqueTargetColumnGroups) { final Set<TableStats> visitedReferencingTables = new HashSet<TableStats>(); for (final ForeignRelationship relationship : backwardRelationships) { final TableStats targetTable = relationship.getRHS(); if (!visitedReferencingTables.add(targetTable)) { final Set<TableStats> affectedTables = makeForwardTableTreeBroadcast(table); log("FK forced broadcast: table '" + table.getFullTableName() + "' referenced by '" + targetTable.getFullTableName() + "' on two or more unique column groups. Had to broadcast '" + affectedTables.size() + "' table(s) with total size of '" + CorpusStats.computeTotalSizeKb(affectedTables) + "KB'", MessageSeverity.WARNING); forcedBroadcastTables.addAll(affectedTables); break; } } } if (!(table.getTableDistributionModel() instanceof Range)) { continue; // The case already resolved from above. } /* Case (1b) */ final Set<ForeignRelationship> forwardRelationships = table.getForwardRelationships(); final Set<TableStats> affectedTables = new LinkedHashSet<TableStats>(); for (final Set<TableColumn> targetColumnGroup : uniqueTargetColumnGroups) { for (final ForeignRelationship relationship : forwardRelationships) { if (!targetColumnGroup.equals(relationship.getForeignColumns())) { final TableStats targetTable = relationship.getRHS(); affectedTables.addAll(makeForwardTableTreeBroadcast(targetTable)); } } } if (!affectedTables.isEmpty()) { log("FK forced broadcast: table '" + table.getFullTableName() + "' has unique foreign and target column groups. Had to broadcast '" + affectedTables.size() + "' table(s) with total size of '" + CorpusStats.computeTotalSizeKb(affectedTables) + "KB'", MessageSeverity.WARNING); forcedBroadcastTables.addAll(affectedTables); } } else if (uniqueTargetColumnGroups.size() > 1) { // Case (2) final Set<TableStats> affectedTables = makeForwardTableTreeBroadcast(table); log("FK forced broadcast: table '" + table.getFullTableName() + "' referenced on two or more unique column groups. Had to broadcast '" + affectedTables.size() + "' table(s) with total size of '" + CorpusStats.computeTotalSizeKb(affectedTables) + "KB'", MessageSeverity.WARNING); forcedBroadcastTables.addAll(affectedTables); } } } /* Print out broadcasted tables. */ log("The following tables were forced broadcast:", MessageSeverity.WARNING); for (final TableStats table : forcedBroadcastTables) { log(table.toString(), MessageSeverity.WARNING, 1); } }
From source file:com.google.bitcoin.core.Wallet.java
/** * Returns an list of N transactions, ordered by increasing age. Transactions on side chains are not included. * Dead transactions (overridden by double spends) are optionally included. <p> * <p/>/*from w w w . j ava 2 s . com*/ * Note: the current implementation is O(num transactions in wallet). Regardless of how many transactions are * requested, the cost is always the same. In future, requesting smaller numbers of transactions may be faster * depending on how the wallet is implemented (eg if backed by a database). */ public List<Transaction> getRecentTransactions(int numTransactions, boolean includeDead) { lock.lock(); try { checkArgument(numTransactions >= 0); // Firstly, put all transactions into an array. int size = getPoolSize(Pool.UNSPENT) + getPoolSize(Pool.SPENT) + getPoolSize(Pool.PENDING); if (numTransactions > size || numTransactions == 0) { numTransactions = size; } ArrayList<Transaction> all = new ArrayList<Transaction>(getTransactions(includeDead)); // Order by date. Collections.sort(all, Collections.reverseOrder(new Comparator<Transaction>() { public int compare(Transaction t1, Transaction t2) { return t1.getUpdateTime().compareTo(t2.getUpdateTime()); } })); if (numTransactions == all.size()) { return all; } else { all.subList(numTransactions, all.size()).clear(); return all; } } finally { lock.unlock(); } }
From source file:net.sourceforge.fenixedu.presentationTier.Action.phd.academicAdminOffice.PhdIndividualProgramProcessDA.java
public ActionForward viewAllAlertMessages(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {/*from w w w . j a v a 2 s .co m*/ PhdIndividualProgramProcess process = getProcess(request); TreeSet<PhdAlertMessage> orderedMessages = new TreeSet<PhdAlertMessage>( Collections.reverseOrder(PhdAlertMessage.COMPARATOR_BY_WHEN_CREATED_AND_ID)); orderedMessages.addAll(process.getAlertMessagesSet()); request.setAttribute("alertMessages", orderedMessages); return mapping.findForward("viewAllAlertMessages"); }
From source file:net.sourceforge.fenixedu.domain.student.Student.java
public PersonalIngressionData getLatestPersonalIngressionData() { TreeSet<PersonalIngressionData> personalInformations = new TreeSet<PersonalIngressionData>( Collections.reverseOrder(PersonalIngressionData.COMPARATOR_BY_EXECUTION_YEAR)); ExecutionYear currentExecutionYear = ExecutionYear.readCurrentExecutionYear(); for (PersonalIngressionData pid : getPersonalIngressionsDataSet()) { if (!pid.getExecutionYear().isAfter(currentExecutionYear)) { personalInformations.add(pid); }// w w w . j av a 2 s . co m } if (personalInformations.isEmpty()) { return null; } return personalInformations.iterator().next(); }
From source file:net.sourceforge.fenixedu.domain.student.Registration.java
public PrecedentDegreeInformation getLatestPrecedentDegreeInformation() { TreeSet<PrecedentDegreeInformation> degreeInformations = new TreeSet<PrecedentDegreeInformation>( Collections.reverseOrder(PrecedentDegreeInformation.COMPARATOR_BY_EXECUTION_YEAR)); ExecutionYear currentExecutionYear = ExecutionYear.readCurrentExecutionYear(); for (PrecedentDegreeInformation pdi : getPrecedentDegreesInformationsSet()) { if (!pdi.getExecutionYear().isAfter(currentExecutionYear)) { degreeInformations.add(pdi); }/*from www . j a va2 s . com*/ } if (degreeInformations.isEmpty()) { return null; } return degreeInformations.iterator().next(); }
From source file:org.fsl.roms.service.action.RoadCheckServiceAction.java
private List<CitationOffenceBO> sortCitationOffence(List<CitationOffenceBO> citationOffenceBOs) { Collections.sort(citationOffenceBOs, Collections.reverseOrder(new Comparator<CitationOffenceBO>() { public int compare(CitationOffenceBO result1, CitationOffenceBO result2) { return result1.getOffenceDateTime().compareTo(result2.getOffenceDateTime()); }/*ww w .j a va 2 s . c o m*/ })); return citationOffenceBOs; }
From source file:org.fsl.roms.service.action.RoadCheckServiceAction.java
private List<TrafficTicket> sortTrafficTicketOffence(List<TrafficTicket> trafficTickets) { Collections.sort(trafficTickets, Collections.reverseOrder(new Comparator<TrafficTicket>() { public int compare(TrafficTicket result1, TrafficTicket result2) { return result1.getIssueDate().compareTo(result2.getIssueDate()); }/*from w ww .j av a 2s . com*/ })); return trafficTickets; }