001/* Computation of self-loops in a graph.
002
003 Copyright (c) 2002-2014 The University of Maryland. All rights reserved.
004 Permission is hereby granted, without written agreement and without
005 license or royalty fees, to use, copy, modify, and distribute this
006 software and its documentation for any purpose, provided that the above
007 copyright notice and the following two paragraphs appear in all copies
008 of this software.
009
010 IN NO EVENT SHALL THE UNIVERSITY OF MARYLAND BE LIABLE TO ANY PARTY
011 FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
012 ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
013 THE UNIVERSITY OF MARYLAND HAS BEEN ADVISED OF THE POSSIBILITY OF
014 SUCH DAMAGE.
015
016 THE UNIVERSITY OF MARYLAND SPECIFICALLY DISCLAIMS ANY WARRANTIES,
017 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
018 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
019 PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
020 MARYLAND HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
021 ENHANCEMENTS, OR MODIFICATIONS.
022
023
024 */
025package ptolemy.graph.analysis;
026
027import java.util.List;
028
029import ptolemy.graph.Graph;
030import ptolemy.graph.analysis.analyzer.Analyzer;
031import ptolemy.graph.analysis.analyzer.SelfLoopAnalyzer;
032import ptolemy.graph.analysis.strategy.SelfLoopStrategy;
033
034///////////////////////////////////////////////////////////////////
035//// SelfLoopAnalysis
036
037/**
038 Computation of self-loops in a graph.
039 A self-loop (also called a self-loop edge) in a graph is an
040 edge whose source and sink nodes are identical.
041 <p>
042 The returned collection cannot be modified when the client uses the default
043 analyzer.
044 <p>
045
046 @since Ptolemy II 2.0
047 @Pt.ProposedRating Red (shahrooz)
048 @Pt.AcceptedRating Red (ssb)
049 @author Shahrooz Shahparnia
050 @version $Id$
051 */
052public class SelfLoopAnalysis extends Analysis {
053    /** Construct an instance of this class for a given graph.
054     *
055     *  @param graph The given graph.
056     */
057    public SelfLoopAnalysis(Graph graph) {
058        super(new SelfLoopStrategy(graph));
059        ;
060    }
061
062    /** Construct an instance of this class with a given analyzer.
063     *
064     *  @param analyzer The analyzer to use.
065     */
066    public SelfLoopAnalysis(SelfLoopAnalyzer analyzer) {
067        super(analyzer);
068        ;
069    }
070
071    ///////////////////////////////////////////////////////////////////
072    ////                         public methods                    ////
073
074    /** Return the self-loop edges in the graph under analysis.
075     *  Each element of the list is an {@link ptolemy.graph.Edge}.
076     *
077     *  @return Return the self-loop edges.
078     */
079    public List edges() {
080        return ((SelfLoopAnalyzer) analyzer()).edges();
081    }
082
083    /** Return a description of the analysis and the associated analyzer.
084     *
085     *  @return A description of the analysis and the associated analyzer.
086     */
087    @Override
088    public String toString() {
089        return "Self loop analysis using the following analyzer:\n"
090                + analyzer().toString();
091    }
092
093    /** Check if a given analyzer is compatible with this analysis.
094     *  In other words if it is possible to use it to compute the computation
095     *  associated with this analysis.
096     *
097     *  @param analyzer The given analyzer.
098     *  @return True if the given analyzer is valid for this analysis.
099     */
100    @Override
101    public boolean validAnalyzerInterface(Analyzer analyzer) {
102        return analyzer instanceof SelfLoopAnalyzer;
103    }
104}