Add method to return all defined networks.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 5 Sep 2013 04:49:22 +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
src/main/java/net/pterodactylus/xdcc/data/Channel.java

index fb3e61e..b157851 100644 (file)
@@ -17,6 +17,7 @@
 
 package net.pterodactylus.xdcc.core;
 
+import static net.pterodactylus.xdcc.data.Channel.TO_NETWORK;
 import static net.pterodactylus.xdcc.data.Download.FILTER_RUNNING;
 
 import java.io.File;
@@ -158,6 +159,15 @@ public class Core extends AbstractExecutionThreadService {
        }
 
        /**
+        * Returns all defined networks.
+        *
+        * @return All defined networks
+        */
+       public Collection<Network> networks() {
+               return FluentIterable.from(channels).transform(TO_NETWORK).toSet();
+       }
+
+       /**
         * Returns all configured channels. Due to various circumstances, configured
         * channels might not actually be joined.
         *
index 93ebfa0..ffdb6c8 100644 (file)
@@ -17,6 +17,8 @@
 
 package net.pterodactylus.xdcc.data;
 
+import com.google.common.base.Function;
+
 /**
  * Defines a channel in a {@link Network}.
  *
@@ -24,6 +26,14 @@ package net.pterodactylus.xdcc.data;
  */
 public class Channel {
 
+       /** Function to convert a channel to its network. */
+       public static final Function<Channel, Network> TO_NETWORK = new Function<Channel, Network>() {
+               @Override
+               public Network apply(Channel channel) {
+                       return channel.network();
+               }
+       };
+
        /** The network this channel belongs to. */
        private final Network network;