TiffType { public static TiffShort getType(final TiffValue[] values) { Guardian.assertNotNull("values", values); Guardian.assertGreaterThan("values.length", values.length, 0); final TiffValue value = values[0]; Guardian.assertNotNull("value", value); if (value instanceof TiffShort) { ensureElementsEqualValueType(values, TiffShort.class); return SHORT; } if (value instanceof TiffUInt) { ensureElementsEqualValueType(values, TiffUInt.class); return LONG; } if (value instanceof TiffRational) { ensureElementsEqualValueType(values, TiffRational.class); return RATIONAL; } if (value instanceof GeoTiffAscii) { ensureElementsEqualValueType(values, GeoTiffAscii.class); return ASCII; } if (value instanceof TiffAscii) { ensureElementsEqualValueType(values, TiffAscii.class); return ASCII; } if (value instanceof TiffDouble) { ensureElementsEqualValueType(values, TiffDouble.class); return DOUBLE; } if (value instanceof TiffLong) { ensureElementsEqualValueType(values, TiffLong.class); return SLONG_8; } throw new IllegalArgumentException("the given type [" + values.getClass() + "] is not supported"); }  static TiffShort getType(final TiffValue[] values); static final byte BYTE_TYPE; static final TiffShort BYTE; static final byte ASCII_TYPE; static final TiffShort ASCII; static final byte SHORT_TYPE; static final TiffShort SHORT; static final byte LONG_TYPE; static final TiffShort LONG; static final byte RATIONAL_TYPE; static final TiffShort RATIONAL; static final byte SBYTE_TYPE; static final TiffShort SBYTE; static final byte UNDEFINED_TYPE; static final TiffShort UNDEFINED; static final byte SSHORT_TYPE; static final TiffShort SSHORT; static final byte SLONG_TYPE; static final TiffShort SLONG; static final byte SRATIONAL_TYPE; static final TiffShort SRATIONAL; static final byte FLOAT_TYPE; static final TiffShort FLOAT; static final byte DOUBLE_TYPE; static final TiffShort DOUBLE; static final byte LONG_8_TYPE; static final TiffShort LONG_8; static final byte SLONG_8_TYPE; static final TiffShort SLONG_8; }
@Test public void testGetType_nullInput() { try { TiffType.getType(null); fail("IllegalArgumentException expected"); } catch (IllegalArgumentException expected) { } }
@Test public void testGetType_zeroLengthInput() { try { TiffType.getType(new TiffValue[0]); fail("IllegalArgumentException expected"); } catch (IllegalArgumentException expected) { } }
@Test public void testGetType_elementsAreNull() { try { TiffType.getType(new TiffValue[2]); fail("IllegalArgumentException expected"); } catch (IllegalArgumentException expected) { } }
@Test public void testGetType() { final TiffValue[] array = new TiffValue[1]; array[0] = new TiffShort(1); TiffShort type = TiffType.getType(array); assertEquals(3, type.getValue()); array[0] = new TiffUInt(2); type = TiffType.getType(array); assertEquals(4, type.getValue()); array[0] = new TiffRational(3, 4); type = TiffType.getType(array); assertEquals(5, type.getValue()); array[0] = new TiffAscii("bla"); type = TiffType.getType(array); assertEquals(2, type.getValue()); array[0] = new GeoTiffAscii("blubb"); type = TiffType.getType(array); assertEquals(2, type.getValue()); array[0] = new TiffDouble(5.6); type = TiffType.getType(array); assertEquals(12, type.getValue()); array[0] = new TiffLong(7); type = TiffType.getType(array); assertEquals(17, type.getValue()); }