List of usage examples for java.util Arrays sort
public static <T> void sort(T[] a, Comparator<? super T> c)
From source file:de.tor.tribes.util.AllyUtils.java
public static Tribe[] getTribes(Ally pAlly, Comparator<Tribe> pComparator) { Tribe[] result = null;/*from www. jav a 2 s.c o m*/ if (pAlly == null) { return new Tribe[0]; } else if (pAlly.equals(NoAlly.getSingleton())) { List<Tribe> tribes = new LinkedList<>(); CollectionUtils.addAll(tribes, DataHolder.getSingleton().getTribes().values()); CollectionUtils.filter(tribes, new Predicate() { @Override public boolean evaluate(Object o) { return ((Tribe) o).getAlly() == null || ((Tribe) o).getAlly().equals(NoAlly.getSingleton()); } }); result = tribes.toArray(new Tribe[tribes.size()]); } else { result = pAlly.getTribes(); } if (pComparator != null) { Arrays.sort(result, pComparator); } return result; }
From source file:net.sourceforge.vulcan.spring.jdbc.JdbcSchemaMigrator.java
public void setMigrationScripts(Resource[] migrationScripts) { this.migrationScripts = migrationScripts; Arrays.sort(this.migrationScripts, new Comparator<Resource>() { public int compare(Resource o1, Resource o2) { return o1.getFilename().compareTo(o2.getFilename()); }//w ww . j av a 2 s . c o m }); }
From source file:com.sketchy.server.action.GetImageFiles.java
@Override public JSONServletResult execute(HttpServletRequest request) throws Exception { JSONServletResult jsonServletResult = new JSONServletResult(Status.SUCCESS); try {/* w ww. j a va 2 s . co m*/ File[] files = HttpServer.IMAGE_UPLOAD_DIRECTORY.listFiles(new FilenameFilter() { @Override public boolean accept(File arg0, String filename) { return (StringUtils.endsWithIgnoreCase(filename, ".dat") && (!StringUtils.endsWithIgnoreCase(filename, "rendered.dat"))); } }); Arrays.sort(files, new Comparator<File>() { @Override public int compare(File f1, File f2) { if ((f1 == null) || (f2 == null)) return 0; // Shouldn't ever be null, but if so if either is null, then just return 0; return f1.getName().compareToIgnoreCase(f2.getName()); } }); List<Object> rows = new ArrayList<Object>(); for (File file : files) { Map<String, Object> row = new HashMap<String, Object>(); File dimFile = new File(file.getPath()); if (dimFile.exists()) { String json = FileUtils.readFileToString(dimFile); SourceImageAttributes sourceImageAttributes = (SourceImageAttributes) ImageAttributes .fromJson(json); row.put("imageSize", Integer.toString(sourceImageAttributes.getWidth()) + " x " + Integer.toString(sourceImageAttributes.getHeight())); row.put("imageName", sourceImageAttributes.getImageName()); row.put("filename", sourceImageAttributes.getImageFilename()); } rows.add(row); } jsonServletResult.put("rows", rows); } catch (Throwable t) { jsonServletResult = new JSONServletResult(Status.ERROR, "Error! " + t.getMessage()); } return jsonServletResult; }
From source file:com.commander4j.thread.InboundMessageCollectionThread.java
private LinkedList<String> getInputFilename(String inputPath) { LinkedList<String> Result = new LinkedList<String>(); File dir;//from w w w. jav a 2 s . co m dir = new File(inputPath); chld = dir.listFiles((FileFilter) FileFileFilter.FILE); if (chld == null) { logger.debug("Specified directory does not exist or is not a directory. [" + inputPath + "]"); } else { Arrays.sort(chld, LastModifiedFileComparator.LASTMODIFIED_COMPARATOR); for (int i = 0; i < chld.length; i++) { fileName = chld[i].getName(); if (fileName.toLowerCase().endsWith(".xml")) { Result.addLast(fileName); } } } return Result; }
From source file:com.lightbox.android.bitmap.BitmapFileCleanerTask.java
private static List<File> getFilesSortedByLastModifiedReverse(File dir) { DebugLog.d(TAG, "starting getFilesSortedByLastModifiedReverse"); File[] filesArray = dir.listFiles(); Arrays.sort(filesArray, LastModifiedFileComparator.LASTMODIFIED_REVERSE); DebugLog.d(TAG, "finshed getFilesSortedByLastModifiedReverse"); return Arrays.asList(filesArray); }
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/* ww w . ja v a2 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:org.cleverbus.admin.services.log.LogParser.java
public File[] getLogFiles(final DateTime date) throws FileNotFoundException { File logFolder = new File(logFolderPath); if (!logFolder.exists() || !logFolder.canRead()) { throw new FileNotFoundException("there is no readable log folder - " + logFolderPath); }//from www.j a v a 2 s . c o m final String logDateFormatted = FILE_DATE_FORMAT.print(date); final long dateMillis = date.getMillis(); File[] files = logFolder.listFiles(new FileFilter() { @Override public boolean accept(File file) { String name = file.getName(); return name.endsWith(FILE_EXTENSION) // it's a log file && name.contains(logDateFormatted) // it contains the date in the name && file.lastModified() >= dateMillis; // and it's not older than the search date } }); Arrays.sort(files, LastModifiedFileComparator.LASTMODIFIED_COMPARATOR); if (files.length == 0) { Log.debug("No log files ending with {}, containing {}, modified after {}, at {}", FILE_EXTENSION, logDateFormatted, date, logFolderPath); } else { Log.debug("Found log files for {}: {}", date, files); } return files; }
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 ww w.j ava 2 s. c om*/ 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:de.alpharogroup.io.annotations.ImportResourcesUtils.java
/** * Gets a map with ImportResource objects and the corresponding to the found class from the * given package Name. The search is made recursive. The key from an entry of the map is the * class where the ImportResource objects found and the value is an Array of the ImportResource * objects that contains in the class./*from w w w .jav a 2 s. c o m*/ * * @param packageName * the package name * @return the import resources * @throws ClassNotFoundException * the class not found exception * @throws IOException * Signals that an I/O exception has occurred. */ public static Map<Class<?>, ImportResource[]> getImportResources(final String packageName) throws ClassNotFoundException, IOException { final Map<Class<?>, ImportResource[]> resourcesMap = new LinkedHashMap<>(); final Class<ImportResources> importResourcesClass = ImportResources.class; final Class<ImportResource> importResourceClass = ImportResource.class; final Set<Class<?>> importResourcesClasses = AnnotationUtils.getAllAnnotatedClasses(packageName, importResourcesClass); final Set<Class<?>> importResourceClasses = AnnotationUtils.getAllAnnotatedClasses(packageName, importResourceClass); importResourcesClasses.addAll(importResourceClasses); for (final Class<?> annotatedClass : importResourcesClasses) { final ImportResources importResources = annotatedClass.getAnnotation(ImportResources.class); ImportResource[] importResourcesArray = null; ImportResource[] importResourceArray = null; if (importResources != null) { importResourcesArray = importResources.resources(); } final ImportResource importResource = annotatedClass.getAnnotation(ImportResource.class); if (importResource != null) { importResourceArray = new ImportResource[1]; importResourceArray[0] = importResource; } final ImportResource[] array = (ImportResource[]) ArrayUtils.addAll(importResourceArray, importResourcesArray); Arrays.sort(array, new ImportResourceComparator()); resourcesMap.put(annotatedClass, array); } return resourcesMap; }
From source file:it.baywaylabs.jumpersumo.robot.Daemon.java
/** * This method is called when invoke <b>execute()</b>.<br /> * Do not invoke manually. Use: <i>new Daemon().execute("");</i> * * @param params blank string./*from w ww . ja va 2 s . c o m*/ * @return null if all is going ok. */ @Override protected String doInBackground(String... params) { while (folder.listFiles().length > 0) { // Select only files, no directory. File[] files = folder.listFiles((FileFilter) FileFileFilter.FILE); // Sorting following FIFO idea. Arrays.sort(files, LastModifiedFileComparator.LASTMODIFIED_REVERSE); if (files[0].getName().endsWith(".csv") || files[0].getName().endsWith(".txt")) { String commandsList = ""; try { commandsList = f.getStringFromFile(files[0].getPath()); } catch (Exception e) { e.printStackTrace(); } Log.e(TAG, "Lista comandi: " + commandsList); Interpreter in = new Interpreter(deviceController); in.doListCommands(commandsList); files[0].delete(); } else { Log.e(TAG, "Error: There is no csv|txt files or is not a file but a directory."); } } return null; }