/*
 * #%L
 * ImgLib2: a general-purpose, multidimensional image processing library.
 * %%
 * Copyright (C) 2009 - 2015 Tobias Pietzsch, Stephan Preibisch, Barry DeZonia,
 * Stephan Saalfeld, Curtis Rueden, Albert Cardona, Christian Dietz, Jean-Yves
 * Tinevez, Johannes Schindelin, Jonathan Hale, Lee Kamentsky, Larry Lindsey, Mark
 * Hiner, Michael Zinsmaier, Martin Horn, Grant Harris, Aivar Grislis, John
 * Bogovic, Steffen Jaensch, Stefan Helfrich, Jan Funke, Nick Perry, Mark Longair,
 * Melissa Linkert 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.
 * #L%
 */
package net.imglib2.interpolation.randomaccess;

import net.imglib2.RandomAccessible;
import net.imglib2.RealInterval;
import net.imglib2.RealRandomAccess;
import net.imglib2.Volatile;
import net.imglib2.interpolation.InterpolatorFactory;
import net.imglib2.type.numeric.ARGBType;
import net.imglib2.type.numeric.NumericType;
import net.imglib2.type.numeric.RealType;

/**
 * Provides clamping n-linear interpolators for volatile and non-volatile types.
 *
 * @param <T>
 *
 * @author Tobias Pietzsch <tobias.pietzsch@gmail.com>
 */
public class ClampingNLinearInterpolatorFactory< T extends NumericType< T > > implements InterpolatorFactory< T, RandomAccessible< T > >
{
	@SuppressWarnings( { "unchecked", "rawtypes" } )
	@Override
	public RealRandomAccess< T > create( final RandomAccessible< T > randomAccessible )
	{
		final T type = randomAccessible.randomAccess().get();
		if ( type instanceof RealType )
		{
			if ( type instanceof Volatile )
				return new ClampingNLinearInterpolatorVolatileRealType( randomAccessible );
			else
				return new ClampingNLinearInterpolatorRealType( randomAccessible );
		}
		else if ( type instanceof ARGBType )
		{
			if ( type instanceof Volatile )
				return new ClampingNLinearInterpolatorVolatileARGB( randomAccessible );
			else
				return ( RealRandomAccess< T > ) new NLinearInterpolatorARGB( ( RandomAccessible< ARGBType > ) randomAccessible );
		}
		else
			// fall back to (non-clamping) NLinearInterpolator
			return new NLinearInterpolator< T >( randomAccessible );
	}

	/**
	 * For now, ignore the {@link RealInterval} and return
	 * {@link #create(RandomAccessible)}.
	 */
	@Override
	public RealRandomAccess< T > create( final RandomAccessible< T > randomAccessible, final RealInterval interval )
	{
		return create( randomAccessible );
	}
}

@@ -2212,16 +2212,68 @@
 ealType;
+%0Aimport net.imglib2.type.volatiles.VolatileARGBType;
 %0A%0A/**%0A *
@@ -3027,42 +3027,51 @@
 f ( 
-type instanceof ARGBT
+ARGBType.class.isInstance( t
 ype )
+ )
 %0A%09%09%7B%0A%09%09%09
 if (
@@ -3070,95 +3070,85 @@
 %0A%09%09%09
-if ( type instanceof Volatile )%0A%09%09%09%09return new ClampingNLinearInterpolatorVolatileARGB(
+return ( RealRandomAccess ) new NLinearInterpolatorARGB( ( RandomAccessible )
  ran
@@ -3161,32 +3161,87 @@
 essible );%0A%09
+%09%7D%0A
 %09%09else
+ if ( VolatileARGBType.class.isInstance( type ) )%0A%09%09%7B
 %0A
-%09
 %09%09%09return ( 
@@ -3260,20 +3260,23 @@
 cess
-%3C T %3E
  ) new 
+Clamping
 NLin
@@ -3282,36 +3282,64 @@
 nearInterpolator
-ARGB
+VolatileARGB%3C VolatileARGBType %3E
 ( ( RandomAccess
@@ -3346,20 +3346,8 @@
 ible
-%3C ARGBType %3E
  ) r

fix compile and logic errors