edu.uci.ics.jung.utils
Class UserData
java.lang.Object
edu.uci.ics.jung.utils.UserData
- All Implemented Interfaces:
- UserDataContainer, Cloneable
- Direct Known Subclasses:
- DefaultUserData, UnifiedUserData
public abstract class UserData
- extends Object
- implements UserDataContainer
Represents custom user- and system-level information to extend the definition
of a node. This is the easiest way to extend the class without subclassing.
This works as a dictionary in order to help ensure that there are
possibilities for extending user information to a variety of different sorts
of data. (Each provider of information can register their own enhanced
information without interfering with other providers.)
Some suggested uses of UserData include
Underlying data references, such as pointers to data sources
Raw data which can be analyzed or used by the constraint and filter systems
Temporary enhanced information which can be used for visualization
Consider a series of nodes that has, among other things, enhanced information
about 3D coordinates. This might be stored in the 3DData data structure,
which generates itself with an input from a node.
Thus the relevant call might be n.setUserInfo ("3DData", new 3DData (
))
.
Later, to access this information, the call might be 3DData dd =
(3DData) n.getUserInfo("3DData").
Shared and Individual Data
Note that the there are no required semantics for the key or the information.
However, it is necessary to specify information that is used for SHARED and
for INDIVIDUAL data elements. When a new View of a graph is
generated, the Node elements inside it are all shallow-copied. The UserInfo
that they use, however, is not copied, by default. This is the
correct and logical behavior if the UserInfo contains source information.
But what when the UserInfo contains transient information, specific to the
view, such as graph metrics or coordinates? In that case, the UserInfo would
be quite inappropriate to share that information between copies.
The solution to this is to add a third flag, "shared", which tells whether
the currect data is shared or not. This flag is assigned when the data is
added.
CLONE
public static final UserDataContainer.CopyAction CLONE
- A CopyAction that clones UserData--that is, it uses the Java
clone()
call to clone the object. Throws
a CloneNotSupportedException if clone isn't allowed.
SHARED
public static final UserDataContainer.CopyAction SHARED
- A CopyAction that links UserData--that is, points to the original data.
At that point, both UserDataContainers will contain references to the
same UserData, and, if that data is mutable, will both see changes to it.
(In the case of immutable user data, such as Strings, they will
disconnect if one or the other attempts to change its value: this is the
normal behavior with
String s = "X";
String t = s;
s = "Y";
System.out.pritnln( t ); // will still contain X.
REMOVE
public static final UserDataContainer.CopyAction REMOVE
- Causes the userdata not to be copied over, and instead returns null.
Useful for temporary userdata that isn't meant to be used.
UserData
public UserData()
toString
public String toString()
- Overrides:
toString
in class Object
- See Also:
Object.toString()
clone
public Object clone()
throws CloneNotSupportedException
- Specified by:
clone
in interface UserDataContainer
- Overrides:
clone
in class Object
- Throws:
CloneNotSupportedException