Skip to content

Instantly share code, notes, and snippets.

@HelloThisIsFlo
Created January 26, 2017 08:46
Show Gist options
  • Save HelloThisIsFlo/5d6f7d398ddb32774080ea4df41b5ef4 to your computer and use it in GitHub Desktop.
Save HelloThisIsFlo/5d6f7d398ddb32774080ea4df41b5ef4 to your computer and use it in GitHub Desktop.
public class SomeClass {
public List<Book> findSpecificBookInFile(String bookName, String filePath) {
/////////////////////////////
// Parsing the XML file ///
/////////////////////////////
ParseType xmlType = new ParseType(Parsing.Type.XML, Parsing.Xml.ExtraColumn);
ParseFileFactory xmlFileFactory = new ParseFileFactory(xmlType);
ParseFile<Parsing.Type.XML> xmlFile = xmlFileFactory.open(filePath);
RootType bookType = new TypeToken<Book>() {}.getType();
List<Book> fromFile;
try {
fromFile = xmlFile.parseList(bookType, 0);
} catch (IOException e) {
// do things
}
/////////////////
// Find book ///
/////////////////
return fromFile.stream()
.filter(book -> bookName.equals(book.title()))
.findFirst()
.orElse(Book.NULL);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment