@Test public void testFromStringNegative() throws Exception { String meta; FieldMetadata fieldMetadata; try { meta = "dbFieldPosition=1;dbFieldType=FLOAT;numberScale=2;numberPrecision=3;"; fieldMetadata = FieldMetadata.fromString(meta); Assert.fail("Parsing field metadata from string should have failed due to missing field name"); } catch (Exception e) { Assert.assertTrue(e instanceof NullPointerException); } try { meta = "dbFieldName=AUTHOR;dbFieldType=FLOAT;numberScale=2;numberPrecision=3;"; fieldMetadata = FieldMetadata.fromString(meta); Assert.fail("Parsing field metadata from string should have failed due to missing field position"); } catch (Exception e) { Assert.assertTrue(e instanceof NullPointerException); } try { meta = "dbFieldName=AUTHOR;dbFieldPosition=26;"; fieldMetadata = FieldMetadata.fromString(meta); Assert.fail("Parsing field metadata from string should have failed due to missing field type"); } catch (Exception e) { Assert.assertTrue(e instanceof NullPointerException); } try { meta = "dbFieldName=AUTHOR,dbFieldPosition=26,dbFieldType=NVARCHAR2;"; fieldMetadata = FieldMetadata.fromString(meta); Assert.fail("Parsing field metadata from string should have failed due to invalid delimiter"); } catch (Exception e) { Assert.assertTrue(e instanceof IllegalArgumentException); } try { meta = "dbFieldName:AUTHOR;dbFieldPosition:26;dbFieldType:NVARCHAR2;"; fieldMetadata = FieldMetadata.fromString(meta); Assert.fail("Parsing field metadata from string should have failed due to invalid delimiter"); } catch (Exception e) { Assert.assertTrue(e instanceof IllegalArgumentException); } }
public static FieldMetadata fromString(String meta) { Map<String, String> metas = parseMetadata(meta); String fieldName = Preconditions.checkNotNull(metas.get(COL_NAME), String.format("Missing metadata %s from meta string %s", COL_NAME, meta)); int fieldPosition = Integer.parseInt(Preconditions.checkNotNull(metas.get(COL_POSITION), String.format("Missing metadata %s from meta string %s", COL_POSITION, meta))); Types fieldType = Types.fromString(Preconditions.checkNotNull(metas.get(FieldType.FIELD_TYPE_NAME), String.format("Missing metadata %s from meta string %s", FieldType.FIELD_TYPE_NAME, meta))); String nullable = Optional.ofNullable(metas.get(FieldType.NULLABLE)).orElse(""); Optional<Integer> numberPrecision = Optional.ofNullable(metas.get(FieldType.PRECISION)).map(Integer::valueOf); Optional<Integer> numberScale = Optional.ofNullable(metas.get(FieldType.SCALE)).map(Integer::valueOf); return new FieldMetadata(fieldName, nullable, fieldPosition, fieldType, numberPrecision, numberScale); }
FieldMetadata { public static FieldMetadata fromString(String meta) { Map<String, String> metas = parseMetadata(meta); String fieldName = Preconditions.checkNotNull(metas.get(COL_NAME), String.format("Missing metadata %s from meta string %s", COL_NAME, meta)); int fieldPosition = Integer.parseInt(Preconditions.checkNotNull(metas.get(COL_POSITION), String.format("Missing metadata %s from meta string %s", COL_POSITION, meta))); Types fieldType = Types.fromString(Preconditions.checkNotNull(metas.get(FieldType.FIELD_TYPE_NAME), String.format("Missing metadata %s from meta string %s", FieldType.FIELD_TYPE_NAME, meta))); String nullable = Optional.ofNullable(metas.get(FieldType.NULLABLE)).orElse(""); Optional<Integer> numberPrecision = Optional.ofNullable(metas.get(FieldType.PRECISION)).map(Integer::valueOf); Optional<Integer> numberScale = Optional.ofNullable(metas.get(FieldType.SCALE)).map(Integer::valueOf); return new FieldMetadata(fieldName, nullable, fieldPosition, fieldType, numberPrecision, numberScale); } }
FieldMetadata { public static FieldMetadata fromString(String meta) { Map<String, String> metas = parseMetadata(meta); String fieldName = Preconditions.checkNotNull(metas.get(COL_NAME), String.format("Missing metadata %s from meta string %s", COL_NAME, meta)); int fieldPosition = Integer.parseInt(Preconditions.checkNotNull(metas.get(COL_POSITION), String.format("Missing metadata %s from meta string %s", COL_POSITION, meta))); Types fieldType = Types.fromString(Preconditions.checkNotNull(metas.get(FieldType.FIELD_TYPE_NAME), String.format("Missing metadata %s from meta string %s", FieldType.FIELD_TYPE_NAME, meta))); String nullable = Optional.ofNullable(metas.get(FieldType.NULLABLE)).orElse(""); Optional<Integer> numberPrecision = Optional.ofNullable(metas.get(FieldType.PRECISION)).map(Integer::valueOf); Optional<Integer> numberScale = Optional.ofNullable(metas.get(FieldType.SCALE)).map(Integer::valueOf); return new FieldMetadata(fieldName, nullable, fieldPosition, fieldType, numberPrecision, numberScale); } FieldMetadata(@NotNull String dbFieldName, String nullable, int dbFieldPosition, @NotNull Types dbFieldType,
      Optional<Integer> numberPrecision, Optional<Integer> numberScale); }
