* existing number of repetitions.
*/
public Structure get(String name, int rep) throws HL7Exception {
List<Structure> list = structures.get(name);
if (list == null)
throw new HL7Exception(name + " does not exist in the group " + this.getClass().getName(), HL7Exception.APPLICATION_INTERNAL_ERROR);
Structure ret;
if (rep < list.size()) {
// return existing Structure if it exists
ret = list.get(rep);
} else if (rep == list.size()) {
// verify that Structure is repeating ...
Boolean repeats = this.repeating.get(name);
if (!repeats.booleanValue() && list.size() > 0)
throw new HL7Exception("Can't create repetition #" + rep + " of Structure " + name + " - this Structure is non-repeating", HL7Exception.APPLICATION_INTERNAL_ERROR);
// create a new Structure, add it to the list, and return it
Class<? extends Structure> c = classes.get(name); // get class
ret = tryToInstantiateStructure(c, name);
list.add(ret);
} else {
throw new HL7Exception("Can't return repetition #" + rep + " of " + name + " - there are only " + list.size() + " repetitions.",
HL7Exception.APPLICATION_INTERNAL_ERROR);
}
return ret;
}