import org.apache.commons.lang3.time.DateUtils; //导入方法依赖的package包/类
@Override
public Iterable _apply(final String line) {
final String[] t = line.split(",");
final String road = t[0];
final String junctionA = t[1];
final String junctionB = t[2];
final Date timestamp;
try {
timestamp = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(t[3]);
} catch (final ParseException e) {
throw new IllegalArgumentException("Invalid date: " + t[3]);
}
final Date startDate = DateUtils.truncate(timestamp, Calendar.DAY_OF_MONTH);
final Date endDate = DateUtils.addMilliseconds(DateUtils.addDays(startDate, 1), -1);
return Arrays.asList(
new Edge.Builder()
.group("RoadHasJunction")
.source(road)
.dest(junctionA)
.directed(true)
.build(),
new Edge.Builder()
.group("RoadHasJunction")
.source(road)
.dest(junctionB)
.directed(true)
.build(),
new Edge.Builder()
.group("RoadUse")
.source(junctionA)
.dest(junctionB)
.directed(true)
.property("count", 1L)
.property("startDate", startDate)
.property("endDate", endDate)
.build()
);
}