@Test(expected = DocumentConverterException.class) public void fromDocument_noOptionalFieldNames() throws DocumentConverterException { final Document document = new Document() .append(TypeDocumentConverter.ID, "urn:icecream"); new TypeDocumentConverter().fromDocument(document); }
@Override public Type fromDocument(final Document document) throws DocumentConverterException { requireNonNull(document); if(!document.containsKey(ID)) { throw new DocumentConverterException("Could not convert document '" + document + "' because its '" + ID + "' field is missing."); } if(!document.containsKey(PROPERTY_NAMES)) { throw new DocumentConverterException("Could not convert document '" + document + "' because its '" + PROPERTY_NAMES + "' field is missing."); } final RyaIRI typeId = new RyaIRI( document.getString(ID) ); final ImmutableSet.Builder<RyaIRI> propertyNames = ImmutableSet.builder(); document.getList(PROPERTY_NAMES, String.class) .forEach(propertyName -> propertyNames.add(new RyaIRI(propertyName))); return new Type(typeId, propertyNames.build()); }
TypeDocumentConverter implements DocumentConverter<Type> { @Override public Type fromDocument(final Document document) throws DocumentConverterException { requireNonNull(document); if(!document.containsKey(ID)) { throw new DocumentConverterException("Could not convert document '" + document + "' because its '" + ID + "' field is missing."); } if(!document.containsKey(PROPERTY_NAMES)) { throw new DocumentConverterException("Could not convert document '" + document + "' because its '" + PROPERTY_NAMES + "' field is missing."); } final RyaIRI typeId = new RyaIRI( document.getString(ID) ); final ImmutableSet.Builder<RyaIRI> propertyNames = ImmutableSet.builder(); document.getList(PROPERTY_NAMES, String.class) .forEach(propertyName -> propertyNames.add(new RyaIRI(propertyName))); return new Type(typeId, propertyNames.build()); } }
TypeDocumentConverter implements DocumentConverter<Type> { @Override public Type fromDocument(final Document document) throws DocumentConverterException { requireNonNull(document); if(!document.containsKey(ID)) { throw new DocumentConverterException("Could not convert document '" + document + "' because its '" + ID + "' field is missing."); } if(!document.containsKey(PROPERTY_NAMES)) { throw new DocumentConverterException("Could not convert document '" + document + "' because its '" + PROPERTY_NAMES + "' field is missing."); } final RyaIRI typeId = new RyaIRI( document.getString(ID) ); final ImmutableSet.Builder<RyaIRI> propertyNames = ImmutableSet.builder(); document.getList(PROPERTY_NAMES, String.class) .forEach(propertyName -> propertyNames.add(new RyaIRI(propertyName))); return new Type(typeId, propertyNames.build()); }  }
TypeDocumentConverter implements DocumentConverter<Type> { @Override public Type fromDocument(final Document document) throws DocumentConverterException { requireNonNull(document); if(!document.containsKey(ID)) { throw new DocumentConverterException("Could not convert document '" + document + "' because its '" + ID + "' field is missing."); } if(!document.containsKey(PROPERTY_NAMES)) { throw new DocumentConverterException("Could not convert document '" + document + "' because its '" + PROPERTY_NAMES + "' field is missing."); } final RyaIRI typeId = new RyaIRI( document.getString(ID) ); final ImmutableSet.Builder<RyaIRI> propertyNames = ImmutableSet.builder(); document.getList(PROPERTY_NAMES, String.class) .forEach(propertyName -> propertyNames.add(new RyaIRI(propertyName))); return new Type(typeId, propertyNames.build()); }  @Override Document toDocument(final Type type); @Override Type fromDocument(final Document document); }
TypeDocumentConverter implements DocumentConverter<Type> { @Override public Type fromDocument(final Document document) throws DocumentConverterException { requireNonNull(document); if(!document.containsKey(ID)) { throw new DocumentConverterException("Could not convert document '" + document + "' because its '" + ID + "' field is missing."); } if(!document.containsKey(PROPERTY_NAMES)) { throw new DocumentConverterException("Could not convert document '" + document + "' because its '" + PROPERTY_NAMES + "' field is missing."); } final RyaIRI typeId = new RyaIRI( document.getString(ID) ); final ImmutableSet.Builder<RyaIRI> propertyNames = ImmutableSet.builder(); document.getList(PROPERTY_NAMES, String.class) .forEach(propertyName -> propertyNames.add(new RyaIRI(propertyName))); return new Type(typeId, propertyNames.build()); }  @Override Document toDocument(final Type type); @Override Type fromDocument(final Document document); static final String ID; static final String PROPERTY_NAMES; }