From 0965ebe566ffbd6ee89390dd08bb8ae61654aae7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Thu, 5 Sep 2013 06:49:22 +0200 Subject: [PATCH] Add method to return all defined networks. --- src/main/java/net/pterodactylus/xdcc/core/Core.java | 10 ++++++++++ src/main/java/net/pterodactylus/xdcc/data/Channel.java | 10 ++++++++++ 2 files changed, 20 insertions(+) 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; -- 2.7.4