1   package com.stateofflow.eclipse.metrics.location.comparator;
2   
3   import com.stateofflow.eclipse.metrics.collator.MetricsCollator;
4   import com.stateofflow.eclipse.metrics.location.MetricLocation;
5   import com.stateofflow.eclipse.metrics.metric.MetricId;
6   
7   public final class MetricOrderingLocationComparator extends LocationComparator {
8       private final MetricsCollator collator;
9       private final MetricId metricId;
10  
11      public MetricOrderingLocationComparator(final MetricsCollator collator, final MetricId id) {
12          this.collator = collator;
13          this.metricId = id;
14      }
15  
16      protected int compareParticular(final MetricLocation l1, final MetricLocation l2) {
17          if (collator.hasMetric(l1, metricId)) {
18              return !collator.hasMetric(l2, metricId) ? -1 : collator.getMetric(l2, metricId).getValue() - collator.getMetric(l1, metricId).getValue();
19          } else {
20              return collator.hasMetric(l2, metricId) ? 1 : 0;
21          }
22      }
23  }
24