View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.eclipse.aether.internal.impl.collect;
20  
21  import java.util.ArrayList;
22  import java.util.Collections;
23  import java.util.Iterator;
24  import java.util.List;
25  
26  import org.eclipse.aether.RepositorySystemSession;
27  import org.eclipse.aether.collection.VersionFilter;
28  import org.eclipse.aether.graph.Dependency;
29  import org.eclipse.aether.repository.ArtifactRepository;
30  import org.eclipse.aether.repository.RemoteRepository;
31  import org.eclipse.aether.resolution.VersionRangeResult;
32  import org.eclipse.aether.version.Version;
33  import org.eclipse.aether.version.VersionConstraint;
34  
35  /**
36   * Default implementation of {@link VersionFilter.VersionFilterContext}.
37   * Internal helper class for collector implementations.
38   */
39  public final class DefaultVersionFilterContext implements VersionFilter.VersionFilterContext {
40      private final RepositorySystemSession session;
41  
42      private Dependency dependency;
43  
44      VersionRangeResult result;
45  
46      private List<Version> versions;
47  
48      public DefaultVersionFilterContext(RepositorySystemSession session) {
49          this.session = session;
50      }
51  
52      public void set(Dependency dependency, VersionRangeResult result) {
53          this.dependency = dependency;
54          this.result = result;
55          this.versions = new ArrayList<>(result.getVersions());
56      }
57  
58      public List<Version> get() {
59          return new ArrayList<>(versions);
60      }
61  
62      @Override
63      public RepositorySystemSession getSession() {
64          return session;
65      }
66  
67      @Override
68      public Dependency getDependency() {
69          return dependency;
70      }
71  
72      @Override
73      public VersionConstraint getVersionConstraint() {
74          return result.getVersionConstraint();
75      }
76  
77      @Override
78      public int getCount() {
79          return versions.size();
80      }
81  
82      @Override
83      public ArtifactRepository getRepository(Version version) {
84          return result.getRepository(version);
85      }
86  
87      @Override
88      public List<RemoteRepository> getRepositories() {
89          return Collections.unmodifiableList(result.getRequest().getRepositories());
90      }
91  
92      @Override
93      public Iterator<Version> iterator() {
94          return versions.iterator();
95      }
96  
97      @Override
98      public String toString() {
99          return dependency + " " + result.getVersions();
100     }
101 }