Skip to content

Commit

Permalink
alarms: fix natural order comparator to use timestamp first
Browse files Browse the repository at this point in the history
Motivation:

The natural order sorting of alarms currently is
based on its key.  This will work for most types
of alarms because the timestamp is included in
the key string.  However, generic alarms
have a UUID as key, so sorting is suboptimal
in that case.

Modification:

Sort first on the last modified timestamp.  Should
those be equal, then try creation time, and only
thereafter use the key to sort them.

Result:

All alarms are implicitly ordered by at least
their latest modification timestamp.

Target: master
Request: 3.2
Request: 3.1
Request: 3.0
Request: 2.16
Require-notes: no
Require-book: no
Acked-by: Paul
  • Loading branch information
alrossi committed Oct 18, 2017
1 parent 4adcade commit 77204df
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions modules/dcache/src/main/java/org/dcache/alarms/LogEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
package org.dcache.alarms;

import com.google.common.base.Preconditions;
import com.google.common.collect.ComparisonChain;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
Expand Down Expand Up @@ -106,8 +107,14 @@ private static String getFormattedDate(Date date) {

@Override
public int compareTo(LogEntry o) {
Preconditions.checkNotNull(o, "alarm entry parameter was null");
return key.compareTo(o.key);
if (o == null) {
return -1;
}
return ComparisonChain.start()
.compare(lastUpdate, o.lastUpdate)
.compare(firstArrived, o.firstArrived)
.compare(key, o.key)
.result();
}

@Override
Expand Down

0 comments on commit 77204df

Please sign in to comment.