List of usage examples for java.util Arrays sort
public static <T> void sort(T[] a, Comparator<? super T> c)
From source file:com.gzj.tulip.jade.statement.DefaultInterpreterFactory.java
public synchronized void addInterpreter(Interpreter interpreter) { if (!ArrayUtils.contains(this.interpreters, interpreter)) { Interpreter[] interpreters = Arrays.copyOf(this.interpreters, this.interpreters.length + 1); interpreters[this.interpreters.length] = interpreter; Arrays.sort(interpreters, new InterpreterComparator()); this.interpreters = interpreters; }/*from w w w .j a v a2s.com*/ }
From source file:com.thoughtworks.go.util.FileDigester.java
public static String md5DigestOfFolderContent(File directory) throws IOException { File[] files = directory.listFiles(); Arrays.sort(files, NameFileComparator.NAME_COMPARATOR); StringBuilder md5 = new StringBuilder(); for (File file : files) { if (file.isDirectory()) md5.append(md5DigestOfFolderContent(file)); else/* ww w .j a va 2 s.c o m*/ md5.append(file.getName() + md5DigestOfFile(file)); } return md5DigestOfStream(new ByteArrayInputStream(md5.toString().getBytes(CharEncoding.UTF_8))); }
From source file:com.adobe.aem.demo.gui.AemDemoDownload.java
public void run() { if (aemDemo.getDownloadInProgress()) { File theNewestFile = null; File dir = new File(aemDemo.getBuildFile().getParentFile().getAbsolutePath() + File.separator + "dist" + File.separator + "downloads"); FileFilter fileFilter = new WildcardFileFilter("*.*"); File[] files = dir.listFiles(fileFilter); if (files.length > 0) { /** The newest file comes first **/ Arrays.sort(files, LastModifiedFileComparator.LASTMODIFIED_REVERSE); theNewestFile = files[0];//from w w w. ja v a 2s . c o m long newSize = theNewestFile.length(); if (newSize != currentSize && (theNewestFile.lastModified() > (System.currentTimeMillis() - 5000))) { System.out.println(" [echo] " + theNewestFile.getName() + " (" + AemDemoUtils.humanReadableByteCount(theNewestFile.length(), true) + ")"); currentSize = newSize; } } } }
From source file:com.consol.citrus.admin.service.FileBrowserService.java
/** * Gets all sub-folder names in give directory. * @param directory/*from w w w . j av a2 s . c o m*/ * @return */ 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 ApplicationRuntimeException( "Could not open directory because it does not exist: " + directory); } }
From source file:net.landora.videoplayer.files.GeneralDirectoryMenu.java
@Override protected void refreshImpl() { links = new ArrayList<MenuLink>(); File[] children = dir.listFiles((FileFilter) FileFilterUtils.directoryFileFilter()); if (children != null && children.length > 0) { Arrays.sort(children, new FileSorter()); for (File child : children) { links.add(new MenuLink(Icon.Folder, child.getName(), new GeneralDirectoryMenu(child))); }/*from www . ja va2s .c o m*/ } children = dir.listFiles((FileFilter) FileFilterUtils.notFileFilter(FileFilterUtils.directoryFileFilter())); if (children != null & children.length != 0) { Arrays.sort(children, new FileSorter()); for (File child : children) { if (child.isHidden() || !child.isFile() || !ExtensionUtils.isVideoExtension(child)) { continue; } links.add(new MenuLink(Icon.File, child.getName(), new PlayFileAction(child))); } } }
From source file:Main.java
/** * Utility method to sort two related arrays - that is, two arrays where the elements are related to each other * by their position in the array. i.e. firstArray[0] is related to secondArray[0], firstArray[1] is related to * secondArray[1], and so on. The first array is sorted based on its implementation of Comparable, and the 2nd * array is sorted by it's related item in the first array, so that the same elements are still related to each * other after the sort//from w ww . j av a 2 s.com * @param firstArray The first array, which contains the values to sort * @param secondArray The second array, which will be sorted based on the values in the first array * @param <A> The type of element in the first array * @param <B> the type of element in the second array */ public static <A extends Comparable<A>, B> void sortTwoArrays(A[] firstArray, B[] secondArray) { if (firstArray.length != secondArray.length) { throw new RuntimeException("Both arrays must be of the same length"); } class element { public A first; public B second; } element[] elements = new element[firstArray.length]; Arrays.sort(elements, new Comparator<element>() { public int compare(element a, element b) { return a.first.compareTo(b.first); } }); for (int i = 0; i < elements.length; i++) { firstArray[i] = elements[i].first; secondArray[i] = elements[i].second; } }
From source file:com.adobe.aem.demomachine.gui.AemDemoDownload.java
public void run() { if (aemDemo.getDownloadInProgress()) { File theNewestFile = null; File dir = new File(aemDemo.getBuildFile().getParentFile().getAbsolutePath() + File.separator + "dist" + File.separator + "downloads"); // Folder might have not been created yet if (dir != null && dir.exists()) { FileFilter fileFilter = new WildcardFileFilter("*.*"); File[] files = dir.listFiles(fileFilter); if (files.length > 0) { /** The newest file comes first **/ Arrays.sort(files, LastModifiedFileComparator.LASTMODIFIED_REVERSE); theNewestFile = files[0]; long newSize = theNewestFile.length(); if (newSize != currentSize && (theNewestFile.getName().indexOf("xml") < 0) && (theNewestFile.getName().indexOf("html") < 0) && (theNewestFile.lastModified() > (System.currentTimeMillis() - 5000))) { System.out.println(" [echo] " + theNewestFile.getName() + " (" + AemDemoUtils.humanReadableByteCount(theNewestFile.length(), true) + ")"); currentSize = newSize; }/* www. j a v a2s .com*/ } } } }
From source file:net.firejack.platform.service.registry.helper.PackageVersionHelper.java
public static FileInfo[] sortingByName(FileInfo[] files, boolean desc) { Arrays.sort(files, new Comparator() { public int compare(final Object o1, final Object o2) { String s1 = ((FileInfo) o1).getFilename().toLowerCase(); String s2 = ((FileInfo) o2).getFilename().toLowerCase(); return s1.compareTo(s2); }//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:com.cloudera.oryx.als.computation.local.SplitTestTrain.java
@Override public Void call() throws IOException { File[] inputFiles = inboundDir.listFiles(IOUtils.NOT_HIDDEN); if (inputFiles == null || inputFiles.length == 0) { log.info("No input files in {}", inboundDir); return null; }/* w w w. ja va2 s. c o m*/ Arrays.sort(inputFiles, ByLastModifiedComparator.INSTANCE); IOUtils.mkdirs(trainDir); IOUtils.mkdirs(testDir); double testSetFraction = ConfigUtils.getDefaultConfig().getDouble("model.test-set-fraction"); if (testSetFraction == 0.0) { for (File inputFile : inputFiles) { log.info("Copying {} to {}", inputFile, trainDir); Files.copy(inputFile, new File(trainDir, inputFile.getName())); } } else { RandomGenerator random = RandomManager.getRandom(); try (Writer trainOut = IOUtils.buildGZIPWriter(new File(trainDir, "train.csv.gz")); Writer testOut = IOUtils.buildGZIPWriter(new File(testDir, "test.csv.gz"))) { for (File inputFile : inputFiles) { log.info("Splitting {}", inputFile); for (CharSequence line : new FileLineIterable(inputFile)) { if (random.nextDouble() < testSetFraction) { testOut.append(line).append('\n'); } else { trainOut.append(line).append('\n'); } } } } } return null; }
From source file:com.logsniffer.util.grok.GrokAppConfig.java
@Bean public GroksRegistry groksRegistry() throws IOException, GrokException { GroksRegistry registry = new GroksRegistry(); PathMatchingResourcePatternResolver pathMatcher = new PathMatchingResourcePatternResolver(); Resource[] classPathPatterns = pathMatcher.getResources("classpath*:/grok-patterns/*"); Arrays.sort(classPathPatterns, new Comparator<Resource>() { @Override// w w w. j a v a2 s .c o m public int compare(final Resource o1, final Resource o2) { return o1.getFilename().compareTo(o2.getFilename()); } }); LinkedHashMap<String, String[]> grokBlocks = new LinkedHashMap<String, String[]>(); for (Resource r : classPathPatterns) { grokBlocks.put(r.getFilename(), IOUtils.readLines(r.getInputStream()).toArray(new String[0])); } registry.registerPatternBlocks(grokBlocks); return registry; }