CoverageMetaData { public static DataType findCoverageDataType(String string) { string = string.toUpperCase(); for (PrimitiveDataType dataType : PrimitiveDataType.values()) { if (string.equals(dataType.name().toUpperCase())) { return dataType; } } if (string.contains("INT")) { if (string.endsWith("16")) { return PrimitiveDataType.SHORT; } if (string.endsWith("32")) { return PrimitiveDataType.INT; } if (string.endsWith("64")) { return PrimitiveDataType.LONG; } if (string.endsWith("1")) { return PrimitiveDataType.BYTE; } if (string.endsWith("2")) { return PrimitiveDataType.SHORT; } if (string.endsWith("4")) { return PrimitiveDataType.INT; } if (string.endsWith("8")) { return PrimitiveDataType.LONG; } } if (string.contains("INTEGER")) { return PrimitiveDataType.INT; } if (string.contains("FLOAT")) { if (string.endsWith("32")) { return PrimitiveDataType.FLOAT; } if (string.endsWith("64")) { return PrimitiveDataType.DOUBLE; } if (string.endsWith("4")) { return PrimitiveDataType.FLOAT; } if (string.endsWith("8")) { return PrimitiveDataType.DOUBLE; } } return UnknownDataType; }  static DataType findCoverageDataType(String string); final static DataType UnknownDataType; }
@Test public void findCoverageDataTypeTest() { assertThat(findCoverageDataType("int").toString(), is(equalTo("INT"))); assertThat(findCoverageDataType("byte").toString(), is(equalTo("BYTE"))); assertThat(findCoverageDataType("short").toString(), is(equalTo("SHORT"))); assertThat(findCoverageDataType("long").toString(), is(equalTo("LONG"))); assertThat(findCoverageDataType("float").toString(), is(equalTo("FLOAT"))); assertThat(findCoverageDataType("double").toString(), is(equalTo("DOUBLE"))); assertThat(findCoverageDataType("INT1").toString(), is(equalTo("BYTE"))); assertThat(findCoverageDataType("INT2").toString(), is(equalTo("SHORT"))); assertThat(findCoverageDataType("INT4").toString(), is(equalTo("INT"))); assertThat(findCoverageDataType("INT8").toString(), is(equalTo("LONG"))); assertThat(findCoverageDataType("INT16").toString(), is(equalTo("SHORT"))); assertThat(findCoverageDataType("INT32").toString(), is(equalTo("INT"))); assertThat(findCoverageDataType("INT64").toString(), is(equalTo("LONG"))); assertThat(findCoverageDataType("INTEGER").toString(), is(equalTo("INT"))); assertThat(findCoverageDataType("FLOAT4").toString(), is(equalTo("FLOAT"))); assertThat(findCoverageDataType("FLOAT8").toString(), is(equalTo("DOUBLE"))); assertThat(findCoverageDataType("FLOAT32").toString(), is(equalTo("FLOAT"))); assertThat(findCoverageDataType("FLOAT64").toString(), is(equalTo("DOUBLE"))); assertThat(findCoverageDataType("UNUSED"), is(instanceOf(UnknownDataType.getClass()))); }