-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunctionalUnit.java
More file actions
132 lines (110 loc) · 2.96 KB
/
FunctionalUnit.java
File metadata and controls
132 lines (110 loc) · 2.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package foon;
import java.util.*;
public class FunctionalUnit {
public enum nodeType {Input, Output}; // just to make one single function to add stuff to FU
private List<Thing> inputNodes, // input Objects
outputNodes; // output Objects
private Thing motionNode; // Motion observed in the FU
public FunctionalUnit() {
inputNodes = new ArrayList<Thing>();
outputNodes = new ArrayList<Thing>();
motionNode = new Thing();
}
public void addObjectNode(Thing O, nodeType N) {
if (N == nodeType.Input){
inputNodes.add(O);
} else {
outputNodes.add(O);
}
}
public boolean equals(FunctionalUnit U){
int results = 0; // this number must add up to three (3) which suggests that all parts match!
int count = 0; // counter used to determine number of hits (true matches)
// checking if the input nodes are all the same!
for(Thing T : this.inputNodes){
for (Thing TU : U.inputNodes){
if (((Object)T).equals((Object)TU)){
count++;
}
}
}
// if the counter matches up to the number of inputs,
// then that means we have the same set of inputs.
if (count == this.getNumberOfInputs()){
results++;
}
// checking if the Motion is the same
if (((Motion)this.motionNode).equals((Motion)U.motionNode)){
results++;
}
// checking if the output nodes are all the same!
count = 0;
for(Thing T : this.outputNodes){
for (Thing TU : U.outputNodes){
if (((Object)T).equals((Object)TU)){
count++;
}
}
}
if (count == this.getNumberOfInputs()){
results++;
}
// simply return true or false depending on the value of results
return (results == 3);
}
public Thing getMotion(){
return motionNode;
}
public List<Thing> getInputList(){
return inputNodes;
}
public List<Thing> getOutputList(){
return outputNodes;
}
public void setMotion(Thing M){
motionNode = M;
}
public void setInputList(List<Thing> L){
inputNodes = L;
}
public void setOutputList(List<Thing> L){
outputNodes = L;
}
public int getNumberOfInputs(){
return inputNodes.size();
}
public int getNumberOfOutputs(){
return outputNodes.size();
}
public void printFunctionalUnit(){
// print all input Object nodes
for (Thing T: inputNodes){
((Object)T).printObject();
}
// print the Motion node
((Motion)motionNode).printMotion();
// print all output Object nodes
for (Thing T: outputNodes){
((Object)T).printObject();
}
}
public String getInputsForFile(){
String cat = "";
for (Thing T : inputNodes){
// just keep adding all Strings which describe all Objects and then return
cat = cat + (((Object)T).getObject()) + "\n";
}
return cat;
}
public String getMotionForFile(){
return ((Motion)motionNode).getMotion() + "\n";
}
public String getOutputsForFile(){
String cat = "";
for (Thing T : outputNodes){
// just keep adding all Strings which describe all Objects and then return
cat = cat + (((Object)T).getObject()) + "\n";
}
return cat;
}
}