projects
/
Sone.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
18a698e
)
Add method to expose a Sone loader.
author
David ‘Bombe’ Roden
<bombe@pterodactylus.net>
Mon, 4 Nov 2013 05:26:47 +0000
(06:26 +0100)
committer
David ‘Bombe’ Roden
<bombe@pterodactylus.net>
Fri, 28 Feb 2014 21:25:51 +0000
(22:25 +0100)
src/main/java/net/pterodactylus/sone/core/Core.java
patch
|
blob
|
history
src/main/java/net/pterodactylus/sone/database/SoneProvider.java
patch
|
blob
|
history
src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java
patch
|
blob
|
history
diff --git
a/src/main/java/net/pterodactylus/sone/core/Core.java
b/src/main/java/net/pterodactylus/sone/core/Core.java
index
8fcfe10
..
8e6f1b0
100644
(file)
--- a/
src/main/java/net/pterodactylus/sone/core/Core.java
+++ b/
src/main/java/net/pterodactylus/sone/core/Core.java
@@
-97,6
+97,7
@@
import net.pterodactylus.util.number.Numbers;
import net.pterodactylus.util.service.AbstractService;
import net.pterodactylus.util.thread.NamedThreadFactory;
import net.pterodactylus.util.service.AbstractService;
import net.pterodactylus.util.thread.NamedThreadFactory;
+import com.google.common.base.Function;
import freenet.keys.FreenetURI;
import com.google.common.base.Optional;
import freenet.keys.FreenetURI;
import com.google.common.base.Optional;
@@
-330,6
+331,11
@@
public class Core extends AbstractService implements SoneProvider {
}
@Override
}
@Override
+ public Function<String, Optional<Sone>> getSone() {
+ return database.getSone();
+ }
+
+ @Override
public Optional<Sone> getSone(String id) {
synchronized (sones) {
return Optional.fromNullable(sones.get(id));
public Optional<Sone> getSone(String id) {
synchronized (sones) {
return Optional.fromNullable(sones.get(id));
diff --git
a/src/main/java/net/pterodactylus/sone/database/SoneProvider.java
b/src/main/java/net/pterodactylus/sone/database/SoneProvider.java
index
993804f
..
b944ab8
100644
(file)
--- a/
src/main/java/net/pterodactylus/sone/database/SoneProvider.java
+++ b/
src/main/java/net/pterodactylus/sone/database/SoneProvider.java
@@
-21,6
+21,7
@@
import java.util.Collection;
import net.pterodactylus.sone.data.Sone;
import net.pterodactylus.sone.data.Sone;
+import com.google.common.base.Function;
import com.google.common.base.Optional;
/**
import com.google.common.base.Optional;
/**
@@
-30,6
+31,8
@@
import com.google.common.base.Optional;
*/
public interface SoneProvider {
*/
public interface SoneProvider {
+ Function<String, Optional<Sone>> getSone();
+
/**
* Returns the Sone with the given ID, or {@link Optional#absent()} if it
* does not exist.
/**
* Returns the Sone with the given ID, or {@link Optional#absent()} if it
* does not exist.
diff --git
a/src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java
b/src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java
index
e311a5e
..
02ca290
100644
(file)
--- a/
src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java
+++ b/
src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java
@@
-173,6
+173,16
@@
public class MemoryDatabase extends AbstractService implements Database {
}
@Override
}
@Override
+ public Function<String, Optional<Sone>> getSone() {
+ return new Function<String, Optional<Sone>>() {
+ @Override
+ public Optional<Sone> apply(String soneId) {
+ return (soneId == null) ? Optional.<Sone>absent() : getSone(soneId);
+ }
+ };
+ }
+
+ @Override
public Optional<Sone> getSone(String soneId) {
lock.readLock().lock();
try {
public Optional<Sone> getSone(String soneId) {
lock.readLock().lock();
try {