List of usage examples for java.util Collections reverseOrder
@SuppressWarnings("unchecked") public static <T> Comparator<T> reverseOrder()
From source file:org.wso2.carbon.repository.core.jdbc.dao.JDBCResourceVersionDAO.java
public Long[] getSnapshotIDs(String resourcePath) throws RepositoryException { JDBCDatabaseTransaction.ManagedRegistryConnection conn = JDBCDatabaseTransaction.getConnection(); ResultSet results = null;/*from www . j a v a 2 s . co m*/ PreparedStatement ps = null; try { ResourceIDImpl resourceIdImpl = resourceDAO.getResourceID(resourcePath); if (resourceIdImpl == null) { return new Long[0]; } if (resourceIdImpl.isCollection()) { String sql = "SELECT REG_SNAPSHOT_ID FROM REG_SNAPSHOT WHERE " + "REG_PATH_ID=? AND REG_RESOURCE_NAME IS NULL AND REG_TENANT_ID=?"; ps = conn.prepareStatement(sql); ps.setInt(1, resourceIdImpl.getPathID()); ps.setInt(2, CurrentContext.getTenantId()); } else { String sql = "SELECT REG_SNAPSHOT_ID FROM REG_SNAPSHOT WHERE " + "REG_PATH_ID=? AND REG_RESOURCE_NAME=? AND REG_TENANT_ID=?"; ps = conn.prepareStatement(sql); ps.setInt(1, resourceIdImpl.getPathID()); ps.setString(2, resourceIdImpl.getName()); ps.setInt(3, CurrentContext.getTenantId()); } results = ps.executeQuery(); List<Long> snapshotIDs = new ArrayList<Long>(); while (results.next()) { long snapshotNumber = results.getLong(DatabaseConstants.SNAPSHOT_ID_FIELD); snapshotIDs.add(snapshotNumber); } Collections.sort(snapshotIDs, Collections.reverseOrder()); return snapshotIDs.toArray(new Long[snapshotIDs.size()]); } catch (SQLException e) { String msg = "Failed to get snapshot numbers of resource " + resourcePath + ". " + e.getMessage(); log.error(msg, e); throw new RepositoryDBException(msg, e); } finally { try { try { if (results != null) { results.close(); } } finally { if (ps != null) { ps.close(); } } } catch (SQLException ex) { String msg = InternalConstants.RESULT_SET_PREPARED_STATEMENT_CLOSE_ERROR; log.error(msg, ex); } } }
From source file:org.gitools.analysis.clustering.hierarchical.HierarchicalClusterer.java
private Color nameClusters(List<HierarchicalCluster> children, int level) { if (children.isEmpty()) { return next(); }/*from w w w . ja va2s .c om*/ int digits = calculateDigits(children.size()); Collections.sort(children, Collections.reverseOrder()); Color colorParent = null; Double weightParent = 0.0; for (int i = 0; i < children.size(); i++) { HierarchicalCluster child = children.get(i); if (child.getChildren().isEmpty()) { child.setName(JOINER.join(child.getIdentifiers())); } else { child.setName(child.getParentName() + createLabel(i, digits)); } Color colorChild = nameClusters(child.getChildren(), level + 1); child.setColor(colorChild.getRGB()); if (colorParent == null) { colorParent = colorChild; weightParent = (child.getChildren().isEmpty() ? 0.0 : child.getWeight()); } else { colorParent = mixColors(colorParent, weightParent, colorChild, child.getWeight()); weightParent += (child.getChildren().isEmpty() ? 0.0 : child.getWeight()); } } if (level > 10) { return next(); } return colorParent; }
From source file:com.microsoft.gittf.core.tasks.CreateCommitForPendingSetsTask.java
@Override public TaskStatus run(final TaskProgressMonitor progressMonitor) { progressMonitor.beginTask(getProgressMonitorMessage(), 1, TaskProgressDisplay.DISPLAY_SUBTASK_DETAIL); ObjectInserter repositoryInserter = null; TreeWalk treeWalker = null;/*from w ww .j a v a2 s. c om*/ RevWalk walk = null; try { validateTempDirectory(); Item rootServerItem = versionControlService.getItem(serverPath, LatestVersionSpec.INSTANCE, DeletedState.NON_DELETED, GetItemsOptions.NONE); String serverPathToUse = rootServerItem.getServerItem(); Set<String> pendingSetItemPath = new TreeSet<String>(); Map<String, PendingChange> pendingSetMap = new HashMap<String, PendingChange>(); PendingSet[] pendingSets = getPendingSets(); /* * keep track of the items added, renamed and folders renamed for * special handling later */ Set<String> itemsAddedInPendingSet = new TreeSet<String>(); Set<String> itemsRenamedInPendingSet = new TreeSet<String>(); Set<String> itemsDeletedInPendingSet = new TreeSet<String>(); Set<String> foldersRenamedInPendingSet = new TreeSet<String>(Collections.reverseOrder()); Set<String> foldersDeletedInPendingSet = new TreeSet<String>(); progressMonitor.displayVerbose( Messages.getString("CreateCommitForPendingSetsTask.VerboseItemsProcessedFromPendingSets")); //$NON-NLS-1$ for (PendingSet set : pendingSets) { for (PendingChange change : set.getPendingChanges()) { String serverItem = change.getServerItem(); String sourceServerItem = change.getSourceServerItem() != null ? change.getSourceServerItem() : null; String pathToUse = serverItem; ChangeType changeType = change.getChangeType(); if (change.getItemType() == ItemType.FILE) { if (changeType.contains(ChangeType.ADD) || changeType.contains(ChangeType.BRANCH) || changeType.contains(ChangeType.UNDELETE)) { itemsAddedInPendingSet.add(serverItem); } else if (changeType.contains(ChangeType.RENAME)) { itemsRenamedInPendingSet.add(sourceServerItem); pathToUse = sourceServerItem; } else if (changeType.contains(ChangeType.DELETE)) { itemsDeletedInPendingSet.add(serverItem); } else { /* * in case there is a source server item use that. * This will be true in the case of a file edit and * its parent has been renamed */ if (change.getSourceServerItem() != null) { pathToUse = sourceServerItem; } } } else if (change.getItemType() == ItemType.FOLDER) { if (changeType.contains(ChangeType.RENAME)) { foldersRenamedInPendingSet.add(sourceServerItem); pathToUse = sourceServerItem; } else if (changeType.contains(ChangeType.DELETE)) { foldersDeletedInPendingSet.add(serverItem); } } progressMonitor.displayVerbose(pathToUse); pendingSetItemPath.add(pathToUse); pendingSetMap.put(pathToUse, change); } } progressMonitor.displayVerbose(""); //$NON-NLS-1$ progressMonitor.setWork(pendingSetItemPath.size()); repositoryInserter = repository.newObjectInserter(); treeWalker = new NameConflictTreeWalk(repository); walk = new RevWalk(repository); ObjectId baseCommitId = parentCommitID; if (baseCommitId == null) { ChangesetCommitMap commitMap = new ChangesetCommitMap(repository); baseCommitId = commitMap.getCommitID(commitMap.getLastBridgedChangesetID(true), false); } RevCommit parentCommit = walk.parseCommit(baseCommitId); if (parentCommit == null) { throw new Exception( Messages.getString("CreateCommitForPendingSetsTask.LatestDownloadedChangesetNotFound")); //$NON-NLS-1$ } RevTree baseCommitTree = parentCommit.getTree(); /* * We want trees sorted by children first so we can simply walk them * (child-first) to build the hierarchy once we've finished * inserting blobs. */ final Map<CommitTreePath, Map<CommitTreePath, CommitTreeEntry>> baseTreeHeirarchy = new TreeMap<CommitTreePath, Map<CommitTreePath, CommitTreeEntry>>( new CommitTreePathComparator()); final Map<CommitTreePath, Map<CommitTreePath, CommitTreeEntry>> pendingSetTreeHeirarchy = new TreeMap<CommitTreePath, Map<CommitTreePath, CommitTreeEntry>>( new CommitTreePathComparator()); treeWalker.setRecursive(true); treeWalker.addTree(baseCommitTree); /* * Phase one: build the pending set commit tree by copying the * parent tree */ progressMonitor.displayVerbose( Messages.getString("CreateCommitForPendingSetsTask.VerboseItemsDownloadedFromPendingSets")); //$NON-NLS-1$ while (treeWalker.next()) { String itemServerPath = ServerPath.combine(serverPathToUse, treeWalker.getPathString()); /* if the item has a pending change apply the pending change */ if (pendingSetItemPath.contains(itemServerPath)) { progressMonitor.displayVerbose(itemServerPath); if (createStashCommit) { createBlob(repositoryInserter, baseTreeHeirarchy, pendingSetMap.get(itemServerPath), true, progressMonitor); } if (!itemsDeletedInPendingSet.contains(itemServerPath) && !itemsRenamedInPendingSet.contains(itemServerPath)) { createBlob(repositoryInserter, pendingSetTreeHeirarchy, pendingSetMap.get(itemServerPath), false, progressMonitor); } progressMonitor.worked(1); } /* if the item parent is renamed handle this case */ else if (isParentInCollection(foldersRenamedInPendingSet, itemServerPath)) { if (createStashCommit) { createBlob(repositoryInserter, baseTreeHeirarchy, itemServerPath, treeWalker.getObjectId(0), treeWalker.getFileMode(0), progressMonitor); } String destinationServerItem = updateServerItemWithParentRename(foldersRenamedInPendingSet, itemServerPath, pendingSetMap); if (ServerPath.isChild(serverPathToUse, destinationServerItem)) { createBlob(repositoryInserter, pendingSetTreeHeirarchy, destinationServerItem, treeWalker.getObjectId(0), treeWalker.getFileMode(0), progressMonitor); } } /* * add all other items to the tree unless their parent was * deleted */ else { if (createStashCommit) { createBlob(repositoryInserter, baseTreeHeirarchy, itemServerPath, treeWalker.getObjectId(0), treeWalker.getFileMode(0), progressMonitor); } if (!isParentInCollection(foldersDeletedInPendingSet, itemServerPath)) { createBlob(repositoryInserter, pendingSetTreeHeirarchy, itemServerPath, treeWalker.getObjectId(0), treeWalker.getFileMode(0), progressMonitor); } } } progressMonitor.displayVerbose(""); //$NON-NLS-1$ /* for items that were added in the shelveset add those here */ progressMonitor.displayVerbose( Messages.getString("CreateCommitForPendingSetsTask.VerboseItemsDownloadedFromPendingSetsAdds")); //$NON-NLS-1$ for (String newItem : itemsAddedInPendingSet) { if (!ServerPath.isChild(serverPathToUse, newItem)) { // Ignore files that are added that are not mapped in the // repository continue; } progressMonitor.displayVerbose(newItem); createBlob(repositoryInserter, pendingSetTreeHeirarchy, pendingSetMap.get(newItem), false, progressMonitor); progressMonitor.worked(1); } for (String renamedItem : itemsRenamedInPendingSet) { PendingChange change = pendingSetMap.get(renamedItem); if (!ServerPath.isChild(serverPathToUse, change.getServerItem())) { // Ignore files that are renamed to server items that are // outside the repository continue; } progressMonitor.displayVerbose(renamedItem); createBlob(repositoryInserter, pendingSetTreeHeirarchy, change, false, progressMonitor); progressMonitor.worked(1); } progressMonitor.displayVerbose(""); //$NON-NLS-1$ /* Phase two: add child trees to their parents. */ progressMonitor.setDetail(Messages.getString("CreateCommitTask.CreatingTrees")); //$NON-NLS-1$ ObjectId rootBaseTree = createStashCommit ? createTrees(repositoryInserter, baseTreeHeirarchy) : null; ObjectId rootPendingSetTree = createTrees(repositoryInserter, pendingSetTreeHeirarchy); /* Phase three: create the commit. */ progressMonitor.setDetail(Messages.getString("CreateCommitTask.CreatingCommit")); //$NON-NLS-1$ if (createStashCommit) { this.commitId = StashUtil.create(repository, repositoryInserter, rootBaseTree, rootPendingSetTree, rootBaseTree, parentCommitID, getOwnerDisplayName(), getOwner(), getComment(), getName()); } else { this.commitId = createCommit(repositoryInserter, rootPendingSetTree, parentCommitID); } progressMonitor.endTask(); return TaskStatus.OK_STATUS; } catch (Exception e) { log.error(e); return new TaskStatus(TaskStatus.ERROR, e); } finally { FileHelpers.deleteDirectory(tempDir); if (repositoryInserter != null) { repositoryInserter.release(); } if (treeWalker != null) { treeWalker.release(); } if (walk != null) { walk.release(); } } }
From source file:com.nokia.carbide.installpackages.InstallPackages.java
public Comparator<String> getSDKVersionComparator() { if (sdkVersionOrder.isEmpty()) return Collections.reverseOrder(); // for backward compatibility return getOrderListStringComparator(sdkVersionOrder); }
From source file:org.xwiki.extension.job.history.internal.DefaultExtensionJobHistory.java
private List<File> getHistoryFiles() { File[] files = this.config.getStorage().listFiles(new FileFilter() { @Override/*from www.j a v a2 s . c om*/ public boolean accept(File file) { return file.isFile() && file.getName().endsWith(".xml"); } }); List<File> fileList = files != null ? Arrays.asList(files) : Collections.<File>emptyList(); Collections.sort(fileList, Collections.reverseOrder()); return fileList; }
From source file:models.data.providers.LogProvider.java
public static List<LogFileGeneric> getLogFileGenericsInFolder(String folderPath) { List<String> fileNames = FileIoUtils.getFileNamesInFolder(folderPath); List<LogFileGeneric> logFileGenerics = new ArrayList<LogFileGeneric>(); for (String fileName : fileNames) { LogFileGeneric logFileGeneric = new LogFileGeneric(fileName); logFileGenerics.add(logFileGeneric); if (VarUtils.IN_DETAIL_DEBUG) { models.utils.LogUtils.printLogNormal(logFileGeneric.toString()); }/*from w ww. j a v a 2 s. c om*/ } Collections.sort(logFileGenerics, Collections.reverseOrder()); return logFileGenerics; }
From source file:org.nuxeo.ecm.platform.ui.web.model.impl.EditableModelImpl.java
/** * Returns a new row key that is not already used. *///from w w w .ja v a 2 s . co m protected int getNewRowKey() { Collection<Integer> keys = keyMap.values(); if (keys.isEmpty()) { return 0; } else { List<Integer> lkeys = Arrays.asList(keys.toArray(new Integer[] {})); Comparator<Integer> comp = Collections.reverseOrder(); Collections.sort(lkeys, comp); Integer max = lkeys.get(0); return max + 1; } }
From source file:hivemall.anomaly.SingularSpectrumTransform.java
/** * Implicit Krylov Approximation (IKA) based naive scoring. * * Number of iterations for the Power method and QR method is fixed to 1 for efficiency. This * may cause failure (i.e. meaningless scores) depending on datasets and initial values. * *///from w w w. ja va 2 s. c om private double computeScoreIKA(@Nonnull final RealMatrix H, @Nonnull final RealMatrix G) { // assuming n = m = window, and keep track the left singular vector as `q` MatrixUtils.power1(G, q, 1, q, new double[window]); RealMatrix T = new Array2DRowRealMatrix(k, k); MatrixUtils.lanczosTridiagonalization(H.multiply(H.transpose()), q, T); double[] eigvals = new double[k]; RealMatrix eigvecs = new Array2DRowRealMatrix(k, k); MatrixUtils.tridiagonalEigen(T, 1, eigvals, eigvecs); // tridiagonalEigen() returns unordered eigenvalues, // so the top-r eigenvectors should be picked carefully TreeMap<Double, Integer> map = new TreeMap<Double, Integer>(Collections.reverseOrder()); for (int i = 0; i < k; i++) { map.put(eigvals[i], i); } Iterator<Integer> indices = map.values().iterator(); double s = 0.d; for (int i = 0; i < r; i++) { if (!indices.hasNext()) { throw new IllegalStateException("Should not happen"); } double v = eigvecs.getEntry(0, indices.next().intValue()); s += v * v; } return 1.d - Math.sqrt(s); }
From source file:org.sofun.core.team.TeamServiceImpl.java
@SuppressWarnings("unchecked") @Override// w w w . ja va2 s . co m public Set<TeamTag> getTeamTags(int limit) { Set<TeamTag> tags = new HashSet<TeamTag>(); String queryStr = "from " + TeamTagImpl.class.getSimpleName(); Query query = createQuery(queryStr); if (limit > 0) { query.setMaxResults(limit); } List<TeamTag> results = query.getResultList(); // Sort tags in reverse order based on score. See compareTo() for // implementation details. Collections.sort(results, Collections.reverseOrder()); if (results != null) { tags = new LinkedHashSet<TeamTag>(results); } return tags; }
From source file:org.tinymediamanager.scraper.MediaArtwork.java
public List<ImageSizeAndUrl> getImageSizes() { List<ImageSizeAndUrl> descImageSizes = new ArrayList<MediaArtwork.ImageSizeAndUrl>(imageSizes); // sort descending Collections.sort(descImageSizes, Collections.reverseOrder()); return descImageSizes; }