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   * @version $Id: MetadataGraph.java 958295 2010-06-26 23:16:18Z hboutemy $
30   *
31   */
32  public class MetadataGraph
33  {
34      /** all graph nodes */
35      Collection<MetadataGraphNode> nodes;
36  
37      /** entry point for tree-like structures */
38      MetadataGraphNode entry;
39  
40      public MetadataGraph( MetadataGraphNode entry )
41      {
42          this();
43  
44          this.entry = entry;
45      }
46  
47      public MetadataGraph()
48      {
49          nodes = new ArrayList<MetadataGraphNode>( 64 );
50      }
51  
52      public void addNode( MetadataGraphNode node )
53      {
54          nodes.add( node );
55      }
56  
57      /**
58       * find a node by the GAV (metadata)
59       *
60       * @param md
61       * @return
62       */
63      public MetadataGraphNode findNode( MavenArtifactMetadata md )
64      {
65          for ( MetadataGraphNode mgn : nodes )
66          {
67              if ( mgn.metadata.equals( md ) )
68              {
69                  return mgn;
70              }
71          }
72  
73          MetadataGraphNode node = new MetadataGraphNode( md );
74          addNode( node );
75          return node;
76      }
77  
78      /**
79       * getter
80       *
81       * @return
82       */
83      public MetadataGraphNode getEntry()
84      {
85          return entry;
86      }
87  
88      /**
89       * getter
90       *
91       * @return
92       */
93      public Collection<MetadataGraphNode> getNodes()
94      {
95          return nodes;
96      }
97  }