X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fcore%2FCore.java;h=0680d30e5bc1008a776b76fa349c1251182aa458;hb=535ff37f006c1dd058590667e3b895ebc66af04a;hp=71dd3497a355d2454a59774413abd8dc83b7be89;hpb=da82d77fe096ef89404a8323adced3b75fefaa87;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index 71dd349..0680d30 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -55,6 +55,7 @@ import net.pterodactylus.sone.core.event.SoneRemovedEvent; import net.pterodactylus.sone.core.event.SoneUnlockedEvent; import net.pterodactylus.sone.data.Album; import net.pterodactylus.sone.data.Image; +import net.pterodactylus.sone.data.LocalSone; import net.pterodactylus.sone.data.Post; import net.pterodactylus.sone.data.PostReply; import net.pterodactylus.sone.data.Reply; @@ -147,15 +148,15 @@ public class Core extends AbstractService implements SoneProvider, PostProvider, /** Locked local Sones. */ /* synchronize on itself. */ - private final Set lockedSones = new HashSet(); + private final Set lockedSones = new HashSet(); /** Sone inserters. */ /* synchronize access on this on sones. */ - private final Map soneInserters = new HashMap(); + private final Map soneInserters = new HashMap(); /** Sone rescuers. */ /* synchronize access on this on sones. */ - private final Map soneRescuers = new HashMap(); + private final Map soneRescuers = new HashMap(); /** All known Sones. */ private final Set knownSones = new HashSet(); @@ -268,9 +269,8 @@ public class Core extends AbstractService implements SoneProvider, PostProvider, * The local Sone to get the rescuer for * @return The Sone rescuer for the given Sone */ - public SoneRescuer getSoneRescuer(Sone sone) { + public SoneRescuer getSoneRescuer(LocalSone sone) { checkNotNull(sone, "sone must not be null"); - checkArgument(sone.isLocal(), "sone must be local"); synchronized (soneRescuers) { SoneRescuer soneRescuer = soneRescuers.get(sone); if (soneRescuer == null) { @@ -289,7 +289,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider, * The sone to check * @return {@code true} if the Sone is locked, {@code false} if it is not */ - public boolean isLocked(Sone sone) { + public boolean isLocked(LocalSone sone) { synchronized (lockedSones) { return lockedSones.contains(sone); } @@ -326,27 +326,13 @@ public class Core extends AbstractService implements SoneProvider, PostProvider, return database.getSone(id); } - /** - * {@inheritDocs} - */ @Override - public Collection getLocalSones() { + public Collection getLocalSones() { return database.getLocalSones(); } - /** - * Returns the local Sone with the given ID, optionally creating a new Sone. - * - * @param id - * The ID of the Sone - * @return The Sone with the given ID, or {@code null} - */ - public Sone getLocalSone(String id) { - Optional sone = database.getSone(id); - if (sone.isPresent() && sone.get().isLocal()) { - return sone.get(); - } - return null; + public Optional getLocalSone(String id) { + return database.getLocalSone(id); } /** @@ -377,7 +363,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider, * @return {@code true} if a modification has been detected in the Sone, * {@code false} otherwise */ - public boolean isModifiedSone(Sone sone) { + public boolean isModifiedSone(LocalSone sone) { return soneInserters.containsKey(sone) && soneInserters.get(sone).isModified(); } @@ -586,13 +572,13 @@ public class Core extends AbstractService implements SoneProvider, PostProvider, /** * Locks the given Sone. A locked Sone will not be inserted by - * {@link SoneInserter} until it is {@link #unlockSone(Sone) unlocked} + * {@link SoneInserter} until it is {@link #unlockSone(LocalSone) unlocked} * again. * * @param sone * The sone to lock */ - public void lockSone(Sone sone) { + public void lockSone(LocalSone sone) { synchronized (lockedSones) { if (lockedSones.add(sone)) { eventBus.post(new SoneLockedEvent(sone)); @@ -603,11 +589,11 @@ public class Core extends AbstractService implements SoneProvider, PostProvider, /** * Unlocks the given Sone. * - * @see #lockSone(Sone) + * @see #lockSone(LocalSone) * @param sone * The sone to unlock */ - public void unlockSone(Sone sone) { + public void unlockSone(LocalSone sone) { synchronized (lockedSones) { if (lockedSones.remove(sone)) { eventBus.post(new SoneUnlockedEvent(sone)); @@ -628,7 +614,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider, return null; } logger.info(String.format("Adding Sone from OwnIdentity: %s", ownIdentity)); - Sone sone = database.registerLocalSone(ownIdentity); + LocalSone sone = database.registerLocalSone(ownIdentity); SoneInserter soneInserter = new SoneInserter(this, eventBus, freenetInterface, ownIdentity.getId()); eventBus.register(soneInserter); synchronized (soneInserters) { @@ -1264,7 +1250,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider, public void serviceStop() { localElementTicker.shutdownNow(); synchronized (soneInserters) { - for (Entry soneInserter : soneInserters.entrySet()) { + for (Entry soneInserter : soneInserters.entrySet()) { soneInserter.getValue().stop(); } }