List of usage examples for java.util Comparator Comparator
Comparator
From source file:jetbrains.exodus.env.Reflect.java
public Reflect(@NotNull final File directory) { final File[] files = LogUtil.listFiles(directory); Arrays.sort(files, new Comparator<File>() { @Override// w w w . j a v a 2 s . c o m public int compare(File o1, File o2) { long cmp = LogUtil.getAddress(o1.getName()) - LogUtil.getAddress(o2.getName()); if (cmp > 0) return 1; if (cmp < 0) return -1; return 0; } }); final int filesLength = files.length; if (filesLength == 0) { throw new IllegalArgumentException("No files found"); } System.out.println("Files found: " + filesLength); int i = 0; long fileSize = 0; for (final File f : files) { ++i; final long length = f.length(); if (fileSize % LogUtil.LOG_BLOCK_ALIGNMENT != 0 && i != filesLength) { throw new IllegalArgumentException( "Length of non-last file " + f.getName() + " is badly aligned: " + length); } fileSize = Math.max(fileSize, length); } System.out.println("Max file length: " + fileSize); final int pageSize; if (fileSize % DEFAULT_PAGE_SIZE == 0 || filesLength == 1) { pageSize = DEFAULT_PAGE_SIZE; } else { pageSize = LogUtil.LOG_BLOCK_ALIGNMENT; } System.out.println("Computed page size: " + pageSize); final DataReader reader = new FileDataReader(directory, 16); final DataWriter writer = new FileDataWriter(directory); LogConfig logConfig = new LogConfig(); logConfig.setReader(reader); logConfig.setWriter(writer); final EnvironmentConfig environmentConfig = new EnvironmentConfig(); environmentConfig .setLogFileSize(((fileSize + pageSize - 1) / pageSize) * pageSize / LogUtil.LOG_BLOCK_ALIGNMENT); environmentConfig.setLogCachePageSize(pageSize); environmentConfig.setGcEnabled(false); env = (EnvironmentImpl) Environments.newInstance(logConfig, environmentConfig); log = env.getLog(); }
From source file:com.haulmont.cuba.desktop.gui.components.SwingXTableSettings.java
@Override public boolean saveSettings(Element element) { element.addAttribute("horizontalScroll", String.valueOf(table.isHorizontalScrollEnabled())); saveFontPreferences(element);// ww w.ja v a 2 s . c o m Element columnsElem = element.element("columns"); if (columnsElem != null) { element.remove(columnsElem); } columnsElem = element.addElement("columns"); final List<TableColumn> visibleTableColumns = table.getColumns(); final List<Table.Column> visibleColumns = new ArrayList<>(); for (TableColumn tableColumn : visibleTableColumns) { visibleColumns.add((Table.Column) tableColumn.getIdentifier()); } List<TableColumn> columns = table.getColumns(true); Collections.sort(columns, new Comparator<TableColumn>() { @SuppressWarnings("SuspiciousMethodCalls") @Override public int compare(TableColumn col1, TableColumn col2) { if (col1 instanceof TableColumnExt && !((TableColumnExt) col1).isVisible()) { return 1; } if (col2 instanceof TableColumnExt && !((TableColumnExt) col2).isVisible()) { return -1; } int i1 = visibleColumns.indexOf(col1.getIdentifier()); int i2 = visibleColumns.indexOf(col2.getIdentifier()); return Integer.compare(i1, i2); } }); for (TableColumn column : columns) { Element colElem = columnsElem.addElement("column"); colElem.addAttribute("id", column.getIdentifier().toString()); int width = column.getWidth(); colElem.addAttribute("width", String.valueOf(width)); if (column instanceof TableColumnExt) { Boolean visible = ((TableColumnExt) column).isVisible(); colElem.addAttribute("visible", visible.toString()); } } if (table.getRowSorter() != null) { TableColumn sortedColumn = table.getSortedColumn(); List<? extends RowSorter.SortKey> sortKeys = table.getRowSorter().getSortKeys(); if (sortedColumn != null && !sortKeys.isEmpty()) { columnsElem.addAttribute("sortColumn", String.valueOf(sortedColumn.getIdentifier())); columnsElem.addAttribute("sortOrder", sortKeys.get(0).getSortOrder().toString()); } } return true; }
From source file:net.sbfmc.modules.anticheat.conf.AnticheatReportsNicksConf.java
@Override public void initConf() throws IOException { confFolder = new File(SBFPlugin.getPlugin().getDataFolder(), "anticheat_reports"); if (confFolder.exists() && confFolder.length() / 1024 / 1024 > 256) { File[] files = confFolder.listFiles(); Arrays.sort(files, new Comparator<File>() { @Override//from w w w . ja va2 s.c o m public int compare(File o1, File o2) { return (int) (o1.lastModified() - o2.lastModified()); } }); ArrayUtils.reverse(files); for (File file : files) { if (confFolder.length() / 1024 / 1024 < 256) { break; } file.delete(); } } createConf(); }
From source file:com.hmsinc.epicenter.webapp.remoting.MetadataService.java
/** * Gets all available classifiers./*from w ww . j a va 2 s.co m*/ * * Sorts with non-beta first. * * @return */ @Secured("ROLE_USER") @Transactional(readOnly = true) @RemoteMethod public Collection<Classifier> getClassifiers() { final List<Classifier> ret = analysisRepository.getClassifiers(); Collections.sort(ret, new Comparator<Classifier>() { public int compare(Classifier o1, Classifier o2) { return new CompareToBuilder().append(o1.isBeta(), o2.isBeta()).append(o1.getName(), o2.getName()) .toComparison(); } }); return ret; }
From source file:edu.monash.merc.util.DMUtil.java
@SuppressWarnings({ "unchecked", "rawtypes" }) public static Map<String, String> sortByValue(Map<String, String> map) { List list = new LinkedList(map.entrySet()); Collections.sort(list, new Comparator() { public int compare(Object o1, Object o2) { return ((Comparable) ((Map.Entry) (o1)).getValue()).compareTo(((Map.Entry) (o2)).getValue()); }/*from w w w . j a v a2 s . co m*/ }); Map<String, String> result = new LinkedHashMap(); for (Iterator it = list.iterator(); it.hasNext();) { Map.Entry entry = (Map.Entry) it.next(); result.put((String) entry.getKey(), (String) entry.getValue()); } return result; }
From source file:org.pentaho.agilebi.spoon.visualizations.VisualizationManager.java
private void loadVisualizations(File aDir) { File[] theFiles = aDir.listFiles(); if (theFiles == null) { return;//from w w w .j av a2 s.c o m } for (int i = 0; i < theFiles.length; i++) { File theFile = theFiles[i]; if (theFile.isDirectory()) { File[] dirFiles = theFile.listFiles(); for (int j = 0; j < dirFiles.length; j++) { File pluginFile = dirFiles[j]; if (pluginFile.getName().equals(PLUGIN_FILE)) { loadVisualizationFile(pluginFile); } } } } // sort the list based on order and alpha Collections.sort(visualizations, new Comparator<IVisualization>() { public int compare(IVisualization v1, IVisualization v2) { if (v1.getOrder() > v2.getOrder()) { return -1; } else if (v1.getOrder() < v2.getOrder()) { return 1; } else { return v1.getTitle().compareTo(v2.getTitle()); } } }); }
From source file:de.micromata.genome.gwiki.controls.GWikiDeletedPagesActionBean.java
public Object onViewItem() { if (StringUtils.isEmpty(pageId) == true) { wikiContext.addValidationError("gwiki.page.edit.DeletedPages.message.pageidnotset"); list = true;/* www .j a v a 2 s. c o m*/ return null; } List<GWikiElementInfo> versionsInfos = wikiContext.getWikiWeb().getStorage().getVersions(pageId); Collections.sort(versionsInfos, new Comparator<GWikiElementInfo>() { public int compare(GWikiElementInfo o1, GWikiElementInfo o2) { return o2.getId().compareTo(o1.getId()); } }); XmlElement ta = GWikiPageInfoActionBean.getStandardTable(); ta.nest(// tr(// th(text(translate("gwiki.page.edit.DeletedPages.col.author"))), // th(text(translate("gwiki.page.edit.DeletedPages.col.time"))), // th(text(translate("gwiki.page.edit.DeletedPages.col.action"))) // )// ); for (GWikiElementInfo ei : versionsInfos) { ta.nest(// tr(// td(text(StringUtils.defaultString( ei.getProps().getStringValue(GWikiPropKeys.MODIFIEDBY), "Unknown"))), // td(text(getDisplayDate(ei.getProps().getDateValue(GWikiPropKeys.MODIFIEDAT)))), // td(// a(attrs("href", wikiContext.localUrl(ei.getId())), text(translate("gwiki.page.edit.DeletedPages.link.view"))), // a(attrs("href", wikiContext.localUrl("edit/PageInfo") + "?restoreId=" + ei.getId() + "&pageId=" + pageId + "&method_onRestore=true"), // text(translate("gwiki.page.edit.DeletedPages.link.restore"))// )) // )); } versionBox = GWikiPageInfoActionBean.getBoxFrame("Versionen", ta).toString(); return null; }
From source file:de.hybris.platform.acceleratorfacades.device.populators.ResponsiveMediaContainerPopulator.java
protected List<ImageData> sortMediasBasedOnWidth(final List<ImageData> mediaDataList) { if (CollectionUtils.isNotEmpty(mediaDataList)) { Collections.sort(mediaDataList, new Comparator<ImageData>() { @Override//from w ww . ja v a 2 s . c o m public int compare(final ImageData imageData1, final ImageData imageData2) { return (imageData1.getWidth()).compareTo(imageData2.getWidth()); } }); } return mediaDataList; }
From source file:net.chrissearle.flickrvote.web.ShowChallengeAction.java
public String execute() throws Exception { if (logger.isLoggable(Level.FINE)) { logger.fine("Challenge ID " + challengeTag); }/*from www . j a v a2 s .c o m*/ ChallengeSummary challengeSummary = challengeService.getChallengeSummary(challengeTag); if (logger.isLoggable(Level.FINE)) { logger.fine("Challenge " + challengeSummary); } if (challengeSummary != null) { challenge = new DisplayChallengeSummary(challengeSummary); ChallengeItem challengeItem = photographyService.getChallengeImages(challengeSummary.getTag()); images = new ArrayList<DisplayImage>(challengeItem.getImages().size()); for (ImageItem image : challengeItem.getImages()) { images.add(new DisplayImage(image)); } Collections.sort(images, new Comparator<DisplayImage>() { public int compare(DisplayImage o1, DisplayImage o2) { return o2.getVoteCount().compareTo(o1.getVoteCount()); } }); } return ActionSupport.SUCCESS; }
From source file:de.taimos.dao.hibernate.EntityDAOMock.java
protected void sortById(List<E> values) { Collections.sort(values, new Comparator<E>() { @Override/*from w ww. j a v a 2s. co m*/ @SuppressWarnings({ "unchecked", "rawtypes" }) public int compare(E o1, E o2) { return ((Comparable) o1.getId()).compareTo(o2.getId()); } }); }