List of usage examples for java.util Arrays sort
public static <T> void sort(T[] a, Comparator<? super T> c)
From source file:com.cloudera.oryx.als.computation.local.ReadInputs.java
private void readInput() throws IOException { File[] inputFiles = inputDir.listFiles(IOUtils.CSV_COMPRESSED_FILTER); if (inputFiles == null || inputFiles.length == 0) { log.info("No input files in {}", inputDir); return;/*from w w w. j a v a 2 s. c o m*/ } Arrays.sort(inputFiles, ByLastModifiedComparator.INSTANCE); for (File inputFile : inputFiles) { log.info("Reading {}", inputFile); for (CharSequence line : new FileLineIterable(inputFile)) { String[] columns = DelimitedDataUtils.decode(line); String userIDString = columns[0]; long userID = isInbound ? idMapping.add(userIDString) : Long.parseLong(userIDString); String itemIDString = columns[1]; long itemID = isInbound ? idMapping.add(itemIDString) : Long.parseLong(itemIDString); float value; if (columns.length > 2) { String valueToken = columns[2]; value = valueToken.isEmpty() ? Float.NaN : LangUtils.parseFloat(valueToken); } else { value = 1.0f; } if (Float.isNaN(value)) { // Remove, not set MatrixUtils.remove(userID, itemID, RbyRow, RbyColumn); } else { MatrixUtils.addTo(userID, itemID, value, RbyRow, RbyColumn); } if (knownItemIDs != null) { LongSet itemIDs = knownItemIDs.get(userID); if (Float.isNaN(value)) { // Remove, not set if (itemIDs != null) { itemIDs.remove(itemID); if (itemIDs.isEmpty()) { knownItemIDs.remove(userID); } } } else { if (itemIDs == null) { itemIDs = new LongSet(); knownItemIDs.put(userID, itemIDs); } itemIDs.add(itemID); } } } } }
From source file:$.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); }// w ww . j av a2 s .co 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:de.tudarmstadt.ukp.dkpro.core.api.datasets.internal.LoadedDataset.java
@Override public File[] getDataFiles() { Set<File> all = new HashSet<>(); // Collect all data files all.addAll(asList(getFiles(FileRole.DATA))); // If no files are marked as data files, try aggregating over test/dev/train sets if (all.isEmpty()) { Split split = getDefaultSplit(); if (split != null) { all.addAll(asList(split.getTrainingFiles())); all.addAll(asList(split.getTestFiles())); all.addAll(asList(split.getDevelopmentFiles())); }// w w w . j ava 2 s .c o m } // Sort to ensure stable order File[] result = all.toArray(all.toArray(new File[all.size()])); Arrays.sort(result, (a, b) -> { return a.getPath().compareTo(b.getPath()); }); return result; }
From source file:com.codebutler.farebot.transit.orca.OrcaTransitFactory.java
@NonNull private static List<Trip> parseTrips(@NonNull DesfireCard card) { List<Trip> trips = new ArrayList<>(); DesfireFile file = card.getApplication(0x3010f2).getFile(0x02); if (file instanceof RecordDesfireFile) { RecordDesfireFile recordFile = (RecordDesfireFile) card.getApplication(0x3010f2).getFile(0x02); OrcaTrip[] useLog = new OrcaTrip[recordFile.getRecords().size()]; for (int i = 0; i < useLog.length; i++) { useLog[i] = OrcaTrip.create(recordFile.getRecords().get(i)); }/* w ww.jav a 2 s. c o m*/ Arrays.sort(useLog, new Trip.Comparator()); ArrayUtils.reverse(useLog); for (int i = 0; i < useLog.length; i++) { OrcaTrip trip = useLog[i]; OrcaTrip nextTrip = (i + 1 < useLog.length) ? useLog[i + 1] : null; if (isSameTrip(trip, nextTrip)) { trips.add(MergedOrcaTrip.create(trip, nextTrip)); i++; continue; } trips.add(trip); } } Collections.sort(trips, new Trip.Comparator()); return trips; }
From source file:com.alibaba.napoli.client.util.NapoliTestUtil.java
/** * ????//from w w w . ja v a2s .com * * @param list */ public static void sortFile(final File[] list) { Arrays.sort(list, new Comparator<File>() { public int compare(final File f1, final File f2) { return f1.getName().compareTo(f2.getName()); } }); }
From source file:com.jkoolcloud.tnt4j.streams.inputs.HdfsFileLineStream.java
/** * Searches for files matching name pattern. Name pattern also may contain path of directory, where file search * should be performed, e.g., C:/Tomcat/logs/localhost_access_log.*.txt. If no path is defined (just file name * pattern) then files are searched in {@code System.getProperty("user.dir")}. Files array is ordered by file create * timestamp in descending order./* ww w .j a v a 2 s . c om*/ * * @param path * path of file * @param fs * file system * * @return array of found files paths. * @throws IOException * if files can't be listed by file system. * * @see FileSystem#listStatus(Path, PathFilter) * @see FilenameUtils#wildcardMatch(String, String, IOCase) */ public static Path[] searchFiles(Path path, FileSystem fs) throws IOException { FileStatus[] dir = fs.listStatus(path.getParent(), new PathFilter() { @Override public boolean accept(Path path) { String name = path.getName(); return FilenameUtils.wildcardMatch(name, "*", IOCase.INSENSITIVE); // NON-NLS } }); Path[] activityFiles = new Path[dir == null ? 0 : dir.length]; if (dir != null) { Arrays.sort(dir, new Comparator<FileStatus>() { @Override public int compare(FileStatus o1, FileStatus o2) { return Long.valueOf(o1.getModificationTime()).compareTo(o2.getModificationTime()) * (-1); } }); for (int i = 0; i < dir.length; i++) { activityFiles[i] = dir[i].getPath(); } } return activityFiles; }
From source file:mml.handler.get.MMLGetImgHandler.java
/** * Create the list of images//from w w w. j ava2 s . com * @param req the http request * @param map the page reference to dimensions map * @return the images as a sequence of IMGs inside divs */ String createImgs(HttpServletRequest req, HashMap<String, String> map) { Element images = new Element("div"); images.addAttribute("id", "images"); Set<String> keys = map.keySet(); String[] names = new String[keys.size()]; keys.toArray(names); if (pageRefs == null) { ImageComparator comp = new ImageComparator(); Arrays.sort(names, comp); } else { names = sortByPageRefs(names); } for (String name : names) { String jDoc = map.get(name); JSONObject info = (JSONObject) JSONValue.parse(jDoc); Element wrap = new Element("div"); wrap.addAttribute("class", "image"); Element img = new Element("img"); String jDocId = (String) info.get(JSONKeys.DOCID); String src = "/" + jDocId; img.addAttribute("src", src); img.addAttribute("id", "image_" + name); //String mimetype = (String)info.get("mimetype"); int width = ((Number) info.get("width")).intValue(); int height = ((Number) info.get("height")).intValue(); img.addAttribute("style", "width: 100%; max-width: " + width + "px"); img.addAttribute("data-width", Integer.toString(width)); img.addAttribute("data-height", Integer.toString(height)); img.addAttribute("data-ref", name); wrap.addChild(img); images.addChild(wrap); } return images.toString(); }
From source file:org.cloudfoundry.identity.uaa.scim.DefaultPasswordValidator.java
@Override public void validate(String password, ScimUser user) throws InvalidPasswordException { List<Rule> rules;/*from w w w . j a v a 2s. c om*/ PasswordData passwordData = new PasswordData(new Password(password)); passwordData.setUsername(user.getUserName()); // Build dictionary rule based on Scim data rules = new ArrayList<Rule>(defaultRules); if (password.length() < 20) { // Check sequences only in "short" passwords (see CFID-221) rules.addAll(shortRules); } String[] userWords = user.wordList().toArray(new String[user.wordList().size()]); Arrays.sort(userWords, WordLists.CASE_INSENSITIVE_COMPARATOR); rules.add(new DictionarySubstringRule(new WordListDictionary(new ArrayWordList(userWords, false)))); edu.vt.middleware.password.PasswordValidator validator = new edu.vt.middleware.password.PasswordValidator( rules); RuleResult result = validator.validate(passwordData); if (!result.isValid()) { String errors = StringUtils.collectionToDelimitedString(validator.getMessages(result), ","); throw new InvalidPasswordException(errors); } }
From source file:com.Da_Technomancer.crossroads.API.packets.Message.java
private static Field[] getClassFields(Class<?> clazz) { if (fieldCache.containsValue(clazz)) return fieldCache.get(clazz); else {/*from w w w.j a va 2s . c om*/ Field[] fields = clazz.getFields(); Arrays.sort(fields, (Field f1, Field f2) -> { return f1.getName().compareTo(f2.getName()); }); fieldCache.put(clazz, fields); return fields; } }
From source file:com.psaravan.filebrowserview.lib.FileBrowserEngine.FileBrowserEngine.java
/** * Loads the specified folder.// w w w. j a v a2s . co m * * @param directory The file object to points to the directory to load. * @return An {@link AdapterData} object that holds the data of the specified directory. */ public AdapterData loadDir(File directory) { mCurrentDir = directory; //Init the directory's data arrays. ArrayList<String> namesList = new ArrayList<String>(); ArrayList<String> pathsList = new ArrayList<String>(); ArrayList<Integer> typesList = new ArrayList<Integer>(); ArrayList<String> sizesList = new ArrayList<String>(); //Grab a list of all files/subdirs within the specified directory. File[] files = directory.listFiles(); if (files != null) { //Sort the files/subdirs by name. Arrays.sort(files, NameFileComparator.NAME_INSENSITIVE_COMPARATOR); for (int i = 0; i < files.length; i++) { File file = files[i]; if ((!file.isHidden() || mFileBrowserView.shouldShowHiddenFiles()) && file.canRead()) { if (file.isDirectory() && mFileBrowserView.shouldShowFolders()) { /* * Starting with Android 4.2, /storage/emulated/legacy/... * is a symlink that points to the actual directory where * the user's files are stored. We need to detect the * actual directory's file path here. */ String filePath; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) filePath = getRealFilePath(file.getAbsolutePath()); else filePath = file.getAbsolutePath(); pathsList.add(filePath); namesList.add(file.getName()); File[] listOfFiles = file.listFiles(); if (listOfFiles != null) { typesList.add(FOLDER); if (listOfFiles.length == 1) { sizesList.add("" + listOfFiles.length + " item"); } else { sizesList.add("" + listOfFiles.length + " items"); } } else { typesList.add(FOLDER); sizesList.add("Unknown items"); } } else { try { String path = file.getCanonicalPath(); //Check if the file ends with an excluded extension. String[] splits = path.split("."); if (mFileBrowserView.getFileExtensionFilter().getFilterMap() .containsKey("." + splits[splits.length - 1])) continue; pathsList.add(path); } catch (IOException e) { continue; } namesList.add(file.getName()); String fileName = ""; try { fileName = file.getCanonicalPath(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } //Add the file element to typesList based on the file type. if (getFileExtension(fileName).equalsIgnoreCase("mp3") || getFileExtension(fileName).equalsIgnoreCase("3gp") || getFileExtension(fileName).equalsIgnoreCase("mp4") || getFileExtension(fileName).equalsIgnoreCase("m4a") || getFileExtension(fileName).equalsIgnoreCase("aac") || getFileExtension(fileName).equalsIgnoreCase("ts") || getFileExtension(fileName).equalsIgnoreCase("flac") || getFileExtension(fileName).equalsIgnoreCase("mid") || getFileExtension(fileName).equalsIgnoreCase("xmf") || getFileExtension(fileName).equalsIgnoreCase("mxmf") || getFileExtension(fileName).equalsIgnoreCase("midi") || getFileExtension(fileName).equalsIgnoreCase("rtttl") || getFileExtension(fileName).equalsIgnoreCase("rtx") || getFileExtension(fileName).equalsIgnoreCase("ota") || getFileExtension(fileName).equalsIgnoreCase("imy") || getFileExtension(fileName).equalsIgnoreCase("ogg") || getFileExtension(fileName).equalsIgnoreCase("mkv") || getFileExtension(fileName).equalsIgnoreCase("wav")) { //The file is an audio file. typesList.add(FILE_AUDIO); sizesList.add("" + getFormattedFileSize(file.length())); } else if (getFileExtension(fileName).equalsIgnoreCase("jpg") || getFileExtension(fileName).equalsIgnoreCase("gif") || getFileExtension(fileName).equalsIgnoreCase("png") || getFileExtension(fileName).equalsIgnoreCase("bmp") || getFileExtension(fileName).equalsIgnoreCase("webp")) { //The file is a picture file. typesList.add(FILE_PICTURE); sizesList.add("" + getFormattedFileSize(file.length())); } else if (getFileExtension(fileName).equalsIgnoreCase("3gp") || getFileExtension(fileName).equalsIgnoreCase("mp4") || getFileExtension(fileName).equalsIgnoreCase("3gp") || getFileExtension(fileName).equalsIgnoreCase("ts") || getFileExtension(fileName).equalsIgnoreCase("webm") || getFileExtension(fileName).equalsIgnoreCase("mkv")) { //The file is a video file. typesList.add(FILE_VIDEO); sizesList.add("" + getFormattedFileSize(file.length())); } else { //We don't have an icon for this file type so give it the generic file flag. typesList.add(FILE_GENERIC); sizesList.add("" + getFormattedFileSize(file.length())); } } } } } return new AdapterData(namesList, typesList, pathsList, sizesList); }