001/* ===========================================================
002 * JFreeChart : a free chart library for the Java(tm) platform
003 * ===========================================================
004 *
005 * (C) Copyright 2000-present, by David Gilbert and Contributors.
006 *
007 * Project Info:  http://www.jfree.org/jfreechart/index.html
008 *
009 * This library is free software; you can redistribute it and/or modify it
010 * under the terms of the GNU Lesser General Public License as published by
011 * the Free Software Foundation; either version 2.1 of the License, or
012 * (at your option) any later version.
013 *
014 * This library is distributed in the hope that it will be useful, but
015 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
016 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
017 * License for more details.
018 *
019 * You should have received a copy of the GNU Lesser General Public
020 * License along with this library; if not, write to the Free Software
021 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
022 * USA.
023 *
024 * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. 
025 * Other names may be trademarks of their respective owners.]
026 *
027 * ----------------
028 * FlowDataset.java
029 * ----------------
030 * (C) Copyright 2022-present, by David Gilbert and Contributors.
031 *
032 * Original Author:  David Gilbert;
033 * Contributor(s):   -;
034 *
035 */
036
037package org.jfree.data.flow;
038
039import java.util.List;
040import java.util.Set;
041import org.jfree.data.general.Dataset;
042
043/**
044 * A dataset representing value flows from a set of source nodes to a set of 
045 * destination nodes.  The number of source nodes does not need to match the
046 * number of destination nodes.
047 * <br><br>
048 * The dataset can represent flows in one or many stages.  In the simple case,
049 * the flows are defined in one stage, going directly from a source node to 
050 * the final destination node.  In a multi-stage dataset there will be groups
051 * of intermediate nodes and the flows are defined stage-by-stage from the
052 * source to the destination.
053 * 
054 * @param <K> the type for the keys used to identify sources and destinations 
055 *     (instances should be immutable, {@code String} is a good default choice).
056 * 
057 * @since 1.5.3
058 */
059public interface FlowDataset<K extends Comparable<K>> extends Dataset {
060
061    /**
062     * Returns the number of flow stages (never less than one).
063     * 
064     * @return The number of flow stages.
065     */
066    int getStageCount();
067    
068    /**
069     * Returns a list of the sources at the specified stage.
070     * 
071     * @param stage  the stage index (0 to {@code getStageCount()} - 1).
072     * 
073     * @return A list of the sources at the specified stage (never {@code null}).
074     */
075    List<K> getSources(int stage);
076    
077    /**
078     * Returns a list of the destinations at the specified stage.  For a 
079     * multi-stage dataset, the destinations at stage N are the same as the
080     * sources at stage N+1.
081     * 
082     * @param stage  the stage index (0 to {@code getStageCount()} - 1).
083     * 
084     * @return A list of the sources at the specified stage (never {@code null}).
085     */
086    List<K> getDestinations(int stage);
087
088    /**
089     * Returns the set of keys for all the nodes in the dataset.
090     * 
091     * @return The set of keys for all the nodes in the dataset (possibly empty but never {@code null}).
092     */
093    Set<NodeKey<K>> getAllNodes();
094    
095    /**
096     * Returns the value of a property, if specified, for the specified node.  
097     *
098     * @param nodeKey  the node key ({@code null} not permitted).
099     * @param propertyKey  the node key ({@code null} not permitted).
100     * 
101     * @return The property value, or {@code null}. 
102     */    
103    Object getNodeProperty(NodeKey<K> nodeKey, String propertyKey);
104
105    /**
106     * Returns the flow between a source node and a destination node at a
107     * specified stage.  This must be 0 or greater.  The dataset can return
108     * {@code null} to represent an unknown value.
109     * 
110     * @param stage  the stage index (0 to {@code getStageCount()} - 1).
111     * @param source  the source ({@code null} not permitted). 
112     * @param destination  the destination ({@code null} not permitted).
113     * 
114     * @return The flow (zero or greater, possibly {@code null}). 
115     */
116    Number getFlow(int stage, K source, K destination);
117    
118    /**
119     * Returns a set of keys for all the flows in the dataset.
120     * 
121     * @return A set. 
122     */
123    Set<FlowKey<K>> getAllFlows();
124
125    /**
126     * Returns the value of a property, if specified, for the specified flow.  
127     * 
128     * @param flowKey  the flow key ({@code null} not permitted).
129     * @param propertyKey  the property key ({@code null} not permitted).
130     * 
131     * @return The property value, or {@code null}. 
132     */    
133    Object getFlowProperty(FlowKey<K> flowKey, String propertyKey);
134
135}
136