List of usage examples for java.util Collections reverseOrder
@SuppressWarnings("unchecked") public static <T> Comparator<T> reverseOrder()
From source file:org.addhen.smssync.presentation.view.ui.fragment.MessageFragment.java
private void deleteItems() { //Sort in ascending order for restoring deleted items Comparator cmp = Collections.reverseOrder(); Collections.sort(mPendingMessages, cmp); removeItems();/* w ww. ja v a 2 s .c o m*/ Snackbar snackbar = Snackbar.make(mFab, getActivity().getString(R.string.item_deleted, mPendingMessages.size()), Snackbar.LENGTH_LONG); snackbar.setAction(R.string.undo, e -> { // Restore items for (PendingMessage pendingDeletedDeployment : mPendingMessages) { mMessageAdapter.addItem(pendingDeletedDeployment.messageModel, pendingDeletedDeployment.getPosition()); } clearItems(); }); View view = snackbar.getView(); TextView tv = (TextView) view.findViewById(android.support.design.R.id.snackbar_text); tv.setTextColor(getAppContext().getResources().getColor(R.color.red)); snackbar.setCallback(new Snackbar.Callback() { @Override public void onDismissed(Snackbar snackbar, int event) { super.onDismissed(snackbar, event); if (event != Snackbar.Callback.DISMISS_EVENT_ACTION) { if (mPendingMessages.size() > 0) { for (PendingMessage pendingDeletedDeployment : mPendingMessages) { mDeleteMessagePresenter .deleteMessage(pendingDeletedDeployment.messageModel.getMessageUuid()); } clearItems(); } } } }); snackbar.show(); }
From source file:edu.uoc.pelp.engine.aem.BasicCodeAnalyzer.java
/** * Delete all temporal files and directories created during the program analysis *//*from w w w. j a va2s . c o m*/ protected void clearTempFiles() { File[] fileList = new File[_tmpFiles.size()]; _tmpFiles.toArray(fileList); // Remove main file if (_buildingMainFile != null) { if (_buildingMainFile.exists()) { // Delete the file or if it is not possble, mark it for delayed deletion if (!_buildingMainFile.delete()) { _buildingMainFile.deleteOnExit(); } _buildingMainFile = null; } } // Remove files in the list for (File f : fileList) { if (f.exists() && f.isFile()) { // Delete the file or if it is not possble, mark it for delayed deletion if (!f.delete()) { f.deleteOnExit(); } // Remove the file from the list _tmpFiles.remove(f); } } // Sort folders in reverse order, to ensure child folders to be the first to be deleted Collections.sort(_tmpFiles, Collections.reverseOrder()); // Create a new list with remaining paths fileList = new File[_tmpFiles.size()]; _tmpFiles.toArray(fileList); // Remove folders for (File f : fileList) { if (!f.delete()) { f.deleteOnExit(); } } }
From source file:hudson.plugins.jobConfigHistory.FileHistoryDao.java
@Override public void purgeOldEntries(final File itemHistoryRoot, final int maxEntries) { if (maxEntries > 0) { LOG.log(Level.FINE, "checking for history files to purge ({0} max allowed)", maxEntries); final int entriesToLeave = maxEntries - 1; final File[] historyDirs = itemHistoryRoot.listFiles(HistoryFileFilter.INSTANCE); if (historyDirs != null && historyDirs.length >= entriesToLeave) { Arrays.sort(historyDirs, Collections.reverseOrder()); for (int i = entriesToLeave; i < historyDirs.length; i++) { if (isCreatedEntry(historyDirs[i])) { continue; }/* w w w.j a v a2 s.c o m*/ LOG.log(Level.FINE, "purging old directory from history logs: {0}", historyDirs[i]); deleteDirectory(historyDirs[i]); } } } }
From source file:org.kaaproject.kaa.server.admin.services.ProfileServiceImpl.java
@Override public List<SchemaInfoDto> getServerProfileSchemaInfosByEndpointKey(String endpointKeyHash) throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); try {/*from w w w . j av a 2 s .c o m*/ EndpointProfileDto endpointProfile = getEndpointProfileByKeyHash(endpointKeyHash); List<ServerProfileSchemaDto> serverProfileSchemas = controlService .getServerProfileSchemasByApplicationId(endpointProfile.getApplicationId()); List<SchemaInfoDto> schemaInfos = new ArrayList<>(serverProfileSchemas.size()); for (ServerProfileSchemaDto serverProfileSchema : serverProfileSchemas) { SchemaInfoDto schemaInfo = new SchemaInfoDto(serverProfileSchema); String body = null; if (schemaInfo.getVersion() == endpointProfile.getServerProfileVersion()) { body = endpointProfile.getServerProfileBody(); } RecordField schemaForm = createRecordFieldFromCtlSchemaAndBody(serverProfileSchema.getCtlSchemaId(), body); schemaInfo.setSchemaName(serverProfileSchema.getName()); schemaInfo.setSchemaForm(schemaForm); schemaInfos.add(schemaInfo); } Collections.sort(schemaInfos, Collections.reverseOrder()); return schemaInfos; } catch (Exception ex) { throw Utils.handleException(ex); } }
From source file:org.sipfoundry.sipxconfig.site.cdr.CdrReports.java
private List<CdrMinutesGraphBean> getOutgoingExtensionData(List<Cdr> cdrs) { List<CdrMinutesGraphBean> minutesOutgoingCalls = new ArrayList<CdrMinutesGraphBean>(); Map<String, CdrMinutesGraphBean> outgoingCalls = new HashMap<String, CdrMinutesGraphBean>(); for (Cdr cdr : cdrs) { if (cdr.getDuration() > 0) { boolean callerInternal = cdr.getCallerInternal(); if (callerInternal) { String extension = cdr.getCaller(); CdrMinutesGraphBean bean = outgoingCalls.get(extension); if (bean == null) { outgoingCalls.put(extension, new CdrMinutesGraphBean(extension, (double) cdr.getDuration())); } else { bean.setMinutes((bean.getMinutes() + cdr.getDuration())); }/*from ww w .j av a2s .c o m*/ } } } minutesOutgoingCalls.addAll(outgoingCalls.values()); Collections.sort(minutesOutgoingCalls, Collections.reverseOrder()); if (minutesOutgoingCalls.size() > 10) { minutesOutgoingCalls = minutesOutgoingCalls.subList(0, 10); } return minutesOutgoingCalls; }
From source file:org.addhen.smssync.presentation.view.ui.fragment.MessageFragment.java
private void publishItems() { //Sort in ascending order for restoring deleted items Comparator cmp = Collections.reverseOrder(); Collections.sort(mPendingMessages, cmp); removeItems();//from w w w .j av a 2 s. c o m Snackbar snackbar = Snackbar.make(mFab, getActivity().getString(R.string.item_deleted, mPendingMessages.size()), Snackbar.LENGTH_LONG); snackbar.setAction(R.string.undo, e -> { // Restore items for (PendingMessage pendingDeletedDeployment : mPendingMessages) { mMessageAdapter.addItem(pendingDeletedDeployment.messageModel, pendingDeletedDeployment.getPosition()); } clearItems(); }); View view = snackbar.getView(); TextView tv = (TextView) view.findViewById(android.support.design.R.id.snackbar_text); tv.setTextColor(getAppContext().getResources().getColor(R.color.red)); snackbar.setCallback(new Snackbar.Callback() { @Override public void onDismissed(Snackbar snackbar, int event) { super.onDismissed(snackbar, event); if (event != Snackbar.Callback.DISMISS_EVENT_ACTION) { if (mPendingMessages.size() > 0) { List<MessageModel> messageModels = new ArrayList<MessageModel>(); for (PendingMessage pendingDeletedDeployment : mPendingMessages) { messageModels.add(pendingDeletedDeployment.messageModel); } mPublishMessagesPresenter.publishMessage(messageModels); clearItems(); } } } }); snackbar.show(); }
From source file:org.caleydo.data.tcga.internal.TCGABrowserStartupAddon.java
private RunOverview[] createModel(File file) { Gson gson = new Gson(); RunOverview[] fromJson;// ww w .j av a 2s .c o m try (Reader r = Files.newReader(file, Charset.forName("UTF-8"))) { fromJson = gson.fromJson(r, RunOverview[].class); Arrays.sort(fromJson, Collections.reverseOrder()); return fromJson; } catch (JsonSyntaxException | JsonIOException | IOException e) { log.error("can't parse " + file.getAbsolutePath(), e); return new RunOverview[0]; } }
From source file:abfab3d.io.output.GridSaver.java
/** * Returns up to numShells shells that are above the minimum volume. * * @param mesh The mesh//from ww w . j a va2 s . c om * @param numShells The maximum number of shells * @param minVolume The minimum volume */ public static ShellResults getLargestShells(WingedEdgeTriangleMesh mesh, int numShells, double minVolume) { ShellFinder shellFinder = new ShellFinder(); ShellFinder.ShellInfo shells[] = shellFinder.findShells(mesh); printf("shellsCount: %d\n", shells.length); int regions_removed = 0; //System.out.println("Minimum volume: " + (minVolume / Units.CM3)); ArrayList<ShellData> saved_shells = new ArrayList<ShellData>(); int face_count = 0; int cnt = 0; for (int i = 0; i < shells.length; i++) { AreaCalculator ac = new AreaCalculator(); shellFinder.getShell(mesh, shells[i].startFace, ac); mesh.getTriangles(ac); double volume = ac.getVolume(); //System.out.println(" vol: " + (volume / Units.CM3)); if (volume >= minVolume) { //System.out.println("Keeping shell: " + volume / Units.CM3); saved_shells.add(new ShellData(shells[i], volume)); if (cnt < numShells) { face_count += shells[i].faceCount; } cnt++; } else { //System.out.println("Removing shell. vol: " + (volume / Units.CM3)); regions_removed++; } } Collections.sort(saved_shells, Collections.reverseOrder()); IndexedTriangleSetBuilder its = new IndexedTriangleSetBuilder(face_count); int shell_cnt = 0; for (ShellData sd : saved_shells) { shellFinder.getShell(mesh, sd.info.startFace, its); shell_cnt++; if (shell_cnt >= numShells) break; } printf("extracting largest shells: %d\n", face_count); mesh = new WingedEdgeTriangleMesh(its.getVertices(), its.getFaces()); return new ShellResults(mesh, regions_removed); }
From source file:org.sipfoundry.sipxconfig.site.cdr.CdrReports.java
private List<CdrGraphBean> mostActiveExtensions(Bag bagExtensions) { List<CdrGraphBean> activeExtensions = new ArrayList<CdrGraphBean>(); Set uniqueSetCallers = bagExtensions.uniqueSet(); for (Object key : uniqueSetCallers) { CdrGraphBean bean = new CdrGraphBean((String) key, bagExtensions.getCount(key)); activeExtensions.add(bean);/*from w ww. jav a2 s. co m*/ } Collections.sort(activeExtensions, Collections.reverseOrder()); if (activeExtensions.size() > 10) { activeExtensions = activeExtensions.subList(0, 10); } return activeExtensions; }