View Javadoc
1   package org.apache.maven.repository;
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.Collection;
24  
25  /**
26   * This is the main graph data structure used by the RepositorySystem to present tree and graph objects.
27   *
28   * @author Oleg Gusakov
29   *
30   */
31  public class MetadataGraph
32  {
33      /** all graph nodes */
34      Collection<MetadataGraphNode> nodes;
35  
36      /** entry point for tree-like structures */
37      MetadataGraphNode entry;
38  
39      public MetadataGraph( MetadataGraphNode entry )
40      {
41          this();
42  
43          this.entry = entry;
44      }
45  
46      public MetadataGraph()
47      {
48          nodes = new ArrayList<>( 64 );
49      }
50  
51      public void addNode( MetadataGraphNode node )
52      {
53          nodes.add( node );
54      }
55  
56      /**
57       * find a node by the GAV (metadata)
58       *
59       * @param md
60       * @return
61       */
62      public MetadataGraphNode findNode( MavenArtifactMetadata md )
63      {
64          for ( MetadataGraphNode mgn : nodes )
65          {
66              if ( mgn.metadata.equals( md ) )
67              {
68                  return mgn;
69              }
70          }
71  
72          MetadataGraphNode node = new MetadataGraphNode( md );
73          addNode( node );
74          return node;
75      }
76  
77      /**
78       * getter
79       *
80       * @return
81       */
82      public MetadataGraphNode getEntry()
83      {
84          return entry;
85      }
86  
87      /**
88       * getter
89       *
90       * @return
91       */
92      public Collection<MetadataGraphNode> getNodes()
93      {
94          return nodes;
95      }
96  }