1/******************************************************************************* 2 * Copyright (c) 2009, 2017 Mountainminds GmbH & Co. KG and Contributors 3 * All rights reserved. This program and the accompanying materials 4 * are made available under the terms of the Eclipse Public License v1.0 5 * which accompanies this distribution, and is available at 6 * http://www.eclipse.org/legal/epl-v10.html 7 * 8 * Contributors: 9 * Marc R. Hoffmann - initial API and implementation 10 * 11 *******************************************************************************/ 12package org.jacoco.report.internal.html.index; 13 14import java.util.HashMap; 15import java.util.Map; 16 17import org.jacoco.report.internal.ReportOutputFolder; 18import org.jacoco.report.internal.html.ILinkable; 19 20/** 21 * An index over all report pages that allows queries according to certain 22 * criteria. 23 */ 24public class ElementIndex implements IIndexUpdate { 25 26 private final ReportOutputFolder baseFolder; 27 28 private final Map<Long, String> allClasses = new HashMap<Long, String>(); 29 30 /** 31 * Creates a new empty index for a HTML report. 32 * 33 * @param baseFolder 34 * base folder where all links are calculated relative to 35 */ 36 public ElementIndex(final ReportOutputFolder baseFolder) { 37 this.baseFolder = baseFolder; 38 } 39 40 /** 41 * Returns the link to the class with the given identifier if a 42 * corresponding page exists. 43 * 44 * @param classid 45 * class identifier 46 * @return Link or null 47 */ 48 public String getLinkToClass(final long classid) { 49 return allClasses.get(Long.valueOf(classid)); 50 } 51 52 // === IIndexUpdater === 53 54 public void addClass(final ILinkable link, final long classid) { 55 allClasses.put(Long.valueOf(classid), link.getLink(baseFolder)); 56 } 57 58} 59