class DefaultVersionRangeResolver implements VersionRangeResolver {

    private static final String MAVEN_METADATA_XML = "maven-metadata.xml";

    private final MetadataResolver metadataResolver;
    private final SyncContextFactory syncContextFactory;
    private final RepositoryEventDispatcher repositoryEventDispatcher;
    private final VersionScheme versionScheme;

    @Inject
    public DefaultVersionRangeResolver(
            MetadataResolver metadataResolver,
            SyncContextFactory syncContextFactory,
            RepositoryEventDispatcher repositoryEventDispatcher,
            VersionScheme versionScheme) {
        this.metadataResolver = Objects.requireNonNull(metadataResolver, "metadataResolver cannot be null");
        this.syncContextFactory = Objects.requireNonNull(syncContextFactory, "syncContextFactory cannot be null");
        this.repositoryEventDispatcher =
                Objects.requireNonNull(repositoryEventDispatcher, "repositoryEventDispatcher cannot be null");
        this.versionScheme = Objects.requireNonNull(versionScheme, "versionScheme cannot be null");
    }

    @Override
    public VersionRangeResult resolveVersionRange(RepositorySystemSession session, VersionRangeRequest request)
            throws VersionRangeResolutionException {
        VersionRangeResult result = new VersionRangeResult(request);

        VersionConstraint versionConstraint;
        try {
            versionConstraint =
                    versionScheme.parseVersionConstraint(request.getArtifact().getVersion());
        } catch (InvalidVersionSpecificationException e) {
            result.addException(e);
            throw new VersionRangeResolutionException(result);
        }

        result.setVersionConstraint(versionConstraint);

        if (versionConstraint.getRange() == null) {
            result.addVersion(versionConstraint.getVersion());
        } else {
            VersionRange.Bound lowerBound = versionConstraint.getRange().getLowerBound();
            if (lowerBound != null
                    && lowerBound.equals(versionConstraint.getRange().getUpperBound())) {
                result.addVersion(lowerBound.getVersion());
            } else {
                Map<String, ArtifactRepository> versionIndex = getVersions(session, result, request);

                List<Version> versions = new ArrayList<>();
                for (Map.Entry<String, ArtifactRepository> v : versionIndex.entrySet()) {
                    try {
                        Version ver = versionScheme.parseVersion(v.getKey());
                        if (versionConstraint.containsVersion(ver)) {
                            versions.add(ver);
                            result.setRepository(ver, v.getValue());
                        }
                    } catch (InvalidVersionSpecificationException e) {
                        result.addException(e);
                    }
                }

                Collections.sort(versions);
                result.setVersions(versions);
            }
        }

        return result;
    }

    private Map<String, ArtifactRepository> getVersions(
            RepositorySystemSession session, VersionRangeResult result, VersionRangeRequest request) {
        RequestTrace trace = RequestTrace.newChild(request.getTrace(), request);

        Map<String, ArtifactRepository> versionIndex = new HashMap<>();

        Metadata metadata = new DefaultMetadata(
                request.getArtifact().getGroupId(),
                request.getArtifact().getArtifactId(),
                MAVEN_METADATA_XML,
                Metadata.Nature.RELEASE_OR_SNAPSHOT);

        List<MetadataRequest> metadataRequests =
                new ArrayList<>(request.getRepositories().size());

        metadataRequests.add(new MetadataRequest(metadata, null, request.getRequestContext()));

        for (RemoteRepository repository : request.getRepositories()) {
            MetadataRequest metadataRequest = new MetadataRequest(metadata, repository, request.getRequestContext());
            metadataRequest.setDeleteLocalCopyIfMissing(true);
            metadataRequest.setTrace(trace);
            metadataRequests.add(metadataRequest);
        }

        List<MetadataResult> metadataResults = metadataResolver.resolveMetadata(session, metadataRequests);

        WorkspaceReader workspace = session.getWorkspaceReader();
        if (workspace != null) {
            List<String> versions = workspace.findVersions(request.getArtifact());
            for (String version : versions) {
                versionIndex.put(version, workspace.getRepository());
            }
        }

        for (MetadataResult metadataResult : metadataResults) {
            result.addException(metadataResult.getException());

            ArtifactRepository repository = metadataResult.getRequest().getRepository();
            if (repository == null) {
                repository = session.getLocalRepository();
            }

            Versioning versioning = readVersions(session, trace, metadataResult.getMetadata(), repository, result);

            versioning = filterVersionsByRepositoryType(
                    versioning, metadataResult.getRequest().getRepository());

            for (String version : versioning.getVersions()) {
                if (!versionIndex.containsKey(version)) {
                    versionIndex.put(version, repository);
                }
            }
        }

        return versionIndex;
    }

    private Versioning readVersions(
            RepositorySystemSession session,
            RequestTrace trace,
            Metadata metadata,
            ArtifactRepository repository,
            VersionRangeResult result) {<FILL_FUNCTION_BODY>}

    private Versioning filterVersionsByRepositoryType(Versioning versioning, RemoteRepository remoteRepository) {
        if (remoteRepository == null) {
            return versioning;
        }
        return versioning.withVersions(versioning.getVersions().stream()
                .filter(version -> remoteRepository
                        .getPolicy(DefaultModelVersionParser.checkSnapshot(version))
                        .isEnabled())
                .toList());
    }

    private void invalidMetadata(
            RepositorySystemSession session,
            RequestTrace trace,
            Metadata metadata,
            ArtifactRepository repository,
            Exception exception) {
        RepositoryEvent.Builder event = new RepositoryEvent.Builder(session, EventType.METADATA_INVALID);
        event.setTrace(trace);
        event.setMetadata(metadata);
        event.setException(exception);
        event.setRepository(repository);

        repositoryEventDispatcher.dispatch(event.build());
    }
}

        Versioning versioning = null;
        try {
            if (metadata != null) {
                try (SyncContext syncContext = syncContextFactory.newInstance(session, true)) {
                    syncContext.acquire(null, Collections.singleton(metadata));

                    if (metadata.getPath() != null && Files.exists(metadata.getPath())) {
                        try (InputStream in = Files.newInputStream(metadata.getPath())) {
                            versioning =
                                    new MetadataStaxReader().read(in, false).getVersioning();
                        }
                    }
                }
            }
        } catch (Exception e) {
            invalidMetadata(session, trace, metadata, repository, e);
            result.addException(e);
        }

        return (versioning != null) ? versioning : Versioning.newInstance();
    
<no_super_class>