001    /*
002     * Sonar, open source software quality management tool.
003     * Copyright (C) 2009 SonarSource SA
004     * mailto:contact AT sonarsource DOT com
005     *
006     * Sonar is free software; you can redistribute it and/or
007     * modify it under the terms of the GNU Lesser General Public
008     * License as published by the Free Software Foundation; either
009     * version 3 of the License, or (at your option) any later version.
010     *
011     * Sonar is distributed in the hope that it will be useful,
012     * but WITHOUT ANY WARRANTY; without even the implied warranty of
013     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014     * Lesser General Public License for more details.
015     *
016     * You should have received a copy of the GNU Lesser General Public
017     * License along with Sonar; if not, write to the Free Software
018     * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
019     */
020    package org.sonar.api.batch;
021    
022    import java.util.Collection;
023    import java.util.Date;
024    import java.util.List;
025    import java.util.Set;
026    
027    import org.sonar.api.design.Dependency;
028    import org.sonar.api.measures.Measure;
029    import org.sonar.api.measures.MeasuresFilter;
030    import org.sonar.api.measures.Metric;
031    import org.sonar.api.resources.Project;
032    import org.sonar.api.resources.ProjectLink;
033    import org.sonar.api.resources.Resource;
034    import org.sonar.api.rules.Violation;
035    import org.sonar.graph.DirectedGraphAccessor;
036    
037    public abstract class SonarIndex implements DirectedGraphAccessor<Resource, Dependency> {
038    
039      public abstract Project getProject();
040    
041      public abstract Resource getResource(Resource resource);
042    
043      public final Collection<Resource> getResources() {
044        return getVertices();
045      }
046    
047      public abstract List<Resource> getChildren(Resource resource);
048    
049      public abstract Resource addResource(Resource resource);
050    
051      public abstract Measure getMeasure(Resource resource, Metric metric);
052    
053      public abstract <M> M getMeasures(Resource resource, MeasuresFilter<M> filter);
054    
055      public abstract void setSource(Resource resource, String source);
056    
057      /**
058       * @since 2.5
059       */
060      public abstract void addViolation(Violation violation, boolean force);
061    
062      public final void addViolation(Violation violation) {
063        addViolation(violation, false);
064      }
065    
066      public abstract Measure addMeasure(Resource resource, Measure measure);
067    
068      public abstract Dependency addDependency(Dependency dependency);
069    
070      public abstract Set<Dependency> getDependencies();
071    
072      public abstract void addLink(ProjectLink link);
073    
074      public abstract void deleteLink(String key);
075    
076      public abstract List<Event> getEvents(Resource resource);
077    
078      public abstract void deleteEvent(Event event);
079    
080      public abstract Event addEvent(Resource resource, String name, String description, String category, Date date);
081    
082      public final Collection<Dependency> getOutgoingDependencies(Resource from) {
083        return getOutgoingEdges(from);
084      }
085    
086      public final Collection<Dependency> getIncomingDependencies(Resource to) {
087        return getIncomingEdges(to);
088      }
089    }