added method for getting mote interfaces based on class names + getInterfaces() returns a collection instead of a vector

This commit is contained in:
fros4943 2010-03-14 19:50:34 +00:00
parent 4710441bb6
commit 4fa88d2bfd
2 changed files with 30 additions and 13 deletions

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: MoteInterfaceHandler.java,v 1.8 2009/04/20 16:13:11 fros4943 Exp $
* $Id: MoteInterfaceHandler.java,v 1.9 2010/03/14 19:50:34 fros4943 Exp $
*/
package se.sics.cooja;
@ -50,7 +50,7 @@ import se.sics.cooja.interfaces.*;
public class MoteInterfaceHandler {
private static Logger logger = Logger.getLogger(MoteInterfaceHandler.class);
private Vector<MoteInterface> allInterfaces = new Vector<MoteInterface>();
private ArrayList<MoteInterface> moteInterfaces = new ArrayList<MoteInterface>();
/* Cached interfaces */
private Battery myBattery;
@ -104,7 +104,7 @@ public class MoteInterfaceHandler {
* @return Mote interface, or null if no interface exists of given type
*/
public <N extends MoteInterface> N getInterfaceOfType(Class<N> interfaceType) {
for (MoteInterface intf : allInterfaces) {
for (MoteInterface intf : moteInterfaces) {
if (interfaceType.isAssignableFrom(intf.getClass())) {
return (N) intf;
}
@ -113,6 +113,23 @@ public class MoteInterfaceHandler {
return null;
}
/**
* Returns the first interface with a class name that ends with the given arguments.
* Example: mote.getInterfaces().get("Temperature");
*
* @param <N>
* @param classname
* @return
*/
public MoteInterface get(String classname) {
for (MoteInterface intf : moteInterfaces) {
if (intf.getClass().getName().endsWith(classname)) {
return intf;
}
}
return null;
}
/**
* Returns the battery interface (if any).
*
@ -261,7 +278,7 @@ public class MoteInterfaceHandler {
public void doActiveActionsBeforeTick() {
if (polledBeforeActive == null) {
ArrayList<PolledBeforeActiveTicks> intfs = new ArrayList<PolledBeforeActiveTicks>();
for (MoteInterface intf: allInterfaces) {
for (MoteInterface intf: moteInterfaces) {
if (intf instanceof PolledBeforeActiveTicks) {
intfs.add((PolledBeforeActiveTicks)intf);
}
@ -280,7 +297,7 @@ public class MoteInterfaceHandler {
public void doActiveActionsAfterTick() {
if (polledAfterActive == null) {
ArrayList<PolledAfterActiveTicks> intfs = new ArrayList<PolledAfterActiveTicks>();
for (MoteInterface intf: allInterfaces) {
for (MoteInterface intf: moteInterfaces) {
if (intf instanceof PolledAfterActiveTicks) {
intfs.add((PolledAfterActiveTicks)intf);
}
@ -299,7 +316,7 @@ public class MoteInterfaceHandler {
public void doPassiveActionsBeforeTick() {
if (polledBeforeAll == null) {
ArrayList<PolledBeforeAllTicks> intfs = new ArrayList<PolledBeforeAllTicks>();
for (MoteInterface intf: allInterfaces) {
for (MoteInterface intf: moteInterfaces) {
if (intf instanceof PolledBeforeAllTicks) {
intfs.add((PolledBeforeAllTicks)intf);
}
@ -318,7 +335,7 @@ public class MoteInterfaceHandler {
public void doPassiveActionsAfterTick() {
if (polledAfterAll == null) {
ArrayList<PolledAfterAllTicks> intfs = new ArrayList<PolledAfterAllTicks>();
for (MoteInterface intf: allInterfaces) {
for (MoteInterface intf: moteInterfaces) {
if (intf instanceof PolledAfterAllTicks) {
intfs.add((PolledAfterAllTicks)intf);
}
@ -334,8 +351,8 @@ public class MoteInterfaceHandler {
/**
* @return Mote interfaces
*/
public Vector<MoteInterface> getInterfaces() {
return allInterfaces;
public Collection<MoteInterface> getInterfaces() {
return moteInterfaces;
}
/**
@ -348,7 +365,7 @@ public class MoteInterfaceHandler {
* @see PolledAfterAllTicks
*/
public void addInterface(MoteInterface intf) {
allInterfaces.add(intf);
moteInterfaces.add(intf);
polledBeforeActive = null;
polledAfterActive = null;
@ -357,6 +374,6 @@ public class MoteInterfaceHandler {
}
public String toString() {
return "Mote interfaces handler (" + allInterfaces.size() + " mote interfaces)";
return "Mote interfaces handler (" + moteInterfaces.size() + " mote interfaces)";
}
}

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: MoteInterfaceViewer.java,v 1.8 2010/01/15 10:54:42 fros4943 Exp $
* $Id: MoteInterfaceViewer.java,v 1.9 2010/03/14 19:50:34 fros4943 Exp $
*/
package se.sics.cooja.plugins;
@ -115,7 +115,7 @@ public class MoteInterfaceViewer extends VisPlugin implements HasQuickHelp, Mote
interfacePanel.removeAll();
String interfaceDescription = (String) selectInterfaceComboBox.getSelectedItem();
selectedMoteInterface = null;
Vector<MoteInterface> intfs = mote.getInterfaces().getInterfaces();
Collection<MoteInterface> intfs = mote.getInterfaces().getInterfaces();
for (MoteInterface intf : intfs) {
if (GUI.getDescriptionOf(intf).equals(interfaceDescription)) {
selectedMoteInterface = intf;