List of usage examples for java.lang Integer compare
public static int compare(int x, int y)
From source file:org.geoserver.qos.QosMainConfigurationWMSValidator.java
protected void validateImageRange(OwsRange range) { Integer min = null, max = null; if (StringUtils.isNotBlank(range.getMinimunValue())) { try {/* w w w .j av a 2 s . c o m*/ min = Integer.parseInt(range.getMinimunValue()); } catch (NumberFormatException e) { throw new IllegalArgumentException("Number format error on Minimun value"); } } if (StringUtils.isNotBlank(range.getMaximunValue())) { try { max = Integer.parseInt(range.getMaximunValue()); } catch (NumberFormatException e) { throw new IllegalArgumentException("Number format error on Maximun value"); } } if (min != null && max != null) { if (Integer.compare(min, max) >= 0) { throw new IllegalArgumentException("Minimun value must be lower than Maximun value"); } } }
From source file:uni.bielefeld.cmg.sparkhit.util.HelpParam.java
public void printReporterHelp() { 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())); }//w w w.ja v a 2s. c o m }); final String executable = System.getProperty("executable", "spark-submit [spark parameter] --class uni.bielefeld.cmg.sparkhit.main.MainOfReporter Sparkhit.jar"); err.println("Name:"); err.println("\tSparkHit Reporter"); 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("\tReport mappint summary"); err.println(executable + " [parameters] -input ./sparkhit.out -outfile ./sparkhit.report"); err.println(); }
From source file:org.opencms.ui.contextmenu.CmsContextMenuTreeBuilder.java
/** * Builds a tree from a list of available context menu items.<p> * * The root node of the returned tree has no useful data, its child nodes correspond to the top-level * entries of the ccontext menu.//from w w w . j a v a2 s . c om * * @param items the available context menu items * @return the context menu item tree */ public CmsTreeNode<I_CmsContextMenuItem> buildTree(List<I_CmsContextMenuItem> items) { items = Lists.newArrayList(items); // First sort by priority and then use a map with the id as the key to store the items, // eliminating items with the same id but a lower priority than another item Collections.sort(items, new Comparator<I_CmsContextMenuItem>() { public int compare(I_CmsContextMenuItem a, I_CmsContextMenuItem b) { return Integer.compare(a.getPriority(), b.getPriority()); } }); LinkedHashMap<String, I_CmsContextMenuItem> itemsById = Maps.newLinkedHashMap(); for (I_CmsContextMenuItem item : items) { String id = item.getId(); I_CmsContextMenuItem prevItem = itemsById.get(id); if (prevItem != null) { LOG.info("Discarding overridden context menu item " + prevItem + " because of higher priority item " + item); } itemsById.put(id, item); } // Now sort by order. Since all children of a node should be processed in one iteration of the following loop, // this order also applies to the child order of each tree node built in the next step List<I_CmsContextMenuItem> uniqueItems = Lists.newArrayList(itemsById.values()); uniqueItems = filterVisible(uniqueItems); if (m_context.getResources().size() == 1) { m_defaultActionItem = findDefaultAction(uniqueItems); } Collections.sort(uniqueItems, new Comparator<I_CmsContextMenuItem>() { public int compare(I_CmsContextMenuItem a, I_CmsContextMenuItem b) { return Float.compare(a.getOrder(), b.getOrder()); } }); Set<String> processedIds = Sets.newHashSet(); boolean changed = true; Map<String, CmsTreeNode<I_CmsContextMenuItem>> treesById = Maps.newHashMap(); // Create childless tree node for each item for (I_CmsContextMenuItem item : itemsById.values()) { CmsTreeNode<I_CmsContextMenuItem> node = new CmsTreeNode<I_CmsContextMenuItem>(); node.setData(item); treesById.put(item.getId(), node); } CmsTreeNode<I_CmsContextMenuItem> root = new CmsTreeNode<I_CmsContextMenuItem>(); // Use null as the root node, which does not have any useful data treesById.put(null, root); // Iterate through list multiple times, each time only processing those items whose parents // we have encountered in a previous iteration (actually, in the last iteration). We do this so that the resulting // tree is actually a tree and contains no cycles, even if there is a reference cycle between the context menu items via their parent ids. // (Items which form such a cycle will never be reached.) while (changed) { changed = false; Iterator<I_CmsContextMenuItem> iterator = uniqueItems.iterator(); Set<String> currentLevel = Sets.newHashSet(); while (iterator.hasNext()) { I_CmsContextMenuItem currentItem = iterator.next(); String parentId = currentItem.getParentId(); if ((parentId == null) || processedIds.contains(parentId)) { changed = true; iterator.remove(); currentLevel.add(currentItem.getId()); treesById.get(parentId).addChild(treesById.get(currentItem.getId())); } } processedIds.addAll(currentLevel); } return root; }
From source file:org.mitre.mpf.interop.JsonDetectionProcessingError.java
@Override public int compareTo(JsonDetectionProcessingError other) { int result = 0; if (other == null) { return 1; } else if ((result = Integer.compare(startOffset, other.startOffset)) != 0 || (result = Integer.compare(stopOffset, other.stopOffset)) != 0 || (result = ObjectUtils.compare(message, other.message)) != 0) { return result; } else {//ww w .j a v a 2s. co m return result; } }
From source file:no.imr.stox.functions.utils.RUtils.java
/** * Get R folder/*from w w w.ja va 2 s. co m*/ * * @param errors * @return */ public static File getRFolder(List<String> errors) { // For mac: String osName = System.getProperty("os.name").toLowerCase(); switch (osName) { case "mac os x": return new File("/Library/Frameworks/R.framework/Versions/Current/Resources/bin"); default: // For windows, maybe linux: String[] files = new String[] { "C:/Program Files", "C:/Program Files (x86)", System.getenv("ProgramFiles"), System.getenv("ProgramFiles(X86)"), System.getProperty("user.home"), "C:", "/usr/bin" }; for (String fn : files) { File f = safeFile(fn + "/R"); if (f == null) { if (errors != null) { errors.add(fn + "/R" + " not found"); } continue; } if (errors != null) { errors.clear(); } File[] fl = f.listFiles(); if (fl == null) { continue; } List<File> lf = Arrays.asList(f.listFiles()); Collections.sort(lf, (File o1, File o2) -> { return -Integer.compare(getRVersionByPath(o1.getPath()), getRVersionByPath(o2.getPath())); }); for (File rf : lf) { if (rf.isDirectory() && rf.getPath().contains("R-")) { File rBin = getRBinFolderByRoot(rf); if (rBin != null) { if (errors != null) { errors.clear(); } return rf; } else if (errors != null) { errors.add(rf.getPath() + "/bin/" + getJREArchID() + " not found in "); } } else if (errors != null) { errors.add(rf.getPath() + " is not a valid R installation"); } } } } return null; }
From source file:net.udidb.engine.ops.impls.help.HelpMessageProvider.java
private String createLongMessage(String name, String shortMessage, Class<? extends Operation> opClass) { List<Pair<Field, Operand>> operands = ReflectionUtils .getAllFields(opClass, ReflectionUtils.withAnnotation(Operand.class)).stream() .map(f -> Pair.of(f, f.getAnnotation(Operand.class))).filter(p -> p.getRight() != null) .sorted((p1, p2) -> Integer.compare(p1.getRight().order(), p2.getRight().order())) .collect(Collectors.toList()); String header = name + " " + operands.stream().map(p -> getOperandIdentifier(p.getLeft(), p.getRight())) .collect(Collectors.joining(" ")); String operandDescriptions = operands.stream() .map(p -> String.format("%15s -- %s", p.getLeft().getName(), getOperandDescription(p.getLeft()))) .collect(Collectors.joining("\n")); return header + "\n\n" + shortMessage + "\n\n" + operandDescriptions; }
From source file:org.apache.ranger.plugin.policyevaluator.RangerAbstractPolicyEvaluator.java
@Override public int compareTo(RangerPolicyResourceEvaluator obj) { if (LOG.isDebugEnabled()) { LOG.debug("==> RangerAbstractPolicyEvaluator.compareTo()"); }//w w w . ja v a2s.c o m int result; if (obj instanceof RangerPolicyEvaluator) { RangerPolicyEvaluator other = (RangerPolicyEvaluator) obj; if (hasDeny() && !other.hasDeny()) { result = -1; } else if (!hasDeny() && other.hasDeny()) { result = 1; } else { result = Long.compare(other.getUsageCount(), this.usageCount); if (result == 0) { result = Integer.compare(this.evalOrder, other.getEvalOrder()); } } } else { result = Long.compare(getId(), obj.getId()); } if (LOG.isDebugEnabled()) { LOG.debug("<== RangerAbstractPolicyEvaluator.compareTo(), result:" + result); } return result; }
From source file:org.ethereum.net.NodeManager.java
private void purgeNodeHandlers() { if (nodeHandlerMap.size() > NODES_TRIM_THRESHOLD) { List<NodeHandler> sorted = new ArrayList<>(nodeHandlerMap.values()); Collections.sort(sorted, (o1, o2) -> Integer.compare(o1.getNodeStatistics().getReputation(), o2.getNodeStatistics().getReputation())); for (NodeHandler handler : sorted) { nodeHandlerMap.remove(handler.getNode().getAddressAsString()); if (nodeHandlerMap.size() <= MAX_NODES) break; }//ww w. j ava2s. co m } }
From source file:com.insightml.utils.Collections.java
public static <T, N extends Number> Map<T, N> sort(final Map<T, N> map, final SortOrder order) { final TreeMap<T, N> sorted = new TreeMap<>((o1, o2) -> { final double o1Value = map.get(o1).doubleValue(); final double o2Value = map.get(o2).doubleValue(); if (o1Value == o2Value) { if (o1 instanceof Comparable) { return ((Comparable<T>) o1).compareTo(o2); }/*w ww. ja va 2 s . c o m*/ // TODO: This can be very unexpected!!! return Integer.compare(o1.hashCode(), o2.hashCode()); } if (order == SortOrder.DESCENDING) { return o1Value < o2Value ? 1 : -1; } return o1Value > o2Value ? 1 : -1; }); sorted.putAll(map); return sorted; }
From source file:com.github.fauu.natrank.model.entity.RankingEntry.java
@Override public int compareTo(RankingEntry other) { int ratingComparison = -1 * Integer.compare(this.getRating(), other.getRating()); if (ratingComparison == 0) { return (-1 * Integer.compare(this.getMatchesTotal(), other.getMatchesTotal())); }/*from w w w .ja v a 2s . c om*/ return ratingComparison; }