-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMetaController.java
More file actions
48 lines (44 loc) · 1.81 KB
/
MetaController.java
File metadata and controls
48 lines (44 loc) · 1.81 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
package org.hyperonline.hyperlib.controller.meta;
import org.hyperonline.hyperlib.controller.SendableMotorController;
import org.hyperonline.hyperlib.controller.meta.groups.ControllerGroup;
/**
* Interface that represents a meta-controller as opposed to a raw controller (see HYPER_* classes)
* @param <T> type of controller this wraps - could also be a MetaController itself
*
* @author Dheeraj Prakash
*/
public interface MetaController<T extends SendableMotorController> extends SendableMotorController {
/**
* Get the controller that this meta-controller wraps
* @return the controller this wraps
*/
T getController();
/**
* Travel down the meta-controller chain and obtain the raw controller being wrapped.
* @return the raw controller.
*
* FIXME: make this return not just SendableMotorController
*/
default SendableMotorController getRawController() {
SendableMotorController tmp = this.getController();
while (true) {
if (tmp instanceof MetaController<?>) tmp = ((MetaController<?>) tmp).getController();
else if (tmp instanceof RawController) return tmp;
}
}
/**
* Travel down the meta-controller chain and obtain the {@link ControllerGroup} being used.
* Useful to get the slave controller instead of master at the end of the chain.
* @return ControllerGroup
*
* FIXME: make this return the correct subclass
*/
default ControllerGroup<?, ?> getControllerGroup() {
SendableMotorController tmp = this.getController();
while (true) {
if (tmp instanceof ControllerGroup<?,?>) return (ControllerGroup<?, ?>) tmp;
else if (tmp instanceof MetaController<?>) tmp = ((MetaController<?>) tmp).getController();
else return null;
}
}
}