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