List of usage examples for java.lang Integer compare
public static int compare(int x, int y)
From source file:uni.bielefeld.cmg.sparkhit.util.HelpParam.java
public void printDecompresserHelp() { HelpFormatter formatter = new HelpFormatter(); formatter.setOptionComparator(new Comparator<Option>() { public int compare(Option o1, Option o2) { return Integer.compare(parameterMap.get(o1.getOpt()), parameterMap.get(o2.getOpt())); }// www .j ava 2 s .c o m }); final String executable = System.getProperty("executable", "spark-submit [spark parameter] --class uni.bielefeld.cmg.sparkhit.main.MainOfPiper Sparkhit.jar"); err.println("Name:"); err.println("\tSparkHit Decompresser"); err.println(); err.println("Options:"); formatter.printOptions(new PrintWriter(err, true), 85, parameter, 2, 3); /* print formatted parameters */ err.println(); err.println("Usage:"); err.println("\tDecomress zipball and tarball using spark codec:"); err.println(executable + " [parameters] -fastq genotype.vcf -outfile ./decompressed"); err.println(); }
From source file:org.mitre.mpf.interop.JsonTrackOutputObject.java
@Override public int compareTo(JsonTrackOutputObject other) { int result = 0; if (other == null) { return 0; } else if ((result = Integer.compare(startOffsetFrame, other.startOffsetFrame)) != 0 || (result = Integer.compare(stopOffsetFrame, other.stopOffsetFrame)) != 0 || (result = Integer.compare(startOffsetTime, other.startOffsetTime)) != 0 || (result = Integer.compare(stopOffsetTime, other.stopOffsetTime)) != 0 || (result = ObjectUtils.compare(type, other.type, false)) != 0 || (result = ObjectUtils.compare(source, other.source, false)) != 0 || (result = ObjectUtils.compare(id, other.id, false)) != 0) { return result; } else {/* ww w .j av a 2s .c om*/ return 0; } }
From source file:forge.itemmanager.views.ItemListView.java
@Override public void setup(final ItemManagerConfig config, final Map<ColumnDef, ItemTableColumn> colOverrides) { final Iterable<T> selectedItemsBefore = getSelectedItems(); final DefaultTableColumnModel colmodel = new DefaultTableColumnModel(); //ensure columns ordered properly final List<ItemTableColumn> columns = new LinkedList<ItemTableColumn>(); for (final ItemColumnConfig colConfig : config.getCols().values()) { if (colOverrides == null || !colOverrides.containsKey(colConfig.getDef())) { columns.add(new ItemTableColumn(new ItemColumn(colConfig))); } else {/*from w ww . j a v a2s .com*/ columns.add(colOverrides.get(colConfig.getDef())); } } Collections.sort(columns, new Comparator<ItemTableColumn>() { @Override public int compare(final ItemTableColumn arg0, final ItemTableColumn arg1) { return Integer.compare(arg0.getIndex(), arg1.getIndex()); } }); //hide table header if only showing single string column final boolean hideHeader = (config.getCols().size() == 1 && config.getCols().containsKey(ColumnDef.STRING)); getPnlOptions().removeAll(); if (config.getShowUniqueCardsOption()) { final FCheckBox chkBox = new FCheckBox("Unique Cards Only", this.itemManager.getWantUnique()); chkBox.setFont(ROW_FONT); chkBox.setToolTipText("Toggle whether to show unique cards only"); chkBox.addChangeListener(new ChangeListener() { @Override public void stateChanged(final ChangeEvent arg0) { final boolean wantUnique = chkBox.isSelected(); if (itemManager.getWantUnique() == wantUnique) { return; } itemManager.setWantUnique(wantUnique); itemManager.refresh(); if (itemManager.getConfig() != null) { itemManager.getConfig().setUniqueCardsOnly(wantUnique); } } }); getPnlOptions().add(chkBox); } int modelIndex = 0; for (final ItemTableColumn col : columns) { col.setModelIndex(modelIndex++); if (col.isVisible()) { colmodel.addColumn(col); } if (!hideHeader) { final FCheckBox chkBox = new FCheckBox( StringUtils.isEmpty(col.getShortName()) ? col.getLongName() : col.getShortName(), col.isVisible()); chkBox.setFont(ROW_FONT); chkBox.setToolTipText(col.getLongName()); chkBox.addChangeListener(new ChangeListener() { @Override public void stateChanged(final ChangeEvent arg0) { final boolean visible = chkBox.isSelected(); if (col.isVisible() == visible) { return; } col.setVisible(visible); if (col.isVisible()) { colmodel.addColumn(col); //move column into proper position final int oldIndex = colmodel.getColumnCount() - 1; int newIndex = col.getIndex(); for (int i = 0; i < col.getIndex(); i++) { if (!columns.get(i).isVisible()) { newIndex--; } } if (newIndex < oldIndex) { colmodel.moveColumn(oldIndex, newIndex); } } else { colmodel.removeColumn(col); } ItemManagerConfig.save(); } }); getPnlOptions().add(chkBox); } } if (hideHeader) { this.table.getTableHeader().setPreferredSize(new Dimension(0, 0)); } else { this.table.getTableHeader().setPreferredSize(new Dimension(0, ROW_HEIGHT)); } this.tableModel.addListeners(); this.table.setModel(this.tableModel); this.table.setColumnModel(colmodel); this.tableModel.setup(); this.refresh(selectedItemsBefore, 0, 0); }
From source file:edu.ucla.cs.scai.canali.core.index.utils.DBpediaOntologyExtendedUtils.java
public HashSet<String> createClassParentsFile() throws Exception { System.out.println("Saving class parents"); HashSet<String> classes = new HashSet<>(); try (PrintWriter out = new PrintWriter(new FileOutputStream(destinationPath + "class_parents", false), true)) {/*from ww w .j ava 2s. c om*/ StmtIterator stmts = dbpedia.listStatements(null, RDFS.subClassOf, (RDFNode) null); while (stmts.hasNext()) { Statement stmt = stmts.next(); out.println(stmt.getSubject() + "\t" + stmt.getObject()); classes.add(stmt.getSubject().toString()); } //now process Yago classes //first find the frequency of each class HashMap<String, Integer> classCount = new HashMap<>(); try (BufferedReader in = new BufferedReader(new FileReader(downloadedFilesPath + "yago_types.nt"))) { String l = in.readLine(); String regex = "<(.*)> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <(.*)>"; Pattern p = Pattern.compile(regex); while (l != null) { Matcher m = p.matcher(l); if (m.find()) { String cUri = m.group(2); Integer c = classCount.get(cUri); if (c == null) { classCount.put(cUri, 1); } else { classCount.put(cUri, c + 1); } } l = in.readLine(); } in.close(); } ArrayList<Map.Entry<String, Integer>> a = new ArrayList<>(classCount.entrySet()); Collections.sort(a, new Comparator<Map.Entry<String, Integer>>() { @Override public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) { return Integer.compare(o2.getValue(), o1.getValue()); } }); for (int i = 0; i < a.size(); i++) { if (/*i < a.size() / 10 ||*/yagoClasses.contains(a.get(i).getKey())) { classes.add(a.get(i).getKey()); } } try (BufferedReader in = new BufferedReader(new FileReader(downloadedFilesPath + "yago_taxonomy.nt"))) { String l = in.readLine(); String regex = "(\\s*)<(.*)> <http://www.w3.org/2000/01/rdf-schema#subClassOf> <(.*)>"; Pattern p = Pattern.compile(regex); while (l != null) { Matcher m = p.matcher(l); if (m.find()) { String aUri = m.group(2); String bUri = m.group(3); if (classes.contains(aUri) && classes.contains(bUri)) { out.println(aUri + "\t" + bUri); } } l = in.readLine(); } in.close(); } } return classes; }
From source file:com.example.mediastock.util.Utilities.java
/** * Find most represented swatch of the palette, based on population. *//*ww w . ja v a 2 s .c o m*/ public static Palette.Swatch getDominantSwatch(Palette palette) { return Collections.max(palette.getSwatches(), new Comparator<Palette.Swatch>() { @Override public int compare(Palette.Swatch sw1, Palette.Swatch sw2) { return Integer.compare(sw1.getPopulation(), sw2.getPopulation()); } }); }
From source file:org.mitre.mpf.interop.JsonDetectionOutputObject.java
private int compareMap(SortedMap<String, String> map1, SortedMap<String, String> map2) { if (map1 == null && map2 == null) { return 0; } else if (map1 == null) { return -1; } else if (map2 == null) { return 1; } else {//from ww w . j av a2s. c o m int result = 0; if ((result = Integer.compare(map1.size(), map2.size())) != 0) { return result; } StringBuilder map1Str = new StringBuilder(); for (String key : map1.keySet()) { map1Str.append(key).append(map1.get(key)); } StringBuilder map2Str = new StringBuilder(); for (String key : map2.keySet()) { map2Str.append(key).append(map2.get(key)); } if ((result = ObjectUtils.compare(map1Str.toString(), map2Str.toString())) != 0) { return result; } } return 0; }
From source file:fr.univnantes.lina.UIMAProfiler.java
@Override public void display(PrintStream stream) { if (isEmpty()) return;//from w w w . j a v a2s . com stream.println( "###########################################################################################"); stream.println( "#################################### " + this.name + " ####################################"); stream.println( "###########################################################################################"); String formatString = "%30s %10sms\n"; if (!tasks.isEmpty()) { stream.println("--------------- Tasks --------------"); for (String taskName : tasks.keySet()) { long t = 0; for (ProfilingTask task : tasks.get(taskName)) t += task.getTotal(); stream.format(formatString, taskName, t); } stream.format(formatString, "TOTAL", getTotal()); } if (!counters.isEmpty()) { stream.println("--------------- Hits ------------------"); formatString = "%30s %10s\n"; long total = 0; Comparator<String> comp = new Comparator<String>() { @Override public int compare(String o1, String o2) { return Integer.compare(counters.get(o2).intValue(), counters.get(o1).intValue()); } }; List<String> sortedkeys = new LinkedList<String>(); sortedkeys.addAll(counters.keySet()); Collections.sort(sortedkeys, comp); for (String hitName : sortedkeys) { int h = counters.get(hitName).intValue(); total += h; stream.format(formatString, hitName, h); } stream.format(formatString, "TOTAL", total); if (latexFormat) { stream.println("--------------- Hits (Latex) ----------"); total = 0; sortedkeys = new LinkedList<String>(); sortedkeys.addAll(counters.keySet()); Collections.sort(sortedkeys, comp); for (String hitName : sortedkeys) { int h = counters.get(hitName).intValue(); total += h; stream.println(hitName + " & " + counters.get(hitName).intValue() + " \\\\"); } stream.println("TOTAL & " + total + " \\\\"); } } if (!examples.isEmpty()) { stream.println("-------------- Examples ---------------"); List<String> keySet = Lists.newArrayList(examples.keySet()); Collections.shuffle(keySet); for (String hitName : keySet) { int i = 0; stream.println("* " + hitName); for (Object o : examples.get(hitName)) { i++; if (i > exampleLimit) break; String str = o == null ? "null" : o.toString().replaceAll("\n", " ").replaceAll("\r", " ").toLowerCase(); stream.println("\t" + str); } } } if (!pointStatus.isEmpty()) { stream.println("-------------- Point status -----------"); for (String point : pointStatus.keySet()) { stream.println(point + ": " + pointStatus.get(point)); } } stream.flush(); }
From source file:org.projectbuendia.client.models.ObsValue.java
/** * Compares ObsValue instances according to a total ordering such that: * - All non-null values are greater than null. * - The lowest value is the "false" Boolean value (encoded as the coded concept for "No"). * - Next are all coded values, ordered from least severe to most severe (if they can * be interpreted as having a severity); or from first to last (if they can * be interpreted as having a typical temporal sequence). * - Next is the "true" Boolean value (encoded as the coded concept for "Yes"). * - Next are all numeric values, ordered from least to greatest. * - Next are all text values, ordered lexicographically from A to Z. * - Next are all date values, ordered from least to greatest. * - Next are all instant values, ordered from least to greatest. * @param other The other Value to compare to. * @return//w ww .j a v a2s . c om */ @Override public int compareTo(@Nullable ObsValue other) { if (other == null) return 1; int result = 0; result = Integer.compare(getTypeOrdering(), other.getTypeOrdering()); if (result != 0) return result; if (uuid != null) { result = Integer.compare(getUuidOrdering(), other.getUuidOrdering()); if (result != 0) return result; result = uuid.compareTo(other.uuid); } else if (number != null) { result = Double.compare(number, other.number); } else if (text != null) { result = text.compareTo(other.text); } else if (date != null) { result = date.compareTo(other.date); } else if (instant != null) { result = instant.compareTo(other.instant); } return result; }
From source file:com.evolveum.midpoint.model.api.util.EvaluatedPolicyRuleUtil.java
private static <AD extends AdditionalData> void sortTriggersExt(TreeNode<AugmentedTrigger<AD>> node) { Comparator<? super TreeNode<AugmentedTrigger<AD>>> comparator = (t1, t2) -> { int o1 = defaultIfNull(t1.getUserObject().trigger.getPresentationOrder(), Integer.MAX_VALUE); int o2 = defaultIfNull(t2.getUserObject().trigger.getPresentationOrder(), Integer.MAX_VALUE); return Integer.compare(o1, o2); };/*w w w . j a v a 2 s. c o m*/ node.getChildren().sort(comparator); node.getChildren().forEach(child -> sortTriggersExt(child)); }
From source file:net.sf.maltcms.chromaui.foldChangeViewer.ui.panel.FoldChangeViewPanel.java
public void setPlot(final XYPlot plot) { removeAxisListener();// w w w. jav a 2 s .c o m ADataset1D<?, FoldChangeElement> dataset = null; if (plot.getDataset() instanceof ADataset1D) { dataset = (ADataset1D<?, FoldChangeElement>) plot.getDataset(); } else { throw new IllegalArgumentException("Requires a plot with ADataset1D!"); } this.plot = plot; if (selectionOverlay != null) { content.remove(selectionOverlay); selectionOverlay = null; } if (selectionOverlay == null) { selectionOverlay = new SelectionOverlay(Color.BLUE, Color.RED, 1.75f, 1.75f, 0.66f); chartPanel.addOverlay(selectionOverlay); selectionOverlay.addChangeListener(chartPanel); content.add(selectionOverlay); } else { for (ISelection selection : selectionOverlay.getMouseClickSelection()) { selection.setDataset(dataset); } ISelection selection = selectionOverlay.getMouseHoverSelection(); if (selection != null) { selection.setDataset(dataset); } } if (selectionHandler == null) { selectionHandler = new InstanceContentSelectionHandler(this.content, selectionOverlay, InstanceContentSelectionHandler.Mode.ON_CLICK, dataset, 1); } else { selectionHandler.setDataset(dataset); } if (mouseSelectionHandler == null) { mouseSelectionHandler = new XYMouseSelectionHandler<FoldChangeElement>(dataset); mouseSelectionHandler.addSelectionChangeListener(selectionOverlay); mouseSelectionHandler.addSelectionChangeListener(selectionHandler); chartPanel.addChartMouseListener(mouseSelectionHandler); } else { mouseSelectionHandler.setDataset(dataset); } AxisChangeListener listener = selectionOverlay; ValueAxis domain = this.plot.getDomainAxis(); ValueAxis range = this.plot.getRangeAxis(); if (domain != null) { domain.addChangeListener(listener); } if (range != null) { range.addChangeListener(listener); } if (dataset == null || dataset.getSeriesCount() == 0) { this.plot.setNoDataMessage("<No Data Available>"); } else { this.plot.setNoDataMessage("Loading Data..."); } this.plot.setDomainPannable(true); this.plot.setRangePannable(true); chart = new JFreeChart(this.plot); chartPanel.setChart(chart); XYItemRenderer r = this.plot.getRenderer(); if (r instanceof XYLineAndShapeRenderer) { ((XYLineAndShapeRenderer) r).setDrawSeriesLineAsPath(false); ((XYLineAndShapeRenderer) r).setBaseShapesVisible(true); ((XYLineAndShapeRenderer) r).setBaseShapesFilled(true); } else if (r instanceof XYAreaRenderer) { ((XYAreaRenderer) r).setOutline(true); } ChartCustomizer.setSeriesColors(this.plot, 0.8f); ChartCustomizer.setSeriesStrokes(this.plot, 2.0f); dmkl = new DomainMarkerKeyListener(this.plot); dmkl.setPlot(this.plot); chartPanel.addKeyListener(dmkl); addAxisListener(); //add available chart overlays List<Overlay> overlays = new ArrayList<Overlay>(getLookup().lookupAll(Overlay.class)); Collections.sort(overlays, new Comparator<Overlay>() { @Override public int compare(Overlay o1, Overlay o2) { if (o1 instanceof ChartOverlay && o2 instanceof ChartOverlay) { ChartOverlay co1 = (ChartOverlay) o1; ChartOverlay co2 = (ChartOverlay) o2; return Integer.compare(co1.getLayerPosition(), co2.getLayerPosition()); } else { return 0; } } }); for (Overlay overlay : overlays) { if (!(overlay instanceof SelectionOverlay)) { chartPanel.removeOverlay(overlay); if (overlay instanceof AxisChangeListener) { AxisChangeListener axisChangeListener = (AxisChangeListener) overlay; if (domain != null) { domain.addChangeListener(axisChangeListener); } if (range != null) { range.addChangeListener(axisChangeListener); } } if (overlay instanceof ISelectionChangeListener) { ISelectionChangeListener isl = (ISelectionChangeListener) overlay; mouseSelectionHandler.addSelectionChangeListener(isl); mouseSelectionHandler.addSelectionChangeListener(selectionHandler); selectionOverlay.addChangeListener(chartPanel); } chartPanel.addOverlay(overlay); overlay.addChangeListener(chartPanel); } } //add selection overlay last chartPanel.removeOverlay(selectionOverlay); chartPanel.addOverlay(selectionOverlay); }