private static NumericMatrix getMatrix(Collection<PlainPerson> persons, LegPredicate pred) { NumericMatrix m = new NumericMatrix(); for (Person person : persons) { for (Episode episode : person.getEpisodes()) { for (int i = 0; i < episode.getLegs().size(); i++) { Segment leg = episode.getLegs().get(i); if (pred.test(leg)) { Segment prev = episode.getActivities().get(i); Segment next = episode.getActivities().get(i + 1); String origin = prev.getAttribute(SetZones.ZONE_KEY); String dest = next.getAttribute(SetZones.ZONE_KEY); if (origin != null && dest != null) { m.add(origin, dest, 1); String touched = leg.getAttribute(DBG_TOUCHED); int cnt = 0; if (touched != null) cnt = Integer.parseInt(touched); leg.setAttribute(DBG_TOUCHED, String.valueOf(cnt + 1)); } } } } } return m; }