class InterchangesDelegator extends BaseDelegator implements IInterchangesDelegator {

    public List<IChangelist> processInterchangeMaps(final List<Map<String, Object>> resultMaps,
            final boolean showFiles) throws ConnectionException, AccessException, RequestException {

        List<IChangelist> interchangeList = new ArrayList<>();
        if (nonNull(resultMaps)) {
            for (Map<String, Object> map : resultMaps) {
                if (nonNull(map)) {
                    // map is either an error (in which case we do what we'd
                    // normally do with an error), or it's an "error" -- i.e.
                    // it's
                    // telling us there's no interchanges -- in which case we
                    // return
                    // an empty list,
                    // or it's a change summary (in which case we return a full
                    // changelist
                    // constructed from the summary, even though we don't get
                    // the full
                    // changelist info back),
                    // or (if the showFiles option was set) it's a change
                    // summary with a
                    // nested set of depot file specs inside the same map, in
                    // which case we pick the files off as best we can and then
                    // associate
                    // them with the changelist constructed as above.
                    // p4ic4idea: use IServerMessage instead.
                    IServerMessage err = server.handleFileErrorStr(map);
                    if (nonNull(err)) {
                        // What we're doing here is weeding out the "all
                        // revision(s)
                        // already integrated" non-error error...
                        // Note that the code here may be fragile in the face of
                        // server-side changes to error messages and code
                        // changes.
                        if (err.getGeneric() != 17 && err.getSeverity() != 2
                                && !err.hasMessageFragment("all revision(s) already integrated")) {
                            throw new RequestException(err);
                        }
                    } else {
                        ChangelistSummary changelistSummary = new ChangelistSummary(map, true,
                                server);
                        Changelist changelist = new Changelist(changelistSummary, server, false);
                        interchangeList.add(changelist);
                        List<IFileSpec> fileSpecs = new ArrayList<IFileSpec>();
                        changelist.setFileSpecs(fileSpecs);
                        if (showFiles) {
                            int i = 0;
                            while (nonNull(map.get(DEPOT_FILE + i))) {
                                FileSpec fileSpec = new FileSpec(map, server, i);
                                fileSpec.setChangelistId(changelist.getId());
                                fileSpecs.add(fileSpec);
                                i++;
                            }
                        }
                    }
                }
            }
        }
        return interchangeList;
    }

    public  InterchangesDelegator(IOptionsServer server);

}