001    package org.apache.maven.repository;
002    
003    /*
004     * Licensed to the Apache Software Foundation (ASF) under one
005     * or more contributor license agreements.  See the NOTICE file
006     * distributed with this work for additional information
007     * regarding copyright ownership.  The ASF licenses this file
008     * to you under the Apache License, Version 2.0 (the
009     * "License"); you may not use this file except in compliance
010     * with the License.  You may obtain a copy of the License at
011     *
012     *   http://www.apache.org/licenses/LICENSE-2.0
013     *
014     * Unless required by applicable law or agreed to in writing,
015     * software distributed under the License is distributed on an
016     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017     * KIND, either express or implied.  See the License for the
018     * specific language governing permissions and limitations
019     * under the License.
020     */
021    
022    import java.util.ArrayList;
023    import java.util.Collection;
024    
025    /**
026     * This is the main graph data structure used by the RepositorySystem to present tree and graph objects.
027     *
028     * @author Oleg Gusakov
029     *
030     */
031    public class MetadataGraph
032    {
033        /** all graph nodes */
034        Collection<MetadataGraphNode> nodes;
035    
036        /** entry point for tree-like structures */
037        MetadataGraphNode entry;
038    
039        public MetadataGraph( MetadataGraphNode entry )
040        {
041            this();
042    
043            this.entry = entry;
044        }
045    
046        public MetadataGraph()
047        {
048            nodes = new ArrayList<MetadataGraphNode>( 64 );
049        }
050    
051        public void addNode( MetadataGraphNode node )
052        {
053            nodes.add( node );
054        }
055    
056        /**
057         * find a node by the GAV (metadata)
058         *
059         * @param md
060         * @return
061         */
062        public MetadataGraphNode findNode( MavenArtifactMetadata md )
063        {
064            for ( MetadataGraphNode mgn : nodes )
065            {
066                if ( mgn.metadata.equals( md ) )
067                {
068                    return mgn;
069                }
070            }
071    
072            MetadataGraphNode node = new MetadataGraphNode( md );
073            addNode( node );
074            return node;
075        }
076    
077        /**
078         * getter
079         *
080         * @return
081         */
082        public MetadataGraphNode getEntry()
083        {
084            return entry;
085        }
086    
087        /**
088         * getter
089         *
090         * @return
091         */
092        public Collection<MetadataGraphNode> getNodes()
093        {
094            return nodes;
095        }
096    }