List of usage examples for java.lang Long compare
public static int compare(long x, long y)
From source file:Main.java
public static void main(String[] args) { System.out.println(Long.compare(1L, 2L)); }
From source file:io.appform.jsonrules.utils.ComparisonUtils.java
static int compare(JsonNode evaluatedNode, Object value) { int comparisonResult = 0; if (evaluatedNode.isNumber()) { if (Number.class.isAssignableFrom(value.getClass())) { Number nValue = (Number) value; if (evaluatedNode.isIntegralNumber()) { comparisonResult = Long.compare(evaluatedNode.asLong(), nValue.longValue()); } else if (evaluatedNode.isFloatingPointNumber()) { comparisonResult = Double.compare(evaluatedNode.asDouble(), nValue.doubleValue()); }// w ww.ja v a 2s . co m } else { throw new IllegalArgumentException("Type mismatch between operator and operand"); } } else if (evaluatedNode.isBoolean()) { if (Boolean.class.isAssignableFrom(value.getClass())) { Boolean bValue = Boolean.parseBoolean(value.toString()); comparisonResult = Boolean.compare(evaluatedNode.asBoolean(), bValue); } else { throw new IllegalArgumentException("Type mismatch between operator and operand"); } } else if (evaluatedNode.isTextual()) { if (String.class.isAssignableFrom(value.getClass())) { comparisonResult = evaluatedNode.asText().compareTo(String.valueOf(value)); } else { throw new IllegalArgumentException("Type mismatch between operator and operand"); } } else if (evaluatedNode.isObject()) { throw new IllegalArgumentException("Object comparisons not supported"); } return comparisonResult; }
From source file:com.google.uzaygezen.core.LongContent.java
@Override public int compareTo(LongContent o) { return Long.compare(v, o.v); }
From source file:org.nchadoop.ui.listbox.Displayable.java
@Override public int compareTo(final Displayable o) { return Long.compare(o.size, size); }
From source file:edu.iu.lda.SortTask.java
@Override public Object run(LongArrayList list) throws Exception { int size = list.size(); list.toArray(array);/* w w w. j av a 2 s . c o m*/ LongArrays.quickSort(array, 0, size, new LongComparator() { @Override public int compare(Long o1, Long o2) { return Long.compare(o2, o1); } @Override public int compare(long k1, long k2) { return Long.compare(k2, k1); } }); list.clear(); list.addElements(0, array, 0, size); return null; }
From source file:com.squarespace.template.JsonUtils.java
/** * Compare two JsonNode objects and return an integer. * * @return a negative integer, zero, or a positive integer as this object * is less than, equal to, or greater than the specified object. *///from w w w . ja va2 s. co m public static int compare(JsonNode left, JsonNode right) { if (left.isLong() || left.isInt()) { return Long.compare(left.asLong(), right.asLong()); } else if (left.isDouble() || left.isFloat()) { return Double.compare(left.asDouble(), right.asDouble()); } else if (left.isTextual()) { return left.asText().compareTo(right.asText()); } else if (left.isBoolean()) { return Boolean.compare(left.asBoolean(), right.asBoolean()); } // Not comparable in a relative sense, default to equals. return left.equals(right) ? 0 : -1; }
From source file:org.eclipse.winery.accountability.model.BlockchainElement.java
@Override public int compareTo(Object o) { if (o instanceof BlockchainElement) { return Long.compare(this.unixTimestamp, ((BlockchainElement) o).unixTimestamp); } else {/*from w w w . jav a 2 s . c o m*/ throw new IllegalArgumentException(); } }
From source file:io.appform.jsonrules.expressions.numeric.NumericJsonPathBasedExpression.java
@Override protected final boolean evaluate(ExpressionEvaluationContext context, String path, JsonNode evaluatedNode) { if (null == evaluatedNode || !evaluatedNode.isNumber()) { return false; }/*from w w w. j a v a 2 s . c o m*/ int comparisonResult = 0; if (evaluatedNode.isIntegralNumber()) { comparisonResult = Long.compare(evaluatedNode.asLong(), value.longValue()); } else if (evaluatedNode.isFloatingPointNumber()) { comparisonResult = Double.compare(evaluatedNode.asDouble(), value.doubleValue()); } return evaluate(context, comparisonResult); }
From source file:org.apache.hadoop.hbase.regionserver.StoreUtils.java
/** * Gets the largest file (with reader) out of the list of files. * @param candidates The files to choose from. * @return The largest file; null if no file has a reader. *//*from w w w.j a v a 2 s . c o m*/ static Optional<StoreFile> getLargestFile(Collection<StoreFile> candidates) { return candidates.stream().filter(f -> f.getReader() != null) .max((f1, f2) -> Long.compare(f1.getReader().length(), f2.getReader().length())); }
From source file:de.upb.wdqa.wdvd.processors.statistics.FrequencyUtils.java
public static List<Map.Entry<Comparable<?>, Long>> sortByFrequency(Frequency frequency) { Iterator<Map.Entry<Comparable<?>, Long>> iterator = frequency.entrySetIterator(); List<Map.Entry<Comparable<?>, Long>> list = new ArrayList<Map.Entry<Comparable<?>, Long>>(); while (iterator.hasNext()) { Map.Entry<Comparable<?>, Long> entry = iterator.next(); list.add(entry);//from ww w . j a va 2 s. c o m } Comparator<Map.Entry<Comparable<?>, Long>> comparator = new Comparator<Map.Entry<Comparable<?>, Long>>() { @Override public int compare(Map.Entry<Comparable<?>, Long> arg0, Map.Entry<Comparable<?>, Long> arg1) { if (arg0 == null || arg1 == null) { throw new NullPointerException(); } return -Long.compare(arg0.getValue(), arg1.getValue()); } }; Collections.sort(list, comparator); return list; }