Revert "Return an optional from the Sone parser."
[Sone.git] / src / main / java / net / pterodactylus / sone / core / SoneDownloader.java
index bea7702..eb263ed 100644 (file)
@@ -36,8 +36,6 @@ import freenet.client.FetchResult;
 import freenet.keys.FreenetURI;
 import freenet.support.api.Bucket;
 
-import com.google.common.base.Optional;
-
 /**
  * The Sone downloader is responsible for download Sones as they are updated.
  *
@@ -140,7 +138,7 @@ public class SoneDownloader extends AbstractService {
         * @return The downloaded Sone, or {@code null} if the Sone could not be
         *         downloaded
         */
-       public Optional<Sone> fetchSone(Sone sone, FreenetURI soneUri, boolean fetchOnly) {
+       public Sone fetchSone(Sone sone, FreenetURI soneUri, boolean fetchOnly) {
                logger.log(Level.FINE, String.format("Starting fetch for Sone “%s” from %s…", sone, soneUri));
                FreenetURI requestUri = soneUri.setMetaString(new String[] { "sone.xml" });
                sone.setStatus(SoneStatus.downloading);
@@ -151,12 +149,12 @@ public class SoneDownloader extends AbstractService {
                                return null;
                        }
                        logger.log(Level.FINEST, String.format("Got %d bytes back.", fetchResults.getFetchResult().size()));
-                       Optional<Sone> parsedSone = parseSone(sone, fetchResults.getFetchResult(), fetchResults.getFreenetUri());
-                       if (parsedSone.isPresent()) {
+                       Sone parsedSone = parseSone(sone, fetchResults.getFetchResult(), fetchResults.getFreenetUri());
+                       if (parsedSone != null) {
                                if (!fetchOnly) {
-                                       parsedSone.get().setStatus((parsedSone.get().getTime() == 0) ? SoneStatus.unknown : SoneStatus.idle);
-                                       core.updateSone(parsedSone.get());
-                                       addSone(parsedSone.get());
+                                       parsedSone.setStatus((parsedSone.getTime() == 0) ? SoneStatus.unknown : SoneStatus.idle);
+                                       core.updateSone(parsedSone);
+                                       addSone(parsedSone);
                                }
                        }
                        return parsedSone;
@@ -176,15 +174,15 @@ public class SoneDownloader extends AbstractService {
         *            The requested URI
         * @return The parsed Sone, or {@code null} if the Sone could not be parsed
         */
-       public Optional<Sone> parseSone(Sone originalSone, FetchResult fetchResult, FreenetURI requestUri) {
+       public Sone parseSone(Sone originalSone, FetchResult fetchResult, FreenetURI requestUri) {
                logger.log(Level.FINEST, String.format("Parsing FetchResult (%d bytes, %s) for %s…", fetchResult.size(), fetchResult.getMimeType(), originalSone));
                Bucket soneBucket = fetchResult.asBucket();
                InputStream soneInputStream = null;
                try {
                        soneInputStream = soneBucket.getInputStream();
-                       Optional<Sone> parsedSone = parseSone(originalSone, soneInputStream);
-                       if (parsedSone.isPresent()) {
-                               parsedSone.get().modify().setLatestEdition(requestUri.getEdition()).update();
+                       Sone parsedSone = parseSone(originalSone, soneInputStream);
+                       if (parsedSone != null) {
+                               parsedSone.modify().setLatestEdition(requestUri.getEdition()).update();
                        }
                        return parsedSone;
                } catch (Exception e1) {
@@ -206,7 +204,7 @@ public class SoneDownloader extends AbstractService {
         *            The input stream to parse the Sone from
         * @return The parsed Sone
         */
-       public Optional<Sone> parseSone(Sone originalSone, InputStream soneInputStream) {
+       public Sone parseSone(Sone originalSone, InputStream soneInputStream) {
                return new SoneParser().parseSone(core.getDatabase(), originalSone, soneInputStream);
        }