001    package org.apache.maven.lifecycle.internal;
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 org.apache.maven.project.MavenProject;
023    
024    import java.util.HashMap;
025    import java.util.List;
026    import java.util.Map;
027    
028    /**
029     * Provides the positional index of the project
030     * 
031     * @since 3.0
032     * @author Benjamin Bentmann
033     * @author Kristian Rosenvold (extracted class only)
034     *         <p/>
035     *         NOTE: This class is not part of any public api and can be changed or deleted without prior notice.
036     */
037    // Todo: Kristian wonders if this class really is necessary and if it overlaps other concepts.
038    public final class ProjectIndex
039    {
040    
041        private final Map<String, MavenProject> projects;
042    
043        private final Map<String, Integer> indices;
044    
045        public ProjectIndex( List<MavenProject> projects )
046        {
047            this.projects = new HashMap<String, MavenProject>( projects.size() * 2 );
048            this.indices = new HashMap<String, Integer>( projects.size() * 2 );
049    
050            for ( int i = 0; i < projects.size(); i++ )
051            {
052                MavenProject project = projects.get( i );
053                String key = BuilderCommon.getKey( project );
054    
055                this.getProjects().put( key, project );
056                this.getIndices().put( key, i );
057            }
058        }
059    
060        public Map<String, MavenProject> getProjects()
061        {
062            return projects;
063        }
064    
065        public Map<String, Integer> getIndices()
066        {
067            return indices;
068        }
069    }