ElementIndex.java

    1/*******************************************************************************
    2 * Copyright (c) 2009, 2010 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.html.index;
   13
   14import java.util.HashMap;
   15import java.util.Map;
   16
   17import org.jacoco.report.ReportOutputFolder;
   18import org.jacoco.report.html.ILinkable;
   19
   20/**
   21 * An index over all report pages that allows queries according to certain
   22 * criteria.
   23 * 
   24 * @author Marc R. Hoffmann
   25 * @version 0.4.1.20101007204400
   26 */
   27public class ElementIndex implements IIndexUpdate {
   28
   29    private final ReportOutputFolder baseFolder;
   30
   31    private final Map<Long, String> allClasses = new HashMap<Long, String>();
   32
   33    /**
   34     * Creates a new empty index for a HTML report.
   35     * 
   36     * @param baseFolder
   37     *            base folder where all links are calculated relative to
   38     */
   39    public ElementIndex(final ReportOutputFolder baseFolder) {
   40        this.baseFolder = baseFolder;
   41    }
   42
   43    /**
   44     * Returns the link to the class with the given identifier if a
   45     * corresponding page exists.
   46     * 
   47     * @param classid
   48     *            class identifier
   49     * @return Link or null
   50     */
   51    public String getLinkToClass(final long classid) {
   52        return allClasses.get(Long.valueOf(classid));
   53    }
   54
   55    // === IIndexUpdater ===
   56
   57    public void addClass(final ILinkable link, final long classid) {
   58        allClasses.put(Long.valueOf(classid), link.getLink(baseFolder));
   59    }
   60
   61}