if(log.isDebugEnabled()) { log.debug("Adding oldArg: " + arg); }
    private boolean populate(ComponentData data, float insertionOrder, String assemblyId)        throws SQLException    {        boolean result = false;        ComponentData parent = data.getParent();        String id = getComponentAlibId(data);        boolean isAdded = false;        addComponentDataSubstitutions(data);        substitutions.put(":assembly_id:", sqlQuote(assemblyId));        substitutions.put(":insertion_order:", String.valueOf(insertionOrder));        SortedSet oldArgs = (SortedSet) componentArgs.get(id);        if (oldArgs == null) {  // Don't know what the current args are            insureAlib();       // Insure that the alib and lib components are defined            ResultSet rs;            rs = executeQuery(stmt, dbp.getQuery("queryComponentArgs", substitutions));            oldArgs = new TreeSet();            while (rs.next()) {              if(log.isDebugEnabled()) {                log.debug("Adding Old Arg: " + rs.getString(1));              }                oldArgs.add(new Argument(rs.getString(1), rs.getFloat(2)));            }            rs.close();            if (parent != null) {              if(log.isDebugEnabled()) {                log.debug("PopulateDb:populate, Parent is not null");              }                rs = executeQuery(stmt, dbp.getQuery("checkComponentHierarchy",                                                     substitutions));                if (!rs.next()) {                    executeUpdate(dbp.getQuery("insertComponentHierarchy",                                               substitutions));                    isAdded = true;                    result = true; // Modified the experiment in the database                 }                rs.close();            }            componentArgs.put(id, oldArgs); // Avoid doing this again        }        // Now build a SortedSet of what the args should be        SortedSet newArgs = new TreeSet();        Object[] params = data.getParameters();        for (int i = 0; i < params.length; i++) {          if(log.isDebugEnabled()) {            log.debug("PopulateDb:populate; Param: " + params[i]);          }            newArgs.add(new Argument(params[i].toString(), i));        }        // The new args must only contain additions. There must be no        // deletions or alterations of the old args nor is it allowed        // to change the relative order of the existing arguments. If        // there are fewer newArgs than oldArgs, there is clearly a        // violation of this premise.        int excess = newArgs.size() - oldArgs.size();        if(log.isDebugEnabled()) {          log.debug("excess: " + excess);        }        if (excess < 0) {            throw new IllegalArgumentException("Attempt to remove "                                               + (-excess)                                               + " args from "                                               + data);        }        // Prepare to iterate through both old and new args.        // argsToInsert accumulates the new arguments to be inserted.        // Each of the new args is compared with the next unaccounted        // for old arg. If the new arg has a value different from the        // next old arg it is assumed to be an insertion since        // deletions and modifications are disallowed. But, if the        // excess new arg count has been reduced to zero, then no new        // args are possible because there won't be enought old args        // to match the remaining new ones so we throw an exception.        // The argument order is interpolated between the preceding        // and following old argument.        Iterator newIter = newArgs.iterator();        Iterator oldIter = oldArgs.iterator();        List argsToInsert = new ArrayList();        float prev = Float.NaN;        while (oldIter.hasNext()) {            Argument newArg = (Argument) newIter.next();            Argument oldArg = (Argument) oldIter.next();            while (!newArg.argument.equals(oldArg.argument)) {              if(log.isWarnEnabled()) {                log.warn("newArg != oldArg, new: " +newArg.toString() + " old: " + oldArg.toString());              }                // Assume arguments were inserted                excess--;                if (excess < 0) {                    throw new IllegalArgumentException("Component args cannot be modified or removed: " + data);                }                if (Float.isNaN(prev)) prev = oldArg.order - 1f;                argsToInsert.add(new Argument(newArg.argument, (prev + oldArg.order) * 0.5f));                newArg = (Argument) newIter.next();            }            prev = oldArg.order;        }        // Finally, any remaining new args are appended        if (Float.isNaN(prev)) prev = 0f;        while (newIter.hasNext()) {            Argument newArg = (Argument) newIter.next();            prev += 1f;            argsToInsert.add(new Argument(newArg.argument, prev));        }        // Now write all the new arguments that were not previously        // present to the database.        for (Iterator i = argsToInsert.iterator(); i.hasNext(); ) {            Argument arg = (Argument) i.next();            substitutions.put(":argument_value:", sqlQuote(arg.argument));            substitutions.put(":argument_order:", sqlQuote(String.valueOf(arg.order)));            executeUpdate(dbp.getQuery("insertComponentArg", substitutions));            if(log.isDebugEnabled()) {              log.debug("Adding oldArg: " + arg);            }            oldArgs.add(arg);            result = true;        }        if (data.getType().equals(ComponentData.AGENT)) {            populateAgent(data, isAdded);            result = true;        }        ComponentData[] children = data.getChildren();        // The following assumes that the insertion order of old        // children equals their index in the array and that the        // insertion order of all new children should be the their        // index in the array as well.        for (int i = 0, n = children.length; i < n; i++) {            result |= populate(children[i], i, assemblyId);        }        return result;    }