1 package com.stateofflow.eclipse.metrics.builder;
2
3 import com.stateofflow.eclipse.metrics.configuration.MetricsConfiguration;
4 import com.stateofflow.eclipse.metrics.location.MetricLocation;
5 import com.stateofflow.eclipse.metrics.metric.MetricId;
6
7 public abstract class AbstractMetricProcessor implements MetricProcessor {
8 private final MetricsConfiguration configuration;
9
10 public AbstractMetricProcessor(final MetricsConfiguration configuration) {
11 this.configuration = configuration;
12 }
13
14 public void noteMethodValue(final MetricId metricKey, final MetricLocation location, final int value) {
15 if (isEnabled(metricKey)) {
16 noteEnabledMethodValue(metricKey, location, value);
17 }
18 }
19
20 public void noteTypeValue(final MetricId metricKey, final MetricLocation location, final int value) {
21 if (isEnabled(metricKey)) {
22 noteEnabledTypeValue(metricKey, location, value);
23 }
24 }
25
26 protected abstract void noteEnabledMethodValue(MetricId metricKey, MetricLocation location, int value);
27
28 protected abstract void noteEnabledTypeValue(MetricId metricKey, MetricLocation location, int value);
29
30 private boolean isEnabled(final MetricId metricKey) {
31 return getConfiguration().isEnabled(metricKey);
32 }
33
34 protected MetricsConfiguration getConfiguration() {
35 return configuration;
36 }
37 }
38