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   * Default implementation of {@link VersionFilter.VersionFilterContext}.
38   * Internal helper class for collector implementations.
39   */
40  public final class DefaultVersionFilterContext
41      implements VersionFilter.VersionFilterContext
42  {
43      private final RepositorySystemSession session;
44  
45      private Dependency dependency;
46  
47      VersionRangeResult result;
48  
49      private List<Version> versions;
50  
51      public DefaultVersionFilterContext( RepositorySystemSession session )
52      {
53          this.session = session;
54      }
55  
56      public void set( Dependency dependency, VersionRangeResult result )
57      {
58          this.dependency = dependency;
59          this.result = result;
60          this.versions = new ArrayList<>( result.getVersions() );
61      }
62  
63      public List<Version> get()
64      {
65          return new ArrayList<>( versions );
66      }
67  
68      @Override
69      public RepositorySystemSession getSession()
70      {
71          return session;
72      }
73  
74      @Override
75      public Dependency getDependency()
76      {
77          return dependency;
78      }
79  
80      @Override
81      public VersionConstraint getVersionConstraint()
82      {
83          return result.getVersionConstraint();
84      }
85  
86      @Override
87      public int getCount()
88      {
89          return versions.size();
90      }
91  
92      @Override
93      public ArtifactRepository getRepository( Version version )
94      {
95          return result.getRepository( version );
96      }
97  
98      @Override
99      public List<RemoteRepository> getRepositories()
100     {
101         return Collections.unmodifiableList( result.getRequest().getRepositories() );
102     }
103 
104     @Override
105     public Iterator<Version> iterator()
106     {
107         return versions.iterator();
108     }
109 
110     @Override
111     public String toString()
112     {
113         return dependency + " " + result.getVersions();
114     }
115 }