Add method to return all connected networks.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 5 Sep 2013 04:49:33 +0000 (06:49 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 6 Sep 2013 23:36:04 +0000 (01:36 +0200)
src/main/java/net/pterodactylus/xdcc/core/Core.java

index b157851..d13b486 100644 (file)
@@ -70,6 +70,7 @@ import net.pterodactylus.xdcc.data.Network;
 import net.pterodactylus.xdcc.data.Pack;
 import net.pterodactylus.xdcc.data.Server;
 
+import com.google.common.base.Function;
 import com.google.common.base.Optional;
 import com.google.common.base.Predicate;
 import com.google.common.collect.FluentIterable;
@@ -168,6 +169,20 @@ public class Core extends AbstractExecutionThreadService {
        }
 
        /**
+        * Returns all connected networks.
+        *
+        * @return All connected networks
+        */
+       public Collection<Network> connectedNetworks() {
+               return Lists.newArrayList(Optional.presentInstances(FluentIterable.from(networkConnections.values()).transform(new Function<Connection, Optional<Network>>() {
+                       @Override
+                       public Optional<Network> apply(Connection connection) {
+                               return getNetwork(connection);
+                       }
+               })));
+       }
+
+       /**
         * Returns all configured channels. Due to various circumstances, configured
         * channels might not actually be joined.
         *