private ModuleComponentIdentifier chooseBestMatchingDependency(
      ModuleVersionListing versions, ModuleVersionSelector requested) {
    for (Versioned candidate : sortLatestFirst(versions)) {
      // Apply version selection rules
      ModuleComponentIdentifier candidateIdentifier =
          DefaultModuleComponentIdentifier.newId(
              requested.getGroup(), requested.getName(), candidate.getVersion());
      ModuleComponentSelector requestedComponentSelector =
          DefaultModuleComponentSelector.newSelector(requested);
      VersionSelectionInternal selection =
          new DefaultVersionSelection(requestedComponentSelector, candidateIdentifier);
      versionSelectionRules.apply(selection);

      switch (selection.getState()) {
        case ACCEPTED:
          return candidateIdentifier;
        case REJECTED:
          continue;
        default:
          break;
      }

      // Invoke version matcher
      if (versionMatcher.accept(requested.getVersion(), candidate.getVersion())) {
        return candidateIdentifier;
      }
    }
    return null;
  }
  private ModuleComponentIdentifier chooseBestMatchingDependencyWithMetaData(
      ModuleVersionListing versions,
      DependencyMetaData dependency,
      ModuleComponentRepositoryAccess moduleAccess) {
    for (Versioned candidate : sortLatestFirst(versions)) {
      MutableModuleVersionMetaData metaData =
          resolveComponentMetaData(dependency, candidate, moduleAccess);
      ModuleComponentIdentifier candidateIdentifier = metaData.getComponentId();

      // Apply version selection rules
      ModuleComponentSelector requestedComponentSelector =
          DefaultModuleComponentSelector.newSelector(dependency.getRequested());
      VersionSelectionInternal selection =
          new DefaultVersionSelection(requestedComponentSelector, candidateIdentifier);
      versionSelectionRules.apply(selection);

      switch (selection.getState()) {
        case ACCEPTED:
          return candidateIdentifier;
        case REJECTED:
          continue;
        default:
          break;
      }

      // Invoke version matcher
      if (versionMatcher.accept(dependency.getRequested().getVersion(), metaData)) {
        // We already resolved the correct module.
        return candidateIdentifier;
      }
    }
    return null;
  }