From: David ‘Bombe’ Roden Date: Thu, 5 Sep 2013 04:49:22 +0000 (+0200) Subject: Add method to return all defined networks. X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=0965ebe566ffbd6ee89390dd08bb8ae61654aae7;p=xudocci.git Add method to return all defined networks. --- diff --git a/src/main/java/net/pterodactylus/xdcc/core/Core.java b/src/main/java/net/pterodactylus/xdcc/core/Core.java index fb3e61e..b157851 100644 --- a/src/main/java/net/pterodactylus/xdcc/core/Core.java +++ b/src/main/java/net/pterodactylus/xdcc/core/Core.java @@ -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 networks() { + return FluentIterable.from(channels).transform(TO_NETWORK).toSet(); + } + + /** * Returns all configured channels. Due to various circumstances, configured * channels might not actually be joined. * diff --git a/src/main/java/net/pterodactylus/xdcc/data/Channel.java b/src/main/java/net/pterodactylus/xdcc/data/Channel.java index 93ebfa0..ffdb6c8 100644 --- a/src/main/java/net/pterodactylus/xdcc/data/Channel.java +++ b/src/main/java/net/pterodactylus/xdcc/data/Channel.java @@ -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 TO_NETWORK = new Function() { + @Override + public Network apply(Channel channel) { + return channel.network(); + } + }; + /** The network this channel belongs to. */ private final Network network;