/** * Moves all style refs from boby and div to corresponding p element for easiest merging. * * @param tt root timed object */ public static void moveStyleRefToP(TtEltype tt) { Set<Object> styles = new HashSet<>(tt.getBody().getStyle()); // set style to null, workaround for JAXB objects else style list will be just empty (invalid ttml) BodyEltype body = tt.getBody(); body.getStyle().clear(); setStyleListToNull(body); tt.getBody().getDiv().stream() .peek((div) -> { styles.addAll(div.getStyle()); div.getStyle().clear(); setStyleListToNull(div); }) .flatMap((div) -> div.getBlockClass().stream()) .filter((o) -> o instanceof PEltype) .map((o) -> (PEltype) o) .forEachOrdered((p) -> { Set<Object> pStyles = new HashSet<>(styles); pStyles.addAll(p.getStyle()); p.getStyle().clear(); p.getStyle().addAll(pStyles); }); }