/** Computes the latest module builds that correspond to this build. */
  public Map<IvyModule, IvyBuild> getModuleLastBuilds() {
    Collection<IvyModule> mods = getParent().getModules();

    // identify the build number range. [start,end)
    IvyModuleSetBuild nb = getNextBuild();
    int end = nb != null ? nb.getNumber() : Integer.MAX_VALUE;

    // preserve the order by using LinkedHashMap
    Map<IvyModule, IvyBuild> r = new LinkedHashMap<IvyModule, IvyBuild>(mods.size());

    for (IvyModule m : mods) {
      IvyBuild b = m.getNearestOldBuild(end - 1);
      if (b != null && b.getNumber() >= getNumber()) r.put(m, b);
    }

    return r;
  }
  /**
   * Finds {@link Action}s from all the module builds that belong to this {@link IvyModuleSetBuild}.
   * One action per one {@link IvyModule}, and newer ones take precedence over older ones.
   */
  public <T extends Action> List<T> findModuleBuildActions(Class<T> action) {
    Collection<IvyModule> mods = getParent().getModules();
    List<T> r = new ArrayList<T>(mods.size());

    // identify the build number range. [start,end)
    IvyModuleSetBuild nb = getNextBuild();
    int end = nb != null ? nb.getNumber() - 1 : Integer.MAX_VALUE;

    for (IvyModule m : mods) {
      IvyBuild b = m.getNearestOldBuild(end);
      while (b != null && b.getNumber() >= number) {
        T a = b.getAction(action);
        if (a != null) {
          r.add(a);
          break;
        }
        b = b.getPreviousBuild();
      }
    }

    return r;
  }
  /**
   * Computes the module builds that correspond to this build.
   *
   * <p>A module may be built multiple times (by the user action), so the value is a list.
   */
  public Map<IvyModule, List<IvyBuild>> getModuleBuilds() {
    Collection<IvyModule> mods = getParent().getModules();

    // identify the build number range. [start,end)
    IvyModuleSetBuild nb = getNextBuild();
    int end = nb != null ? nb.getNumber() : Integer.MAX_VALUE;

    // preserve the order by using LinkedHashMap
    Map<IvyModule, List<IvyBuild>> r = new LinkedHashMap<IvyModule, List<IvyBuild>>(mods.size());

    for (IvyModule m : mods) {
      List<IvyBuild> builds = new ArrayList<IvyBuild>();
      IvyBuild b = m.getNearestBuild(number);
      while (b != null && b.getNumber() < end) {
        builds.add(b);
        b = b.getNextBuild();
      }
      r.put(m, builds);
    }

    return r;
  }