FieldMetadata { public static FieldMetadata fromString(String meta) { Map<String, String> metas = parseMetadata(meta); String fieldName = Preconditions.checkNotNull(metas.get(COL_NAME), String.format("Missing metadata %s from meta string %s", COL_NAME, meta)); int fieldPosition = Integer.parseInt(Preconditions.checkNotNull(metas.get(COL_POSITION), String.format("Missing metadata %s from meta string %s", COL_POSITION, meta))); Types fieldType = Types.fromString(Preconditions.checkNotNull(metas.get(FieldType.FIELD_TYPE_NAME), String.format("Missing metadata %s from meta string %s", FieldType.FIELD_TYPE_NAME, meta))); String nullable = Optional.ofNullable(metas.get(FieldType.NULLABLE)).orElse(""); Optional<Integer> numberPrecision = Optional.ofNullable(metas.get(FieldType.PRECISION)).map(Integer::valueOf); Optional<Integer> numberScale = Optional.ofNullable(metas.get(FieldType.SCALE)).map(Integer::valueOf); return new FieldMetadata(fieldName, nullable, fieldPosition, fieldType, numberPrecision, numberScale); } FieldMetadata(@NotNull String dbFieldName, String nullable, int dbFieldPosition, @NotNull Types dbFieldType,
      Optional<Integer> numberPrecision, Optional<Integer> numberScale); static Map<String, String> parseMetadata(String meta); static FieldMetadata fromString(String meta); String getDbFieldName(); String getNullable(); int getDbFieldPosition(); Types getDbFieldType(); Optional<Integer> getNumberPrecision(); Optional<Integer> getNumberScale(); }
FieldMetadata { public static FieldMetadata fromString(String meta) { Map<String, String> metas = parseMetadata(meta); String fieldName = Preconditions.checkNotNull(metas.get(COL_NAME), String.format("Missing metadata %s from meta string %s", COL_NAME, meta)); int fieldPosition = Integer.parseInt(Preconditions.checkNotNull(metas.get(COL_POSITION), String.format("Missing metadata %s from meta string %s", COL_POSITION, meta))); Types fieldType = Types.fromString(Preconditions.checkNotNull(metas.get(FieldType.FIELD_TYPE_NAME), String.format("Missing metadata %s from meta string %s", FieldType.FIELD_TYPE_NAME, meta))); String nullable = Optional.ofNullable(metas.get(FieldType.NULLABLE)).orElse(""); Optional<Integer> numberPrecision = Optional.ofNullable(metas.get(FieldType.PRECISION)).map(Integer::valueOf); Optional<Integer> numberScale = Optional.ofNullable(metas.get(FieldType.SCALE)).map(Integer::valueOf); return new FieldMetadata(fieldName, nullable, fieldPosition, fieldType, numberPrecision, numberScale); } FieldMetadata(@NotNull String dbFieldName, String nullable, int dbFieldPosition, @NotNull Types dbFieldType,
      Optional<Integer> numberPrecision, Optional<Integer> numberScale); static Map<String, String> parseMetadata(String meta); static FieldMetadata fromString(String meta); String getDbFieldName(); String getNullable(); int getDbFieldPosition(); Types getDbFieldType(); Optional<Integer> getNumberPrecision(); Optional<Integer> getNumberScale();  }