MCPcopy Create free account
hub / github.com/OpenSourcePhysics/osp / DataRefreshTool

Class DataRefreshTool

src/org/opensourcephysics/tools/DataRefreshTool.java:27–224  ·  view source on GitHub ↗

This tool sends data to any tool that requests it. @author Douglas Brown @version 1.0

Source from the content-addressed store, hash-verified

25 * @version 1.0
26 */
27public class DataRefreshTool implements Tool {
28 private static Map<Data, DataRefreshTool> tools = new HashMap<Data, DataRefreshTool>();
29 private Data data; // data source
30 protected HashSet<Data> moreData = new HashSet<Data>();
31 private HashMap<Integer, Dataset> ids = new HashMap<Integer, Dataset>();
32
33 /**
34 * Returns a DataRefreshTool for the specified data object.
35 *
36 * @param data the data
37 * @return the tool
38 */
39 public static DataRefreshTool getTool(Data data) {
40 DataRefreshTool tool = tools.get(data);
41 if (tool == null) {
42 tool = new DataRefreshTool(data);
43 tools.put(data, tool);
44 }
45 return tool;
46 }
47
48 /**
49 * Constructs a DataRefreshTool for the specified data object.
50 *
51 * @param data the data
52 */
53 private DataRefreshTool(Data data) {
54 this.data = data;
55 }
56
57 /**
58 * Sends a job to this tool and specifies a tool to reply to. The job xml
59 * defines the Data object requesting a refresh ("requestData"). The requestData
60 * is compared with this tool's Data ("localData") as follows: 1. If the
61 * requestData ID matches the localData ID, then the localData is sent back to
62 * the requester. 2. If not, then the requestData ID is compared with the IDs of
63 * all Data objects in the list returned by
64 * DataTool.getSelfContainedData(localData). If a match is found, the matching
65 * Data is sent back to the requester. 3. If not, then the requestData ID is
66 * compared with the IDs of Datasets in the list returned by
67 * DataTool.getDatasets(localData). If a match is found, the matching Dataset is
68 * sent back to the requester. 4. If not, then every Dataset ID in the list
69 * returned by DataTool.getDatasets(requestData) is compared with the IDs of
70 * Datasets in the list returned by DataTool.getDatasets(localData). All
71 * matching Datasets that are found are sent back to the requester.
72 *
73 * @param job the Job
74 * @param replyTo the tool requesting refreshed data
75 */
76 @Override
77 public void send(Job job, Tool replyTo) {
78 XMLControlElement control = new XMLControlElement(job.getXML());
79 if (control.failedToRead() || (replyTo == null) || !Data.class.isAssignableFrom(control.getObjectClass())) {
80 return;
81 }
82 Data request = (Data) control.loadObject(null, true, true);
83 // check for matching ID with localData
84 if (request.getID() == data.getID()) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected