VariableWriterFactory { public static VariableWriter create(NVariable nVariable, VariableDescriptor variableDescriptor, int gridPointCount, int btDataCount) { final DataType dataType = variableDescriptor.getDataType(); final int memberIndex = variableDescriptor.getBtDataMemberIndex(); final boolean is2d = variableDescriptor.isIs2d(); float fillValue = 0.f; if (variableDescriptor.isFillValuePresent()) { fillValue = variableDescriptor.getFillValue(); } if (is2d) { if (dataType == DataType.FLOAT) { if (variableDescriptor.isGridPointData()) { return new FloatStructSequence2DWriter(nVariable, gridPointCount, btDataCount, memberIndex, fillValue); } else { return new FloatStructMember2DWriter(nVariable, gridPointCount, btDataCount, memberIndex, fillValue); } } else if (dataType == DataType.INT) { return new IntStructSequence2DWriter(nVariable, gridPointCount, btDataCount, memberIndex, (int) fillValue); } else if (dataType == DataType.SHORT) { return new ShortStructSequence2DWriter(nVariable, gridPointCount, btDataCount, memberIndex, (short) fillValue); } else if (dataType == DataType.BYTE) { throw new IllegalArgumentException("Unsupported data type for writer: " + dataType); } } else { if (dataType == DataType.FLOAT) { return new FloatStructMemberWriter(nVariable, memberIndex, gridPointCount, fillValue); } else if (dataType == DataType.INT) { return new IntStructMemberWriter(nVariable, memberIndex, gridPointCount, (int) fillValue); } else if (dataType == DataType.SHORT) { return new ShortStructMemberWriter(nVariable, memberIndex, gridPointCount, (short) fillValue); } else if (dataType == DataType.BYTE) { return new ByteStructMemberWriter(nVariable, memberIndex, gridPointCount, (byte) fillValue); } else if (dataType == DataType.LONG) { return new LongStructMemberWriter(nVariable, memberIndex, gridPointCount, (long) fillValue); } else if (dataType == DataType.DOUBLE) { return new DoubleStructMemberWriter(nVariable, memberIndex, gridPointCount, fillValue); } } throw new IllegalArgumentException("Unsupported data type for writer: " + dataType); }  static VariableWriter create(NVariable nVariable, VariableDescriptor variableDescriptor, int gridPointCount, int btDataCount);  }
@Test public void testCreateByteStructMemberWriter() { variableDescriptor.setDataType(DataType.BYTE); variableDescriptor.setGridPointData(true); final VariableWriter writer = VariableWriterFactory.create(nVariable, variableDescriptor, 12, 13); assertTrue(writer instanceof ByteStructMemberWriter); }
@Test public void testCreateByteStructMember2DWriter_unsupported() { variableDescriptor.setDataType(DataType.BYTE); variableDescriptor.setIs2d(true); try { VariableWriterFactory.create(nVariable, variableDescriptor, 12, 13); fail("IllegalArgumentException expected"); } catch (IllegalArgumentException expected) { } }
@Test public void testCreateFloatStructMemberWriter() { variableDescriptor.setDataType(DataType.FLOAT); variableDescriptor.setGridPointData(true); final VariableWriter writer = VariableWriterFactory.create(nVariable, variableDescriptor, 13, 14); assertTrue(writer instanceof FloatStructMemberWriter); }
@Test public void testCreateFloatStructSequence2DWriter() { variableDescriptor.setDataType(DataType.FLOAT); variableDescriptor.setIs2d(true); variableDescriptor.setGridPointData(true); final VariableWriter writer = VariableWriterFactory.create(nVariable, variableDescriptor, 14, 15); assertTrue(writer instanceof FloatStructSequence2DWriter); }
@Test public void testCreateFloatStructMember2DWriter() { variableDescriptor.setDataType(DataType.FLOAT); variableDescriptor.setIs2d(true); variableDescriptor.setGridPointData(false); final VariableWriter writer = VariableWriterFactory.create(nVariable, variableDescriptor, 14, 15); assertTrue(writer instanceof FloatStructMember2DWriter); }
@Test public void testCreateIntStructMemberWriter() { variableDescriptor.setDataType(DataType.INT); variableDescriptor.setGridPointData(true); final VariableWriter writer = VariableWriterFactory.create(nVariable, variableDescriptor, 16, 17); assertTrue(writer instanceof IntStructMemberWriter); }
@Test public void testCreateIntStructSequence2DWriter() { variableDescriptor.setDataType(DataType.INT); variableDescriptor.setIs2d(true); variableDescriptor.setGridPointData(false); final VariableWriter writer = VariableWriterFactory.create(nVariable, variableDescriptor, 18, 19); assertTrue(writer instanceof IntStructSequence2DWriter); }
@Test public void testCreateShortStructMemberWriter() { variableDescriptor.setDataType(DataType.SHORT); variableDescriptor.setGridPointData(true); final VariableWriter writer = VariableWriterFactory.create(nVariable, variableDescriptor, 18, 19); assertTrue(writer instanceof ShortStructMemberWriter); }
@Test public void testCreateShortStructSequence2DWriter() { variableDescriptor.setDataType(DataType.SHORT); variableDescriptor.setIs2d(true); variableDescriptor.setGridPointData(false); final VariableWriter writer = VariableWriterFactory.create(nVariable, variableDescriptor, 19, 20); assertTrue(writer instanceof ShortStructSequence2DWriter); }
@Test public void testCreateLongStructMemberWriter() { variableDescriptor.setDataType(DataType.LONG); variableDescriptor.setGridPointData(true); final VariableWriter writer = VariableWriterFactory.create(nVariable, variableDescriptor, 21, 22); assertTrue(writer instanceof LongStructMemberWriter); }
@Test public void testCreateDoubleStructMemberWriter() { variableDescriptor.setDataType(DataType.DOUBLE); variableDescriptor.setIs2d(false); final VariableWriter writer = VariableWriterFactory.create(nVariable, variableDescriptor, 21, 22); assertTrue(writer instanceof DoubleStructMemberWriter); }
@Test public void testCreateVariableWithUnsupportedDataTypeThrowsException() { variableDescriptor.setDataType(DataType.BOOLEAN); variableDescriptor.setGridPointData(true); try { VariableWriterFactory.create(nVariable, variableDescriptor, 19, 20); fail("IllegalArgumentException expected"); } catch (IllegalArgumentException expected) { } variableDescriptor.setDataType(DataType.ENUM2); variableDescriptor.setGridPointData(false); try { VariableWriterFactory.create(nVariable, variableDescriptor, 19, 20); fail("IllegalArgumentException expected"); } catch (IllegalArgumentException expected) { } }