private void getCurseRoot() { HistoricalFigure parent; do { parent = World.getHistoricalEvents() .stream() .collect( Filters.filterEvent( HfDoesInteractionEvent.class, e -> e.getTargetHfId() == getRoot().hf.getId())) .map(HfDoesInteractionEvent::getDoerHfId) .map(World::getHistoricalFigure) .findFirst() .orElseGet(() -> null); if (parent != null) { root = new FamilyMember(parent, 0, 0); } } while (parent != null); }
@RequestMapping("/hf/{id}") public Template hf(VelocityContext context, int id) { HistoricalFigure hf = World.getHistoricalFigure(id); HistoricalFigure.setContext(hf); context.put("hf", hf); context.put("family", new Family(hf, false)); if (hf.isWerebeast()) { context.put("curse", new Family(hf, true)); } context.put( "events", World.getHistoricalEvents() .stream() .filter(e -> EventHelper.related(hf, e)) .collect(Collectors.toList())); return Templates.get("hf.vm"); }
private void analyzeBites(FamilyMember m) { if (members.contains(m)) return; members.add(m); World.getHistoricalEvents() .stream() .collect( Filters.filterEvent( HfDoesInteractionEvent.class, e -> e.getDoerHfId() == m.hf.getId() && e.getInteraction().startsWith(interaction))) .map(HfDoesInteractionEvent::getTargetHfId) .map(World::getHistoricalFigure) .forEach( hf -> { FamilyMember m2 = new FamilyMember(hf, m.getGeneration() + 1, m.getDistance() + 1); m2.father = m; m.children.add(m2); links.add(new FamilyLink("child", m, m2)); analyzeBites(m2); }); }