List of usage examples for java.util Arrays sort
public static <T> void sort(T[] a, Comparator<? super T> c)
From source file:com.uksf.mf.core.utility.LogHandler.java
/** * First checks if there are already 10 log files, if so, deletes the oldest, then creates the new log file *///from ww w . j ava2s . c o m private void createLogFile() { if (LOG_CREATED) return; LOGS.mkdir(); File[] logs = LOGS.listFiles((FileFilter) FileFileFilter.FILE); assert logs != null; if (logs.length > 1) Arrays.sort(logs, LastModifiedFileComparator.LASTMODIFIED_COMPARATOR); if (logs.length > 9) { if (!logs[0].delete()) { System.out.println("'" + logs[0].getAbsolutePath() + logs[0].getName() + "' was not deleted."); } } logFile = new File(LOGS + "\\MF__" + DATEFORMAT.format(DATE) + ".log"); try { if (!logFile.createNewFile()) { throw new IOException("Log file not created at '" + logFile.getAbsolutePath() + "'"); } } catch (IOException e) { error(e); } System.out.println(logFile.getAbsolutePath()); LOG_CREATED = true; logSeverity(INFO, "Log Created"); }
From source file:com.googlesource.gerrit.plugins.supermanifest.JiriProjects.java
public void sortByPath() { Arrays.sort(projects, new SortbyPath()); }
From source file:com.jaeksoft.searchlib.util.FileUtils.java
public final static File[] sortByLastModified(File[] files, boolean desc) { if (desc)//w ww. j a va 2 s . c o m Arrays.sort(files, new LastModifiedDescComparator()); else Arrays.sort(files, new LastModifiedAscComparator()); return files; }
From source file:net.firejack.platform.service.registry.helper.PackageVersionHelper.java
public static FileInfo[] sortingByNameLikeNumber(FileInfo[] files, boolean desc) { Arrays.sort(files, new Comparator() { public int compare(final Object o1, final Object o2) { Integer i1 = Integer.parseInt(((FileInfo) o1).getFilename()); Integer i2 = Integer.parseInt(((FileInfo) o2).getFilename()); return i1.compareTo(i2); }//from w w w . j a v a 2 s . c o m }); if (desc) { org.apache.commons.lang.ArrayUtils.reverse(files); } return files; }
From source file:de.tudarmstadt.ukp.dkpro.core.api.datasets.Dataset.java
default Split getSplit(double aTrainRatio, double aTestRatio) { Log LOG = LogFactory.getLog(getClass()); File[] all = getDataFiles();//w ww. j av a2s. c om Arrays.sort(all, (File a, File b) -> { return a.getName().compareTo(b.getName()); }); LOG.info("Found " + all.length + " files"); int trainPivot = (int) Math.round(all.length * aTrainRatio); int testPivot = (int) Math.round(all.length * aTestRatio) + trainPivot; File[] train = (File[]) ArrayUtils.subarray(all, 0, trainPivot); File[] test = (File[]) ArrayUtils.subarray(all, trainPivot, testPivot); LOG.debug("Assigned " + train.length + " files to training set"); LOG.debug("Assigned " + test.length + " files to test set"); if (testPivot != all.length) { LOG.info("Files missing from split: [" + (all.length - testPivot) + "]"); } return new SplitImpl(train, test, null); }
From source file:com.mac.holdempoker.app.hands.Quad.java
@Override public void haveCard(Card card) { if (insertSize == 7) { return;//from w w w.j a v a2s .co m } Card[] ranked = cards.get(card.getRank()); if (Objects.isNull(ranked)) { ranked = new Card[4]; cards.put(card.getRank(), ranked); } insert(ranked, card); Arrays.sort(ranked, cardComparator()); insertSize++; }
From source file:io.github.sn0cr.rapidRunner.testRunner.TestCaseFinder.java
public TestCaseFinder(Path parentFolder, String filePattern, String inExtension, String outExtension) { final String[] files = parentFolder.toFile().list(new WildcardFileFilter(filePattern)); Arrays.sort(files, new NaturalOrderComparator()); for (final String filename : files) { final String extension = FilenameUtils.getExtension(filename); final String name = FilenameUtils.getBaseName(filename); final Path toFile = Paths.get(parentFolder.toString(), filename); Pair<Path, Path> testCasePair; if (this.testCases.containsKey(name)) { testCasePair = this.testCases.get(name); } else {/*from w w w . jav a 2s .c o m*/ testCasePair = new Pair<Path, Path>(); } if (extension.equals(inExtension)) { testCasePair.setA(toFile); } else if (extension.equals(outExtension)) { testCasePair.setB(toFile); } if (testCasePair.notEmpty()) { this.testCases.put(name, testCasePair); } } }
From source file:azkaban.flow.GroupedFlow.java
public GroupedFlow(Flow... flows) { this.flows = flows; this.sortedFlows = Arrays.copyOf(this.flows, this.flows.length); Arrays.sort(this.sortedFlows, new Comparator<Flow>() { @Override// www.ja v a2 s . co m public int compare(Flow o1, Flow o2) { return o1.getName().compareTo(o2.getName()); } }); }
From source file:architecture.common.util.LocaleUtils.java
public static Locale[] getAvailableLocales() { Locale locales[] = Locale.getAvailableLocales(); Arrays.sort(locales, new Comparator<Locale>() { public int compare(Locale locale1, Locale locale2) { return locale1.getDisplayName().compareTo(locale2.getDisplayName()); }/*from w w w .j a va2 s . co m*/ }); return locales; }
From source file:com.consol.citrus.admin.util.FileHelperImpl.java
/** * {@inheritDoc}// w w w.ja va2 s . c o m */ public String[] getFolders(File directory) { if (directory.exists()) { String[] files = directory.list(new FilenameFilter() { public boolean accept(File dir, String name) { return name.charAt(0) != '.' && new File(dir, name).isDirectory(); } }); if (files != null) { Arrays.sort(files, String.CASE_INSENSITIVE_ORDER); return files; } else { return new String[] {}; } } else { throw new CitrusAdminRuntimeException( "Could not open directory because it does not exist: " + directory); } }