Package org.jfree.data.flow
Class DefaultFlowDataset<K extends java.lang.Comparable<K>>
- java.lang.Object
-
- org.jfree.data.general.AbstractDataset
-
- org.jfree.data.flow.DefaultFlowDataset<K>
-
- Type Parameters:
K
- the type for the keys used to identify sources and destinations (instances should be immutable,String
is a good default choice).
- All Implemented Interfaces:
java.io.ObjectInputValidation
,java.io.Serializable
,java.lang.Cloneable
,PublicCloneable
,FlowDataset<K>
,Dataset
public class DefaultFlowDataset<K extends java.lang.Comparable<K>> extends AbstractDataset implements FlowDataset<K>, PublicCloneable, java.io.Serializable
A dataset representing flows between source and destination nodes.- Since:
- 1.5.3
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<FlowKey,java.util.Map<java.lang.String,java.lang.Object>>
flowProperties
Flow properties.private java.util.Map<FlowKey<K>,java.lang.Number>
flows
Storage for the flows.private java.util.Map<NodeKey,java.util.Map<java.lang.String,java.lang.Object>>
nodeProperties
Node properties.private java.util.List<java.util.List<K>>
nodes
The nodes at each stage.
-
Constructor Summary
Constructors Constructor Description DefaultFlowDataset()
Creates a new dataset that is initially empty.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Object
clone()
Returns a clone of the dataset.boolean
equals(java.lang.Object obj)
Tests this dataset for equality with an arbitrary object.java.util.Set<FlowKey<K>>
getAllFlows()
Returns a set of keys for all the flows in the dataset.java.util.Set<NodeKey<K>>
getAllNodes()
Returns the set of keys for all the nodes in the dataset.java.util.List<K>
getDestinations(int stage)
Returns a list of the destination nodes for the specified stage.java.lang.Number
getFlow(int stage, K source, K destination)
Returns the flow between a source node and a destination node at a specified stage.java.lang.Object
getFlowProperty(FlowKey<K> flowKey, java.lang.String propertyKey)
Returns the value of a property, if specified, for the specified flow.java.util.List<FlowKey<K>>
getInFlows(NodeKey nodeKey)
Returns a list of flow keys for all the flows coming into this node.java.lang.Object
getNodeProperty(NodeKey<K> nodeKey, java.lang.String propertyKey)
Returns the value of a property, if specified, for the specified node.java.util.List<FlowKey>
getOutFlows(NodeKey nodeKey)
Returns a list of flow keys for all the flows going out of this node.java.util.List<K>
getSources(int stage)
Returns a list of the source nodes for the specified stage.int
getStageCount()
Returns the number of flow stages.int
hashCode()
void
setFlow(int stage, K source, K destination, double flow)
Sets the flow between a source node and a destination node at the specified stage.void
setFlowProperty(FlowKey<K> flowKey, java.lang.String propertyKey, java.lang.Object value)
Sets a property for the specified flow and notifies registered listeners that the dataset has changed.void
setNodeProperty(NodeKey<K> nodeKey, java.lang.String propertyKey, java.lang.Object value)
Sets a property for the specified node and notifies registered listeners that the dataset has changed.-
Methods inherited from class org.jfree.data.general.AbstractDataset
addChangeListener, canEqual, fireDatasetChanged, getGroup, getNotify, hasListener, notifyListeners, removeChangeListener, setGroup, setNotify, validateObject
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.jfree.data.general.Dataset
addChangeListener, getGroup, removeChangeListener, setGroup
-
-
-
-
Field Detail
-
nodes
private java.util.List<java.util.List<K extends java.lang.Comparable<K>>> nodes
The nodes at each stage. The list will have N+1 entries, where N is the number of stages - the last entry contains the destination nodes for the final stage.
-
nodeProperties
private java.util.Map<NodeKey,java.util.Map<java.lang.String,java.lang.Object>> nodeProperties
Node properties.
-
flows
private java.util.Map<FlowKey<K extends java.lang.Comparable<K>>,java.lang.Number> flows
Storage for the flows.
-
flowProperties
private java.util.Map<FlowKey,java.util.Map<java.lang.String,java.lang.Object>> flowProperties
Flow properties.
-
-
Method Detail
-
getSources
public java.util.List<K> getSources(int stage)
Returns a list of the source nodes for the specified stage.- Specified by:
getSources
in interfaceFlowDataset<K extends java.lang.Comparable<K>>
- Parameters:
stage
- the stage (0 togetStageCount() - 1
).- Returns:
- A list of source nodes (possibly empty but never
null
).
-
getDestinations
public java.util.List<K> getDestinations(int stage)
Returns a list of the destination nodes for the specified stage.- Specified by:
getDestinations
in interfaceFlowDataset<K extends java.lang.Comparable<K>>
- Parameters:
stage
- the stage (0 togetStageCount() - 1
).- Returns:
- A list of destination nodes (possibly empty but never
null
).
-
getAllNodes
public java.util.Set<NodeKey<K>> getAllNodes()
Returns the set of keys for all the nodes in the dataset.- Specified by:
getAllNodes
in interfaceFlowDataset<K extends java.lang.Comparable<K>>
- Returns:
- The set of keys for all the nodes in the dataset (possibly empty
but never
null
).
-
getNodeProperty
public java.lang.Object getNodeProperty(NodeKey<K> nodeKey, java.lang.String propertyKey)
Returns the value of a property, if specified, for the specified node.- Specified by:
getNodeProperty
in interfaceFlowDataset<K extends java.lang.Comparable<K>>
- Parameters:
nodeKey
- the node key (null
not permitted).propertyKey
- the node key (null
not permitted).- Returns:
- The property value, or
null
.
-
setNodeProperty
public void setNodeProperty(NodeKey<K> nodeKey, java.lang.String propertyKey, java.lang.Object value)
Sets a property for the specified node and notifies registered listeners that the dataset has changed.- Parameters:
nodeKey
- the node key (null
not permitted).propertyKey
- the property key (null
not permitted).value
- the property value.
-
getFlow
public java.lang.Number getFlow(int stage, K source, K destination)
Returns the flow between a source node and a destination node at a specified stage. This must be 0 or greater. The dataset can returnnull
to represent an unknown value.- Specified by:
getFlow
in interfaceFlowDataset<K extends java.lang.Comparable<K>>
- Parameters:
stage
- the stage index (0 togetStageCount()
- 1).source
- the source (null
not permitted).destination
- the destination (null
not permitted).- Returns:
- The flow (zero or greater, possibly
null
).
-
setFlow
public void setFlow(int stage, K source, K destination, double flow)
Sets the flow between a source node and a destination node at the specified stage. A new stage will be added ifstage
is equal togetStageCount()
.- Parameters:
stage
- the stage (0 togetStageCount()
.source
- the source (null
not permitted).destination
- the destination (null
not permitted).flow
- the flow (0 or greater).
-
getFlowProperty
public java.lang.Object getFlowProperty(FlowKey<K> flowKey, java.lang.String propertyKey)
Returns the value of a property, if specified, for the specified flow.- Specified by:
getFlowProperty
in interfaceFlowDataset<K extends java.lang.Comparable<K>>
- Parameters:
flowKey
- flowKey (null
not permitted).propertyKey
- the property key (null
not permitted).- Returns:
- The property value, or
null
.
-
setFlowProperty
public void setFlowProperty(FlowKey<K> flowKey, java.lang.String propertyKey, java.lang.Object value)
Sets a property for the specified flow and notifies registered listeners that the dataset has changed.- Parameters:
flowKey
- the node key (null
not permitted).propertyKey
- the property key (null
not permitted).value
- the property value.
-
getStageCount
public int getStageCount()
Returns the number of flow stages. A flow dataset always has one or more stages, so this method will return1
even for an empty dataset (one with no sources, destinations or flows defined).- Specified by:
getStageCount
in interfaceFlowDataset<K extends java.lang.Comparable<K>>
- Returns:
- The number of flow stages.
-
getAllFlows
public java.util.Set<FlowKey<K>> getAllFlows()
Returns a set of keys for all the flows in the dataset.- Specified by:
getAllFlows
in interfaceFlowDataset<K extends java.lang.Comparable<K>>
- Returns:
- A set.
-
getInFlows
public java.util.List<FlowKey<K>> getInFlows(NodeKey nodeKey)
Returns a list of flow keys for all the flows coming into this node.- Parameters:
nodeKey
- the node key (null
not permitted).- Returns:
- A list of flow keys (possibly empty but never
null
).
-
getOutFlows
public java.util.List<FlowKey> getOutFlows(NodeKey nodeKey)
Returns a list of flow keys for all the flows going out of this node.- Parameters:
nodeKey
- the node key (null
not permitted).- Returns:
- A list of flow keys (possibly empty but never
null
).
-
clone
public java.lang.Object clone() throws java.lang.CloneNotSupportedException
Returns a clone of the dataset.- Specified by:
clone
in interfacePublicCloneable
- Overrides:
clone
in classAbstractDataset
- Returns:
- A clone of the dataset.
- Throws:
java.lang.CloneNotSupportedException
- if there is a problem with cloning.
-
equals
public boolean equals(java.lang.Object obj)
Tests this dataset for equality with an arbitrary object. This method will returntrue
if the object implements theFlowDataset
and defines the exact same set of nodes and flows as this dataset.- Overrides:
equals
in classAbstractDataset
- Parameters:
obj
- the object to test equality against (null
permitted).- Returns:
- A boolean.
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classAbstractDataset
-
-