Opened 13 years ago

Last modified 13 years ago

#337 closed enhancement

Make ERF implement Iterable<ProbEqkSource> and ProbEqkSource implement Iterable<ProbEqkRupture> — at Version 1

Reported by: Kevin Milner Owned by: Kevin Milner
Priority: major Milestone: OpenSHA 1.3
Component: sha Version:
Keywords: ERF Cc:

Description (last modified by Kevin Milner)

This is just an idea, so feel free to disagree/discuss below. Personally, I find the following code to be very long winded:

for (int sourceID=0; sourceID<erf.getNumSources(); sourceID++) {
	ProbEqkSource source = erf.getSource(sourceID);
	for (int rupID=0; rupID<source.getNumRuptures(); sourceID++) {
		ProbEqkRupture rup = source.getRupture(rupID);
		// do work on rup
	}
}

For many cases (where knowing the source/rup IDs is not important), this could be replaced with the following:

for (ProbEqkSource source : erf) {
	for (ProbEqkRupture rup : source) {
		// do work on rup
	}
}

In order to do this, ERF would have to implement Iterable<ProbEqkSource?>, and ProbEqkSource? would then need to implement Iterable<ProbEqkRupture?>. This would add one method to each:

public Iterator<T> iterator();

What do you think? I don't foresee any adverse impact of adding this.

Change History (1)

comment:1 Changed 13 years ago by Kevin Milner

Description: modified (diff)
Note: See TracTickets for help on using tickets.