001/* Computation of source nodes 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.SourceNodeAnalyzer; 032import ptolemy.graph.analysis.strategy.SourceNodeStrategy; 033 034/////////////////////////////////////////////////////////////////// 035//// SourceNodeAnalysis 036 037/** 038 Computation of source nodes in a graph. 039 A source node in a graph is a node without input edges. 040 <p> 041 The returned collection cannot be modified when the client uses the default 042 analyzer. 043 <p> 044 @since Ptolemy II 2.0 045 @Pt.ProposedRating Red (shahrooz) 046 @Pt.AcceptedRating Red (ssb) 047 @author Shahrooz Shahparnia 048 @version $Id$ 049 */ 050public class SourceNodeAnalysis extends Analysis { 051 /** Construct an instance of this class for a given graph. 052 * 053 * @param graph The given graph. 054 */ 055 public SourceNodeAnalysis(Graph graph) { 056 super(new SourceNodeStrategy(graph)); 057 } 058 059 /** Construct an instance of this class using a given analyzer. 060 * 061 * @param analyzer The given analyzer. 062 */ 063 public SourceNodeAnalysis(SourceNodeAnalyzer analyzer) { 064 super(analyzer); 065 } 066 067 /////////////////////////////////////////////////////////////////// 068 //// public methods //// 069 070 /** Return the source nodes in the graph under analysis. 071 * Each element of the collection is an {@link ptolemy.graph.Node}. 072 * 073 * @return Return the source nodes. 074 */ 075 public List nodes() { 076 return ((SourceNodeAnalyzer) analyzer()).nodes(); 077 } 078 079 /** Return a description of the analysis and the associated analyzer. 080 * 081 * @return A description of the analysis and the associated analyzer. 082 */ 083 @Override 084 public String toString() { 085 return "Source node analysis using the following analyzer:\n" 086 + analyzer().toString(); 087 } 088 089 /** Check if a given analyzer is compatible with this analysis. 090 * In other words if it is possible to use it to compute the computation 091 * associated with this analysis. 092 * 093 * @param analyzer The given analyzer. 094 * @return True if the given analyzer is valid for this analysis. 095 */ 096 @Override 097 public boolean validAnalyzerInterface(Analyzer analyzer) { 098 return analyzer instanceof SourceNodeAnalyzer; 099 } 100}