001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019package org.eclipse.aether.internal.impl.collect; 020 021import java.util.ArrayList; 022import java.util.Collections; 023import java.util.Iterator; 024import java.util.List; 025 026import org.eclipse.aether.RepositorySystemSession; 027import org.eclipse.aether.collection.VersionFilter; 028import org.eclipse.aether.graph.Dependency; 029import org.eclipse.aether.repository.ArtifactRepository; 030import org.eclipse.aether.repository.RemoteRepository; 031import org.eclipse.aether.resolution.VersionRangeResult; 032import org.eclipse.aether.version.Version; 033import org.eclipse.aether.version.VersionConstraint; 034 035/** 036 * Default implementation of {@link VersionFilter.VersionFilterContext}. 037 * Internal helper class for collector implementations. 038 */ 039public final class DefaultVersionFilterContext implements VersionFilter.VersionFilterContext { 040 private final RepositorySystemSession session; 041 042 private Dependency dependency; 043 044 VersionRangeResult result; 045 046 private List<Version> versions; 047 048 public DefaultVersionFilterContext(RepositorySystemSession session) { 049 this.session = session; 050 } 051 052 public void set(Dependency dependency, VersionRangeResult result) { 053 this.dependency = dependency; 054 this.result = result; 055 this.versions = new ArrayList<>(result.getVersions()); 056 } 057 058 public List<Version> get() { 059 return new ArrayList<>(versions); 060 } 061 062 @Override 063 public RepositorySystemSession getSession() { 064 return session; 065 } 066 067 @Override 068 public Dependency getDependency() { 069 return dependency; 070 } 071 072 @Override 073 public VersionConstraint getVersionConstraint() { 074 return result.getVersionConstraint(); 075 } 076 077 @Override 078 public int getCount() { 079 return versions.size(); 080 } 081 082 @Override 083 public ArtifactRepository getRepository(Version version) { 084 return result.getRepository(version); 085 } 086 087 @Override 088 public List<RemoteRepository> getRepositories() { 089 return Collections.unmodifiableList(result.getRequest().getRepositories()); 090 } 091 092 @Override 093 public Iterator<Version> iterator() { 094 return versions.iterator(); 095 } 096 097 @Override 098 public String toString() { 099 return dependency + " " + result.getVersions(); 100 } 101}