import net.pterodactylus.util.thread.NamedThreadFactory;
import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.HashMultimap;
return database.getSones();
}
+ @Override
+ public Function<String, Optional<Sone>> soneLoader() {
+ return database.soneLoader();
+ }
+
/**
* Returns the Sone with the given ID, regardless whether it’s local or
* remote.
import net.pterodactylus.sone.core.Core;
import net.pterodactylus.sone.data.Sone;
+import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.google.inject.ImplementedBy;
@ImplementedBy(Core.class)
public interface SoneProvider {
+ Function<String, Optional<Sone>> soneLoader();
+
/**
* Returns the Sone with the given ID, or {@link Optional#absent()} if it
* does not exist.
import net.pterodactylus.util.config.Configuration;
import net.pterodactylus.util.config.ConfigurationException;
+import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.google.common.base.Predicate;
import com.google.common.collect.HashMultimap;
}
@Override
+ public Function<String, Optional<Sone>> soneLoader() {
+ return new Function<String, Optional<Sone>>() {
+ @Override
+ public Optional<Sone> apply(String soneId) {
+ return getSone(soneId);
+ }
+ };
+ }
+
+ @Override
public Optional<Sone> getSone(String soneId) {
lock.readLock().lock();
try {
import java.util.Arrays;
import java.util.Collection;
-import com.google.common.base.Optional;
-
-import junit.framework.TestCase;
import net.pterodactylus.sone.data.Sone;
import net.pterodactylus.sone.data.impl.IdOnlySone;
import net.pterodactylus.sone.database.SoneProvider;
+import com.google.common.base.Function;
+import com.google.common.base.Optional;
+import junit.framework.TestCase;
+
/**
* JUnit test case for {@link SoneTextParser}.
*
*/
private static class TestSoneProvider implements SoneProvider {
+ @Override
+ public Function<String, Optional<Sone>> soneLoader() {
+ return new Function<String, Optional<Sone>>() {
+ @Override
+ public Optional<Sone> apply(String soneId) {
+ return getSone(soneId);
+ }
+ };
+ }
+
/**
* {@inheritDoc}
*/