Java 8 Comparator - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 Comparator class.

This code example shows how to use the following methods: compare
    public static boolean equals(Object o1, Object o2) {
        if (o1 instanceof JSONObject && o2 instanceof JSONObject) {
            return JSON_OBJECT_COMPARATOR.compare((JSONObject) o1, (JSONObject) o2) == 0;
        } 
        if (o1 instanceof JSONArray && o2 instanceof JSONArray) {
            return JSON_ARRAY_COMPARATOR.compare((JSONArray) o1, (JSONArray) o2) == 0;
        } 
        return o1 == null ? o2 == null : o1.equals(o2);
    } 
 
    public static JSONObject makeRandomJson() {
        try { 
            Random random = new Random();
            JSONObject json = new JSONObject();
            final int size = random.nextInt(20) + 5;
            for (int i = 0; i < size; i++) {
                json.put("id:" + i, random.nextInt(100000) + 500);
            } 
            return json;
        } catch (JSONException e) {
Full Snippet Info
7
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: compare
    private R next;
 
    public ResultMergeSortIterator(Iterator<R> first, Iterator<R> second, Comparator<R> comparator, boolean filterDuplicates) {
        Preconditions.checkNotNull(first);
        Preconditions.checkNotNull(second);
        Preconditions.checkNotNull(comparator);
        this.first = first;
        this.second = second;
        this.comp = comparator;
        this.filterDuplicates = filterDuplicates;
 
        nextFirst = null;
        nextSecond = null;
        next = nextInternal();
    } 
 
    @Override 
    public boolean hasNext() { 
        return next != null;
    } 

7
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: compare
    agg.aggregate();
    agg.aggregate();
    metricValues.put(agg.getName(), agg.get());
    Object after = arithmeticPostAggregator.compute(metricValues);
 
    Assert.assertEquals(-1, comp.compare(before, after));
    Assert.assertEquals(0, comp.compare(before, before));
    Assert.assertEquals(0, comp.compare(after, after));
    Assert.assertEquals(1, comp.compare(after, before));
  } 
} 
Full Snippet Info
6
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: compare
  public int compareTo(PartitionChunk<T> chunk)
  { 
    if (chunk instanceof LinearPartitionChunk) {
      LinearPartitionChunk<T> linearChunk = (LinearPartitionChunk<T>) chunk;
 
      return comparator.compare(chunkNumber, linearChunk.chunkNumber);
    } 
    throw new IllegalArgumentException("Cannot compare against something that is not a LinearPartitionChunk.");
  } 
 
  @Override 
  @SuppressWarnings("unchecked") 
  public boolean equals(Object o)
  { 
    if (this == o) {
      return true; 
    } 
    if (o == null || getClass() != o.getClass()) {
      return false; 
    } 
Full Snippet Info
7
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: compare
  public int compareTo(PartitionChunk<T> chunk)
  { 
    if (chunk instanceof StringPartitionChunk) {
      StringPartitionChunk<T> stringChunk = (StringPartitionChunk<T>) chunk;
 
      return comparator.compare(chunkNumber, stringChunk.chunkNumber);
    } 
    throw new IllegalArgumentException("Cannot compare against something that is not a StringPartitionChunk.");
  } 
 
  @Override 
  @SuppressWarnings("unchecked") 
  public boolean equals(Object o)
  { 
    if (this == o) {
      return true; 
    } 
    if (o == null || getClass() != o.getClass()) {
      return false; 
    } 
Full Snippet Info
7
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE

Related Java 8 Comparator Questions & Answers:

See Code Examples for Java 8 Comparator Methods: