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 */
61 public MetadataGraphNode findNode( MavenArtifactMetadata md )
62 {
63 for ( MetadataGraphNode mgn : nodes )
64 {
65 if ( mgn.metadata.equals( md ) )
66 {
67 return mgn;
68 }
69 }
70
71 MetadataGraphNode node = new MetadataGraphNode( md );
72 addNode( node );
73 return node;
74 }
75
76 /**
77 * getter
78 */
79 public MetadataGraphNode getEntry()
80 {
81 return entry;
82 }
83
84 /**
85 * getter
86 */
87 public Collection<MetadataGraphNode> getNodes()
88 {
89 return nodes;
90 }
91 }