List of usage examples for java.util ArrayList sort
@Override @SuppressWarnings("unchecked") public void sort(Comparator<? super E> c)
From source file:com.netflix.genie.web.jobs.workflow.impl.InitialSetupTask.java
/** * Helper to convert a set of tags into a string that is a suitable value for a shell environment variable. * Adds double quotes as necessary (i.e. in case of spaces, newlines), performs escaping of in-tag quotes. * Input tags are sorted to produce a deterministic output value. * * @param tags a set of tags or null//from w w w.j a v a 2s . c o m * @return a CSV string */ @VisibleForTesting String tagsToString(final Set<String> tags) { final ArrayList<String> sortedTags = new ArrayList<>(tags == null ? Collections.emptySet() : tags); // Sort tags for the sake of determinism (e.g., tests) sortedTags.sort(Comparator.naturalOrder()); final String joinedString = StringUtils.join(sortedTags, ','); // Escape quotes return RegExUtils.replaceAll(RegExUtils.replaceAll(joinedString, "\'", "\\\'"), "\"", "\\\""); }
From source file:com.thoughtworks.go.server.service.dd.FanInGraph.java
private StageIdFaninScmMaterialPair getSmallestScmRevision( Collection<StageIdFaninScmMaterialPair> scmWithDiffVersions) { ArrayList<StageIdFaninScmMaterialPair> materialPairList = new ArrayList<>(scmWithDiffVersions); materialPairList.sort((pair1, pair2) -> { final PipelineTimelineEntry.Revision rev1 = pair1.faninScmMaterial.revision; final PipelineTimelineEntry.Revision rev2 = pair2.faninScmMaterial.revision; return rev1.date.compareTo(rev2.date); });/* ww w.j ava 2s. c o m*/ return materialPairList.get(0); }
From source file:org.sandsoft.tests.Tester.java
public static String ModeListGenerator() { try {// w w w .j av a 2 s. c o m StringBuilder sb = new StringBuilder(); ArrayList<String> support = new ArrayList<>(); ArrayList<String> modenames = new ArrayList<>(); String text = org.apache.commons.io.IOUtils .toString(org.sandsoft.acefx.AceEditor.class.getResourceAsStream("ace/ext-modelist.js")); int ind = text.indexOf("var supportedModes"); String whole = text.substring(text.indexOf("{", ind) + 1, text.indexOf("};", ind)); whole = whole.replace("\r", " ").replace("\n", " ").replace(" ", " "); for (String line : whole.split(",")) { if (line.isEmpty() || !line.contains(":") || !line.contains("[")) { continue; } String name = line.substring(0, line.indexOf(":")).trim(); String data = line.substring(line.indexOf("\"") + 1, line.lastIndexOf("\"")); modenames.add(name); sb.append("public static final ModeData ").append(name); sb.append(" = new ModeData(\"").append(name.replace("_", " ")).append("\", "); sb.append("\"ace/mode/").append(name.toLowerCase()).append("\""); //alias sb.append(", \"").append(data).append("\");\n"); } support.sort(STRING_COMP); int cnt = 1; sb.append("\npublic static final ModeData[] SUPPORTED_MODES = {\n"); for (String key : modenames) { if (cnt++ % 8 == 0) { sb.append("\n"); } sb.append(key).append(", "); } sb.append("\n};\n"); return sb.toString(); } catch (Exception ex) { return ex.getMessage(); } }
From source file:org.bonej.wrapperPlugins.AnalyseSkeletonWrapper.java
private void showAdditionalResults(final SkeletonResult results) { if (!verbose) { return;//w w w . j av a2s . co m } final DefaultGenericTable table = new DefaultGenericTable(); final List<PrimitiveColumn<?, ?>> columns = Arrays.asList(new IntColumn("# Skeleton"), new IntColumn("# Branch"), new DoubleColumn("Branch length"), new IntColumn("V1 x"), new IntColumn("V1 y"), new IntColumn("V1 z"), new IntColumn("V2 x"), new IntColumn("V2 y"), new IntColumn("V2 z"), new DoubleColumn("Euclidean distance"), new DoubleColumn("running average length"), new DoubleColumn("average intensity (inner 3rd)"), new DoubleColumn("average intensity")); final Graph[] graphs = results.getGraph(); for (int i = 0; i < graphs.length; i++) { final ArrayList<Edge> edges = graphs[i].getEdges(); // Sort into descending order by length edges.sort((a, b) -> -Double.compare(a.getLength(), b.getLength())); for (int j = 0; j < edges.size(); j++) { final Edge edge = edges.get(j); ((IntColumn) columns.get(0)).add((i + 1)); ((IntColumn) columns.get(1)).add((j + 1)); ((DoubleColumn) columns.get(2)).add((edge.getLength())); final Point point = edge.getV1().getPoints().get(0); ((IntColumn) columns.get(3)).add((point.x)); ((IntColumn) columns.get(4)).add((point.y)); ((IntColumn) columns.get(5)).add((point.z)); final Point point2 = edge.getV2().getPoints().get(0); ((IntColumn) columns.get(6)).add((point2.x)); ((IntColumn) columns.get(7)).add((point2.y)); ((IntColumn) columns.get(8)).add((point2.z)); final double distance = MathArrays.distance(new double[] { point.x, point.y, point.z }, new double[] { point2.x, point2.y, point2.z }); ((DoubleColumn) columns.get(9)).add((distance)); ((DoubleColumn) columns.get(10)).add((edge.getLength_ra())); ((DoubleColumn) columns.get(11)).add((edge.getColor3rd())); ((DoubleColumn) columns.get(12)).add((edge.getColor())); } } table.addAll(columns); if (!table.isEmpty()) { verboseTable = table; } }
From source file:parsers.ClueWebContentSource.java
@Override public void setConfig(Config config) { super.setConfig(config); // dirs// w w w .j av a 2 s .c om File workDir = new File(config.get("work.dir", "work")); String d = config.get("docs.dir", "trec"); dataDir = new File(d); if (!dataDir.isAbsolute()) { dataDir = new File(workDir, d); } try { // files: accept only WARC files ArrayList<Path> tmpp = new ArrayList<Path>(); collectFiles(dataDir.toPath(), tmpp); ArrayList<File> tmpf = new ArrayList<File>(); for (Path p : tmpp) if (p.toString().endsWith("warc.gz")) { tmpf.add(p.toFile()); } else { System.out.println("Ignoring file: " + p); } tmpf.sort(new PathFileComparator()); for (File f : tmpf) { inputFiles.add(f.toPath()); System.out.println(f); } if (inputFiles.size() == 0) { throw new IllegalArgumentException("No files in dataDir: " + dataDir); } // html parser String htmlParserClassName = config.get("html.parser", "org.apache.lucene.benchmark.byTask.feeds.DemoHTMLParser"); htmlParser = Class.forName(htmlParserClassName).asSubclass(HTMLParser.class).newInstance(); } catch (Exception e) { // Should not get here. Throw runtime exception. throw new RuntimeException(e); } verbose = true; }
From source file:springfirst.MapController.java
@RequestMapping("/nearby") @ResponseBody/* w ww .j a va2 s . c o m*/ public ArrayList<Location> nearby(@RequestParam(value = "x") float x, @RequestParam(value = "y") float y) { float y2 = Math.abs(y) - _longitudeAdjust; float x2 = x - _latitudeAdjust; float[] dimensions = new float[] { _latitudeSquare, _longitudeSquare }; float[] coords = new float[] { x2, y2 }; ArrayList<Location> data = MapService.search(coords, dimensions); while (data.size() < 10) { //TODO: adjust the coordinates dimensions[0] += _latitudeSquare; dimensions[1] += _longitudeSquare; coords[0] -= _latitudeAdjust; coords[1] -= _longitudeAdjust; data = MapService.search(coords, dimensions); } for (Location loc : data) { loc.setDistance(x, y); } data.sort(null); return data; }
From source file:sh.isaac.api.IsaacTaxonomy.java
/** * Export java binding./*from w ww .java 2s . com*/ * * @param out the out * @param packageName the package name * @param className the class name * @throws IOException Signals that an I/O exception has occurred. */ public void exportJavaBinding(Writer out, String packageName, String className) throws IOException { out.append("package " + packageName + ";\n"); out.append("\n\nimport sh.isaac.api.component.concept.ConceptSpecification;\n"); out.append("import sh.isaac.api.ConceptProxy;\n"); out.append("import java.util.UUID;\n"); out.append("\n\npublic class " + className + " {\n"); ArrayList<String> constantList = new ArrayList<>(); ArrayList<ConceptBuilder> sortedBuilders = new ArrayList<>(this.conceptBuildersInInsertionOrder); sortedBuilders.sort((o1, o2) -> { return o1.getFullySpecifiedDescriptionBuilder().getDescriptionText() .compareTo(o2.getFullySpecifiedDescriptionBuilder().getDescriptionText()); }); for (final ConceptBuilder concept : sortedBuilders) { final String preferredName = concept.getFullySpecifiedDescriptionBuilder().getDescriptionText(); String constantName = preferredName.toUpperCase(); constantName = constantName.replace(".", ""); constantName = constantName.replace(",", ""); constantName = constantName.replace("", ""); constantName = constantName.replace("", "C"); constantName = constantName.replace("(", "___"); constantName = constantName.replace(")", ""); constantName = constantName.replace(" ", "_"); constantName = constantName.replace("-", "_"); constantName = constantName.replace("+", "_PLUS"); constantName = constantName.replace("/", "_AND_OR_"); out.append("\n\n /** Java binding for the concept described as <strong><em>" + preferredName + "</em></strong>;\n * identified by UUID: {@code \n * " + "<a href=\"http://localhost:8080/terminology/rest/concept/" + concept.getPrimordialUuid() + "\">\n * " + concept.getPrimordialUuid() + "</a>}.*/"); constantList.add(constantName); out.append("\n public static final ConceptSpecification " + constantName + " ="); out.append("\n new ConceptProxy(\"" + preferredName + "\""); for (final UUID uuid : concept.getUuidList()) { out.append(", UUID.fromString(\"" + uuid.toString() + "\")"); } out.append(");"); } out.append("\n\n public static final ConceptSpecification[] META_DATA_CONCEPTS = {\n"); Collections.sort(constantList); for (int i = 0; i < constantList.size(); i++) { String constant = constantList.get(i); if (i != constantList.size() - 1) { out.append(" ").append(constant).append(",\n"); } else { out.append(" ").append(constant).append("\n"); } } out.append(" };"); out.append("\n}\n"); out.close(); }
From source file:org.kitodo.production.helper.metadata.ImageHelper.java
/** * Get data files. First read them all and next if their size is bigger than * zero sort them with use of GoobiImageFileComparator. * * @param process//from www. ja v a2 s. co m * Process object * @return list of URIs */ public List<URI> getDataFiles(Process process) throws InvalidImagesException { URI dir; try { dir = ServiceManager.getProcessService().getImagesTifDirectory(true, process.getId(), process.getTitle(), process.getProcessBaseUri()); } catch (RuntimeException e) { throw new InvalidImagesException(e); } /* Verzeichnis einlesen */ ArrayList<URI> dataList = new ArrayList<>(); List<URI> files = fileService.getSubUris(dataFilter, dir); if (!files.isEmpty()) { dataList.addAll(files); dataList.sort(new MetadataImageComparator()); } return dataList; }
From source file:net.dv8tion.jda.core.entities.impl.GuildImpl.java
@Override public List<TextChannel> getTextChannels() { ArrayList<TextChannel> channels = new ArrayList<>(textChannels.valueCollection()); channels.sort(Comparator.reverseOrder()); return Collections.unmodifiableList(channels); }
From source file:org.sandsoft.tests.Tester.java
public static String ThemeListGenerator() { try {//w w w. j a v a 2 s. co m StringBuilder sb = new StringBuilder(); ArrayList<String> names = new ArrayList<>(); ArrayList<String> alias = new ArrayList<>(); String text = org.apache.commons.io.IOUtils .toString(org.sandsoft.acefx.AceEditor.class.getResourceAsStream("ace/ext-themelist.js")); int ind = text.indexOf("var themeData"); String whole = text.substring(text.indexOf("[", ind) + 1, text.indexOf("];", ind)); whole = whole.replace("\r", " ").replace("\n", " ").replace(" ", " "); for (String line : whole.split("],")) { if (line.isEmpty() || !line.contains("[")) { continue; } String tt = line.replace("[", "").replace("]", "").replace("\"", "").trim(); String[] data = tt.split(","); String name; String als = "ace/theme/"; boolean dark = false; if (data.length > 1) { name = data[0].trim(); als += data[1].trim(); dark = data[2].trim().contains("dark"); } else { name = data[0].trim(); als += name.toLowerCase().replace(" ", "_"); } String var = name.replace(" ", "_"); sb.append(" public static final ThemeData " + var + " = new ThemeData(\"" + name + "\", " + "\"" + als + "\", " + (dark ? "true" : "false") + ");\n"); names.add(var); alias.add(als); } names.sort(STRING_COMP); alias.sort(STRING_COMP); int cnt = 1; sb.append("\npublic static final ThemeData[] SUPPORTED_THEMES = { \n"); for (String term : names) { sb.append(term).append(", "); if (cnt++ % 8 == 0) { sb.append("\n"); } } sb.append("};\n"); sb.append("\npublic static final String[] ALIAS_LIST = { \n"); for (String term : alias) { sb.append("\"").append(term).append("\", \n"); } sb.append("};\n"); return sb.toString(); } catch (Exception ex) { return ex.getMessage(); } }