package com.flozano.statsd.metrics;

import static java.util.Objects.requireNonNull;

final class PrefixedMetrics implements Metrics {

	private final Metrics inner;

	private final String prefix;

	public PrefixedMetrics(Metrics inner, String prefix) {
		this.inner = requireNonNull(inner);
		this.prefix = requireNonNull(prefix);
	}

	private final String checkAndAppend(CharSequence[] partz) {
		if (partz == null) {
			throw new IllegalArgumentException();
		}
		if (partz.length == 0) {
			throw new IllegalArgumentException();
		}
		if (partz[0] == null) {
			throw new IllegalArgumentException();
		}
		return prefix + inner.metricName(partz);
	}

	@Override
	public Timer timer(CharSequence... name) {
		return inner.timer(checkAndAppend(name));
	}

	@Override
	public Counter counter(CharSequence... name) {
		return inner.counter(checkAndAppend(name));
	}

	@Override
	public Gauge gauge(CharSequence... name) {
		return inner.gauge(checkAndAppend(name));
	}

	@Override
	public Metrics batch() {
		return new PrefixedMetrics(inner.batch(), prefix);
	}

	@Override
	public void close() {
		inner.close();
	}

}

@@ -614,16 +614,32 @@
 urn 
+inner.metricName(
 prefix
- +
+,
  inn
@@ -658,16 +658,17 @@
 e(partz)
+)
 ;%0A%09%7D%0A%0A%09@

Fix prefix