Return an optional Sone from the current session.
[Sone.git] / src / main / java / net / pterodactylus / sone / web / WebInterface.java
index 02a5dd5..258669a 100644 (file)
@@ -381,7 +381,7 @@ public class WebInterface {
         * @return The currently logged in Sone, or {@code null} if no Sone is
         *         currently logged in
         */
-       public Sone getCurrentSone(ToadletContext toadletContext) {
+       public Optional<Sone> getCurrentSone(ToadletContext toadletContext) {
                return getCurrentSone(toadletContext, true);
        }
 
@@ -396,10 +396,10 @@ public class WebInterface {
         * @return The currently logged in Sone, or {@code null} if no Sone is
         *         currently logged in
         */
-       public Sone getCurrentSone(ToadletContext toadletContext, boolean createSession) {
+       public Optional<Sone> getCurrentSone(ToadletContext toadletContext, boolean createSession) {
                Collection<Sone> localSones = getCore().getLocalSones();
                if (localSones.size() == 1) {
-                       return localSones.iterator().next();
+                       return Optional.of(localSones.iterator().next());
                }
                return getCurrentSone(getCurrentSession(toadletContext, createSession));
        }
@@ -412,15 +412,15 @@ public class WebInterface {
         * @return The currently logged in Sone, or {@code null} if no Sone is
         *         currently logged in
         */
-       public Sone getCurrentSone(Optional<Session> session) {
+       public Optional<Sone> getCurrentSone(Optional<Session> session) {
                if (!session.isPresent()) {
-                       return null;
+                       return Optional.absent();
                }
                String soneId = (String) session.get().getAttribute("Sone.CurrentSone");
                if (soneId == null) {
-                       return null;
+                       return Optional.absent();
                }
-               return getCore().getLocalSone(soneId);
+               return Optional.fromNullable(getCore().getLocalSone(soneId));
        }
 
        /**