/*
 * #%L
 * ImgLib2: a general-purpose, multidimensional image processing library.
 * %%
 * Copyright (C) 2009 - 2013 Stephan Preibisch, Tobias Pietzsch, Barry DeZonia,
 * Stephan Saalfeld, Albert Cardona, Curtis Rueden, Christian Dietz, Jean-Yves
 * Tinevez, Johannes Schindelin, Lee Kamentsky, Larry Lindsey, Grant Harris,
 * Mark Hiner, Aivar Grislis, Martin Horn, Nick Perry, Michael Zinsmaier,
 * Steffen Jaensch, Jan Funke, Mark Longair, and Dimiter Prodanov.
 * %%
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 * 
 * 1. Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 * 
 * The views and conclusions contained in the software and documentation are
 * those of the authors and should not be interpreted as representing official
 * policies, either expressed or implied, of any organization.
 * #L%
 */

package net.imglib2.meta;

import java.util.List;

import net.imglib2.meta.axis.LinearAxis;

/**
 * Abstract base class for {@link CalibratedSpace}.
 * 
 * @author Curtis Rueden
 */
public abstract class AbstractCalibratedSpace<A extends CalibratedAxis>
 extends
	AbstractTypedSpace<A> implements CalibratedSpace<A>
{

	public AbstractCalibratedSpace(final int numDims) {
		super(numDims);
	}

	public AbstractCalibratedSpace(final A... axes) {
		super(axes);
	}

	public AbstractCalibratedSpace(final List<A> axes) {
		super(axes);
	}

	// -- CalibratedSpace methods --

	@Override
	public double averageScale(final int d) {
		return averageScale(d);
	}

	@Override
	public double calibration(final int d) {
		return linearAxis(d).scale();
	}

	@Override
	public void calibration(double[] cal) {
		for (int d = 0; d < numDimensions(); d++) {
			cal[d] = calibration(d);
		}
	}

	@Override
	public void calibration(float[] cal) {
		for (int d = 0; d < numDimensions(); d++) {
			cal[d] = (float) calibration(d);
		}
	}

	@Override
	public void setCalibration(double cal, int d) {
		linearAxis(d).setScale(cal);
	}

	@Override
	public void setCalibration(double[] cal) {
		for (int d = 0; d < numDimensions(); d++) {
			setCalibration(cal[d], d);
		}
	}

	@Override
	public void setCalibration(float[] cal) {
		for (int d = 0; d < numDimensions(); d++) {
			setCalibration(cal[d], d);
		}
	}

	@Override
	public String unit(int d) {
		return axis(d).unit();
	}

	@Override
	public void setUnit(String unit, int d) {
		axis(d).setUnit(unit);
	}

	// -- Helper methods --

	private LinearAxis linearAxis(final int d) {
		final A axis = axis(d);
		if (axis instanceof LinearAxis) {
			return (LinearAxis) axis;
		}
		throw new IllegalArgumentException("Unsupported axis: " +
			axis.getClass().getName());
	}

}

@@ -2259,17 +2259,16 @@
 tedAxis%3E
-%0A
  extends
@@ -2778,32 +2778,38 @@
 oid calibration(
+final 
 double%5B%5D cal) %7B%0A
@@ -2918,32 +2918,38 @@
 oid calibration(
+final 
 float%5B%5D cal) %7B%0A%09
@@ -3072,24 +3072,30 @@
 Calibration(
+final 
 double cal, 
@@ -3093,16 +3093,22 @@
 ble cal,
+ final
  int d) 
@@ -3183,16 +3183,22 @@
 bration(
+final 
 double%5B%5D
@@ -3328,16 +3328,22 @@
 bration(
+final 
 float%5B%5D 
@@ -3464,16 +3464,22 @@
 ng unit(
+final 
 int d) %7B
@@ -3540,16 +3540,22 @@
 setUnit(
+final 
 String u
@@ -3558,16 +3558,22 @@
 ng unit,
+ final
  int d) 

clean up style