/*
 * #%L
 * ImageJ software for multidimensional image processing and analysis.
 * %%
 * Copyright (C) 2009 - 2013 Board of Regents of the University of
 * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck
 * Institute of Molecular Cell Biology and Genetics.
 * %%
 * 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 imagej.data;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import net.imglib2.img.ImgPlus;
import net.imglib2.img.array.ArrayImg;
import net.imglib2.img.array.ArrayImgs;
import net.imglib2.type.numeric.RealType;
import net.imglib2.type.numeric.integer.ByteType;
import net.imglib2.type.numeric.real.FloatType;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.scijava.Context;

/**
 * @author Barry DeZonia
 */
public class TestImgPlusService {

	private static Context context;
	private static ImgPlusService service;

	@BeforeClass
	public static void setupOnce() {
		context = new Context(ImgPlusService.class);
		service = context.getService(ImgPlusService.class);
	}

	@AfterClass
	public static void teardownOnce() {
		context.dispose();
	}

	@Test
	public void testUByte() {
		ImgPlus<? extends RealType<?>> imgPlus;
		final ArrayImg<?, ?> imgUByte = ArrayImgs.bytes(5, 5);
		imgPlus = new ImgPlus(imgUByte);

		assertNotNull(service.typed(imgPlus));
		assertNotNull(service.complex(imgPlus));
		assertNotNull(service.numeric(imgPlus));
		assertNotNull(service.real(imgPlus));
		assertNotNull(service.integer(imgPlus));
		assertNotNull(service.asType(imgPlus, new ByteType()));
		assertNull(service.asType(imgPlus, new FloatType()));
	}

	@Test
	public void testFloat() {
		ImgPlus<? extends RealType<?>> imgPlus;
		final ArrayImg<?, ?> imgFloat = ArrayImgs.floats(5, 5);
		imgPlus = new ImgPlus(imgFloat);

		assertNotNull(service.typed(imgPlus));
		assertNotNull(service.complex(imgPlus));
		assertNotNull(service.numeric(imgPlus));
		assertNotNull(service.real(imgPlus));
		assertNull(service.integer(imgPlus));
		assertNull(service.asType(imgPlus, new ByteType()));
		assertNotNull(service.asType(imgPlus, new FloatType()));
	}

	/* TODO - a non-numeric type
	@Test
	public void testBoolean() {
		ImgPlus<? extends RealType<?>> imgPlus;
		final Img<BooleanType> imgBoolean = null;
		imgPlus = new ImgPlus(imgBoolean);

		assertNull(TypedData.typed(imgPlus));
		assertNull(TypedData.complex(imgPlus));
		assertNull(TypedData.numeric(imgPlus));
		assertNull(TypedData.real(imgPlus));
		assertNull(TypedData.integer(imgPlus));
		assertNull(TypedData.asType(imgPlus, new ByteType()));
		assertNull(TypedData.asType(imgPlus, new FloatType()));
		assertNotNull(TypedData.asType(imgPlus, new BooleanType()));
	}
	*/
}

@@ -2041,16 +2041,61 @@
 ayImgs;%0A
+import net.imglib2.type.numeric.IntegerType;%0A
 import n
@@ -2732,17 +2732,16 @@
 oid test
-U
 Byte() %7B
@@ -2809,17 +2809,16 @@
 , ?%3E img
-U
 Byte = A
@@ -2866,17 +2866,16 @@
 Plus(img
-U
 Byte);%0A%0A
@@ -4276,11 +4276,567 @@
 ;%0A%09%7D%0A%09*/
+%0A%0A%09// How useful is it to have typed ImgPluses using service code? Can we do the%0A%09// math ops we might want to do?%0A%0A%09private void note() %7B%0A%0A%09%09ImgPlus%3C? extends RealType%3C?%3E%3E imgPlus;%0A%09%09final ArrayImg%3C?, ?%3E imgLong = ArrayImgs.longs(5, 5);%0A%09%09imgPlus = new ImgPlus(imgLong);%0A%09%09ImgPlus%3CIntegerType%3C?%3E%3E typed = service.integer(imgPlus);%0A%09%09IntegerType%3C?%3E var1 = typed.firstElement();%0A%09%09IntegerType%3C?%3E var2 = typed.firstElement();%0A%0A%09%09// won't compile%0A%09%09// var1.add(var2);%0A%0A%09%09// compiles%0A%09%09var1.setInteger(1000);%0A%09%09var2.setInteger(var1.getIntegerLong() + 4000);%0A%09%7D
 %0A%7D%0A

Add a note about usefulness of ImgPlusService