Remove javax.annotation nullness annotations
[netconf.git] / netconf / netconf-console / src / main / java / org / opendaylight / netconf / console / commands / NetconfListDevicesCommand.java
index 7a1ec73f45ec67a99d77a7b04621fe968b98ab7a..445037be04749a15921e2fd2876f11ec29ee3e80 100644 (file)
@@ -5,42 +5,51 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.netconf.console.commands;
 
+import com.google.common.annotations.VisibleForTesting;
 import java.util.Map;
-import javax.annotation.Nonnull;
-import org.apache.karaf.shell.commands.Command;
-import org.apache.karaf.shell.console.AbstractAction;
-import org.apache.karaf.shell.table.ShellTable;
+import org.apache.karaf.shell.api.action.Action;
+import org.apache.karaf.shell.api.action.Command;
+import org.apache.karaf.shell.api.action.lifecycle.Reference;
+import org.apache.karaf.shell.api.action.lifecycle.Service;
+import org.apache.karaf.shell.support.table.ShellTable;
+import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.netconf.console.api.NetconfCommands;
 import org.opendaylight.netconf.console.utils.NetconfConsoleConstants;
 
-@Command(name = "netconf:list-devices", scope = "netconf", description = "List all netconf devices in the topology.")
-public class NetconfListDevicesCommand extends AbstractAction {
+@Service
+@Command(name = "list-devices", scope = "netconf", description = "List all netconf devices in the topology.")
+public class NetconfListDevicesCommand implements Action {
+
+    @Reference
+    private NetconfCommands service;
 
-    protected final NetconfCommands service;
+    public NetconfListDevicesCommand() {
+
+    }
 
-    public NetconfListDevicesCommand(final NetconfCommands service) {
+    @VisibleForTesting
+    NetconfListDevicesCommand(final NetconfCommands service) {
         this.service = service;
     }
 
     @Override
-    protected Object doExecute() throws Exception {
+    public Object execute() {
         final Map<String, Map<String, String>> allDevices = service.listDevices();
         printDevicesList(allDevices);
         return null;
     }
 
-    private void printDevicesList(@Nonnull final Map<String, Map<String, String>> allDevices) {
+    @SuppressWarnings("checkstyle:RegexpSinglelineJava")
+    private static void printDevicesList(final @NonNull Map<String, Map<String, String>> allDevices) {
         final ShellTable table = new ShellTable();
         table.column(NetconfConsoleConstants.NETCONF_ID).alignLeft();
         table.column(NetconfConsoleConstants.NETCONF_IP).alignLeft();
         table.column(NetconfConsoleConstants.NETCONF_PORT).alignLeft();
         table.column(NetconfConsoleConstants.STATUS).alignLeft();
 
-        for (final String nodeIds : allDevices.keySet()) {
-            final Map<String, String> attributes = allDevices.get(nodeIds);
+        for (final Map<String, String> attributes : allDevices.values()) {
             table.addRow().addContent(attributes.get(NetconfConsoleConstants.NETCONF_ID),
                     attributes.get(NetconfConsoleConstants.NETCONF_IP),
                     attributes.get(NetconfConsoleConstants.NETCONF_PORT),