@Test public void testParseRelatives() { InputStream inputStream = getClass().getResourceAsStream("relatives.json"); List<Relative> relatives = converter.parseRelatives(inputStream); assertNotNull(relatives); assertEquals(1, relatives.size()); Relative relative = relatives.get(0); assertNotNull(relative); }
@Override public List<Relative> parseRelatives(final InputStream inputStream) { checkNotNull(inputStream); JsonParser parser = null; try { parser = jsonFactory.createParser(inputStream); parser.nextToken(); List<Relative> relatives = new ArrayList<Relative>(); String profileId = null; String matchId = null; double similarity = 0.0d; int sharedSegments = 0; Relationship relationship = null; Relationship userRelationship = null; Set<Relationship> range = new HashSet<Relationship>(); while (parser.nextToken() != JsonToken.END_OBJECT) { String field = parser.getCurrentName(); parser.nextToken(); if ("id".equals(field)) { profileId = parser.getText(); } else if ("relatives".equals(field)) { while (parser.nextToken() != JsonToken.END_ARRAY) { while (parser.nextToken() != JsonToken.END_OBJECT) { String relativeField = parser.getCurrentName(); parser.nextToken(); if ("match_id".equals(relativeField)) { matchId = parser.getText(); } else if ("similarity".equals(relativeField)) { similarity = Double.parseDouble(parser.getText()); } else if ("shared_segments".equals(relativeField)) { sharedSegments = parser.getIntValue(); } else if ("relationship".equals(relativeField)) { relationship = Relationship.fromDescription(parser.getText()); } else if ("user_relationship_code".equals(relativeField)) { String code = parser.getText(); userRelationship = code == "null" ? null : Relationship.fromCode(Integer.parseInt(code)); } else if ("predicted_relationship_code".equals(relativeField)) { if (relationship == null) { String code = parser.getText(); relationship = code == "null" ? null : Relationship.fromCode(Integer.parseInt(code)); } } else if ("range".equals(relativeField)) { while (parser.nextToken() != JsonToken.END_ARRAY) { range.add(Relationship.fromDescription(parser.getText())); } } else if ("family_locations".equals(relativeField)) { while (parser.nextToken() != JsonToken.END_ARRAY) { } } else if ("family_surnames".equals(relativeField)) { while (parser.nextToken() != JsonToken.END_ARRAY) { } } else if ("profile_picture_urls".equals(relativeField)) { while (parser.nextToken() != JsonToken.END_OBJECT) { } } } } relatives.add(new Relative(profileId, matchId, similarity, sharedSegments, relationship, userRelationship, range)); matchId = null; similarity = 0.0d; sharedSegments = 0; relationship = null; userRelationship = null; range.clear(); } } return relatives; } catch (IOException e) { logger.warn("could not parse relatives", e); } finally { try { inputStream.close(); } catch (Exception e) { } try { parser.close(); } catch (Exception e) { } } return null; }
JacksonPersonalGenomeConverter implements PersonalGenomeConverter { @Override public List<Relative> parseRelatives(final InputStream inputStream) { checkNotNull(inputStream); JsonParser parser = null; try { parser = jsonFactory.createParser(inputStream); parser.nextToken(); List<Relative> relatives = new ArrayList<Relative>(); String profileId = null; String matchId = null; double similarity = 0.0d; int sharedSegments = 0; Relationship relationship = null; Relationship userRelationship = null; Set<Relationship> range = new HashSet<Relationship>(); while (parser.nextToken() != JsonToken.END_OBJECT) { String field = parser.getCurrentName(); parser.nextToken(); if ("id".equals(field)) { profileId = parser.getText(); } else if ("relatives".equals(field)) { while (parser.nextToken() != JsonToken.END_ARRAY) { while (parser.nextToken() != JsonToken.END_OBJECT) { String relativeField = parser.getCurrentName(); parser.nextToken(); if ("match_id".equals(relativeField)) { matchId = parser.getText(); } else if ("similarity".equals(relativeField)) { similarity = Double.parseDouble(parser.getText()); } else if ("shared_segments".equals(relativeField)) { sharedSegments = parser.getIntValue(); } else if ("relationship".equals(relativeField)) { relationship = Relationship.fromDescription(parser.getText()); } else if ("user_relationship_code".equals(relativeField)) { String code = parser.getText(); userRelationship = code == "null" ? null : Relationship.fromCode(Integer.parseInt(code)); } else if ("predicted_relationship_code".equals(relativeField)) { if (relationship == null) { String code = parser.getText(); relationship = code == "null" ? null : Relationship.fromCode(Integer.parseInt(code)); } } else if ("range".equals(relativeField)) { while (parser.nextToken() != JsonToken.END_ARRAY) { range.add(Relationship.fromDescription(parser.getText())); } } else if ("family_locations".equals(relativeField)) { while (parser.nextToken() != JsonToken.END_ARRAY) { } } else if ("family_surnames".equals(relativeField)) { while (parser.nextToken() != JsonToken.END_ARRAY) { } } else if ("profile_picture_urls".equals(relativeField)) { while (parser.nextToken() != JsonToken.END_OBJECT) { } } } } relatives.add(new Relative(profileId, matchId, similarity, sharedSegments, relationship, userRelationship, range)); matchId = null; similarity = 0.0d; sharedSegments = 0; relationship = null; userRelationship = null; range.clear(); } } return relatives; } catch (IOException e) { logger.warn("could not parse relatives", e); } finally { try { inputStream.close(); } catch (Exception e) { } try { parser.close(); } catch (Exception e) { } } return null; } }
JacksonPersonalGenomeConverter implements PersonalGenomeConverter { @Override public List<Relative> parseRelatives(final InputStream inputStream) { checkNotNull(inputStream); JsonParser parser = null; try { parser = jsonFactory.createParser(inputStream); parser.nextToken(); List<Relative> relatives = new ArrayList<Relative>(); String profileId = null; String matchId = null; double similarity = 0.0d; int sharedSegments = 0; Relationship relationship = null; Relationship userRelationship = null; Set<Relationship> range = new HashSet<Relationship>(); while (parser.nextToken() != JsonToken.END_OBJECT) { String field = parser.getCurrentName(); parser.nextToken(); if ("id".equals(field)) { profileId = parser.getText(); } else if ("relatives".equals(field)) { while (parser.nextToken() != JsonToken.END_ARRAY) { while (parser.nextToken() != JsonToken.END_OBJECT) { String relativeField = parser.getCurrentName(); parser.nextToken(); if ("match_id".equals(relativeField)) { matchId = parser.getText(); } else if ("similarity".equals(relativeField)) { similarity = Double.parseDouble(parser.getText()); } else if ("shared_segments".equals(relativeField)) { sharedSegments = parser.getIntValue(); } else if ("relationship".equals(relativeField)) { relationship = Relationship.fromDescription(parser.getText()); } else if ("user_relationship_code".equals(relativeField)) { String code = parser.getText(); userRelationship = code == "null" ? null : Relationship.fromCode(Integer.parseInt(code)); } else if ("predicted_relationship_code".equals(relativeField)) { if (relationship == null) { String code = parser.getText(); relationship = code == "null" ? null : Relationship.fromCode(Integer.parseInt(code)); } } else if ("range".equals(relativeField)) { while (parser.nextToken() != JsonToken.END_ARRAY) { range.add(Relationship.fromDescription(parser.getText())); } } else if ("family_locations".equals(relativeField)) { while (parser.nextToken() != JsonToken.END_ARRAY) { } } else if ("family_surnames".equals(relativeField)) { while (parser.nextToken() != JsonToken.END_ARRAY) { } } else if ("profile_picture_urls".equals(relativeField)) { while (parser.nextToken() != JsonToken.END_OBJECT) { } } } } relatives.add(new Relative(profileId, matchId, similarity, sharedSegments, relationship, userRelationship, range)); matchId = null; similarity = 0.0d; sharedSegments = 0; relationship = null; userRelationship = null; range.clear(); } } return relatives; } catch (IOException e) { logger.warn("could not parse relatives", e); } finally { try { inputStream.close(); } catch (Exception e) { } try { parser.close(); } catch (Exception e) { } } return null; } JacksonPersonalGenomeConverter(final JsonFactory jsonFactory); }
JacksonPersonalGenomeConverter implements PersonalGenomeConverter { @Override public List<Relative> parseRelatives(final InputStream inputStream) { checkNotNull(inputStream); JsonParser parser = null; try { parser = jsonFactory.createParser(inputStream); parser.nextToken(); List<Relative> relatives = new ArrayList<Relative>(); String profileId = null; String matchId = null; double similarity = 0.0d; int sharedSegments = 0; Relationship relationship = null; Relationship userRelationship = null; Set<Relationship> range = new HashSet<Relationship>(); while (parser.nextToken() != JsonToken.END_OBJECT) { String field = parser.getCurrentName(); parser.nextToken(); if ("id".equals(field)) { profileId = parser.getText(); } else if ("relatives".equals(field)) { while (parser.nextToken() != JsonToken.END_ARRAY) { while (parser.nextToken() != JsonToken.END_OBJECT) { String relativeField = parser.getCurrentName(); parser.nextToken(); if ("match_id".equals(relativeField)) { matchId = parser.getText(); } else if ("similarity".equals(relativeField)) { similarity = Double.parseDouble(parser.getText()); } else if ("shared_segments".equals(relativeField)) { sharedSegments = parser.getIntValue(); } else if ("relationship".equals(relativeField)) { relationship = Relationship.fromDescription(parser.getText()); } else if ("user_relationship_code".equals(relativeField)) { String code = parser.getText(); userRelationship = code == "null" ? null : Relationship.fromCode(Integer.parseInt(code)); } else if ("predicted_relationship_code".equals(relativeField)) { if (relationship == null) { String code = parser.getText(); relationship = code == "null" ? null : Relationship.fromCode(Integer.parseInt(code)); } } else if ("range".equals(relativeField)) { while (parser.nextToken() != JsonToken.END_ARRAY) { range.add(Relationship.fromDescription(parser.getText())); } } else if ("family_locations".equals(relativeField)) { while (parser.nextToken() != JsonToken.END_ARRAY) { } } else if ("family_surnames".equals(relativeField)) { while (parser.nextToken() != JsonToken.END_ARRAY) { } } else if ("profile_picture_urls".equals(relativeField)) { while (parser.nextToken() != JsonToken.END_OBJECT) { } } } } relatives.add(new Relative(profileId, matchId, similarity, sharedSegments, relationship, userRelationship, range)); matchId = null; similarity = 0.0d; sharedSegments = 0; relationship = null; userRelationship = null; range.clear(); } } return relatives; } catch (IOException e) { logger.warn("could not parse relatives", e); } finally { try { inputStream.close(); } catch (Exception e) { } try { parser.close(); } catch (Exception e) { } } return null; } JacksonPersonalGenomeConverter(final JsonFactory jsonFactory); @Override PersonalGenomeClientException parseException(final InputStream inputStream); @Override User parseUser(final InputStream inputStream); @Override UserName parseNames(final InputStream inputStream); @Override Haplogroup parseHaplogroups(final InputStream inputStream); @Override Genotype parseGenotypes(final InputStream inputStream); @Override Genome parseGenomes(final InputStream inputStream); @Override Ancestry parseAncestry(final InputStream inputStream); @Override double parseNeanderthalProportion(final InputStream inputStream); @Override List<Relative> parseRelatives(final InputStream inputStream); @Override List<Risk> parseRisks(final InputStream inputStream); @Override List<Carrier> parseCarriers(final InputStream inputStream); @Override List<DrugResponse> parseDrugResponses(final InputStream inputStream); @Override List<Trait> parseTraits(final InputStream inputStream); }
JacksonPersonalGenomeConverter implements PersonalGenomeConverter { @Override public List<Relative> parseRelatives(final InputStream inputStream) { checkNotNull(inputStream); JsonParser parser = null; try { parser = jsonFactory.createParser(inputStream); parser.nextToken(); List<Relative> relatives = new ArrayList<Relative>(); String profileId = null; String matchId = null; double similarity = 0.0d; int sharedSegments = 0; Relationship relationship = null; Relationship userRelationship = null; Set<Relationship> range = new HashSet<Relationship>(); while (parser.nextToken() != JsonToken.END_OBJECT) { String field = parser.getCurrentName(); parser.nextToken(); if ("id".equals(field)) { profileId = parser.getText(); } else if ("relatives".equals(field)) { while (parser.nextToken() != JsonToken.END_ARRAY) { while (parser.nextToken() != JsonToken.END_OBJECT) { String relativeField = parser.getCurrentName(); parser.nextToken(); if ("match_id".equals(relativeField)) { matchId = parser.getText(); } else if ("similarity".equals(relativeField)) { similarity = Double.parseDouble(parser.getText()); } else if ("shared_segments".equals(relativeField)) { sharedSegments = parser.getIntValue(); } else if ("relationship".equals(relativeField)) { relationship = Relationship.fromDescription(parser.getText()); } else if ("user_relationship_code".equals(relativeField)) { String code = parser.getText(); userRelationship = code == "null" ? null : Relationship.fromCode(Integer.parseInt(code)); } else if ("predicted_relationship_code".equals(relativeField)) { if (relationship == null) { String code = parser.getText(); relationship = code == "null" ? null : Relationship.fromCode(Integer.parseInt(code)); } } else if ("range".equals(relativeField)) { while (parser.nextToken() != JsonToken.END_ARRAY) { range.add(Relationship.fromDescription(parser.getText())); } } else if ("family_locations".equals(relativeField)) { while (parser.nextToken() != JsonToken.END_ARRAY) { } } else if ("family_surnames".equals(relativeField)) { while (parser.nextToken() != JsonToken.END_ARRAY) { } } else if ("profile_picture_urls".equals(relativeField)) { while (parser.nextToken() != JsonToken.END_OBJECT) { } } } } relatives.add(new Relative(profileId, matchId, similarity, sharedSegments, relationship, userRelationship, range)); matchId = null; similarity = 0.0d; sharedSegments = 0; relationship = null; userRelationship = null; range.clear(); } } return relatives; } catch (IOException e) { logger.warn("could not parse relatives", e); } finally { try { inputStream.close(); } catch (Exception e) { } try { parser.close(); } catch (Exception e) { } } return null; } JacksonPersonalGenomeConverter(final JsonFactory jsonFactory); @Override PersonalGenomeClientException parseException(final InputStream inputStream); @Override User parseUser(final InputStream inputStream); @Override UserName parseNames(final InputStream inputStream); @Override Haplogroup parseHaplogroups(final InputStream inputStream); @Override Genotype parseGenotypes(final InputStream inputStream); @Override Genome parseGenomes(final InputStream inputStream); @Override Ancestry parseAncestry(final InputStream inputStream); @Override double parseNeanderthalProportion(final InputStream inputStream); @Override List<Relative> parseRelatives(final InputStream inputStream); @Override List<Risk> parseRisks(final InputStream inputStream); @Override List<Carrier> parseCarriers(final InputStream inputStream); @Override List<DrugResponse> parseDrugResponses(final InputStream inputStream); @Override List<Trait> parseTraits(final InputStream inputStream);  }