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