Remove unnecessary method.
[Sone.git] / src / main / java / net / pterodactylus / sone / core / WebOfTrustUpdater.java
index dd3de58..67bf3ac 100644 (file)
@@ -34,6 +34,7 @@ import net.pterodactylus.sone.freenet.wot.WebOfTrustException;
 import net.pterodactylus.util.logging.Logging;
 import net.pterodactylus.util.service.AbstractService;
 
+import com.google.common.annotations.VisibleForTesting;
 import com.google.inject.Inject;
 
 /**
@@ -101,18 +102,6 @@ public class WebOfTrustUpdater extends AbstractService {
        }
 
        /**
-        * Adds the given context to the given own identity.
-        *
-        * @param ownIdentity
-        *              The own identity to add the context to
-        * @param context
-        *              The context to add
-        */
-       public void addContext(OwnIdentity ownIdentity, String context) {
-               addContextWait(ownIdentity, context, false);
-       }
-
-       /**
         * Adds the given context to the given own identity, waiting for completion of
         * the operation.
         *
@@ -124,25 +113,6 @@ public class WebOfTrustUpdater extends AbstractService {
         *         otherwise
         */
        public boolean addContextWait(OwnIdentity ownIdentity, String context) {
-               return addContextWait(ownIdentity, context, true);
-       }
-
-       /**
-        * Adds the given context to the given own identity, waiting for completion of
-        * the operation.
-        *
-        * @param ownIdentity
-        *              The own identity to add the context to
-        * @param context
-        *              The context to add
-        * @param wait
-        *              {@code true} to wait for the end of the operation, {@code false} to return
-        *              immediately
-        * @return {@code true} if the context was added successfully, {@code false} if
-        *         the context was not added successfully, or if the job should not
-        *         wait for completion
-        */
-       private boolean addContextWait(OwnIdentity ownIdentity, String context, boolean wait) {
                AddContextJob addContextJob = new AddContextJob(ownIdentity, context);
                if (!updateJobs.contains(addContextJob)) {
                        logger.log(Level.FINER, "Adding Context Job: " + addContextJob);
@@ -151,10 +121,8 @@ public class WebOfTrustUpdater extends AbstractService {
                        } catch (InterruptedException ie1) {
                                /* the queue is unbounded so it should never block. */
                        }
-                       if (wait) {
-                               return addContextJob.waitForCompletion();
-                       }
-               } else if (wait) {
+                       return addContextJob.waitForCompletion();
+               } else {
                        for (WebOfTrustUpdateJob updateJob : updateJobs) {
                                if (updateJob.equals(addContextJob)) {
                                        return updateJob.waitForCompletion();
@@ -229,7 +197,7 @@ public class WebOfTrustUpdater extends AbstractService {
                while (!shouldStop()) {
                        try {
                                WebOfTrustUpdateJob updateJob = updateJobs.take();
-                               if (shouldStop() || (updateJob == stopJob)) {
+                               if (shouldStop()) {
                                        break;
                                }
                                logger.log(Level.FINE, "Running Trust Update Job: " + updateJob);
@@ -258,7 +226,8 @@ public class WebOfTrustUpdater extends AbstractService {
         *
         * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
         */
-       private class WebOfTrustUpdateJob {
+       @VisibleForTesting
+       class WebOfTrustUpdateJob implements Runnable {
 
                /** Object for synchronization. */
                @SuppressWarnings("hiding")
@@ -279,6 +248,7 @@ public class WebOfTrustUpdater extends AbstractService {
                 * <p/>
                 * The implementation of this class does nothing.
                 */
+               @Override
                public void run() {
                        /* does nothing. */
                }
@@ -329,7 +299,8 @@ public class WebOfTrustUpdater extends AbstractService {
         *
         * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
         */
-       private class SetTrustJob extends WebOfTrustUpdateJob {
+       @VisibleForTesting
+       class SetTrustJob extends WebOfTrustUpdateJob {
 
                /** The identity giving the trust. */
                private final OwnIdentity truster;
@@ -357,8 +328,8 @@ public class WebOfTrustUpdater extends AbstractService {
                 *              The comment of the trust relation
                 */
                public SetTrustJob(OwnIdentity truster, Identity trustee, Integer score, String comment) {
-                       this.truster = truster;
-                       this.trustee = trustee;
+                       this.truster = checkNotNull(truster, "truster must not be null");
+                       this.trustee = checkNotNull(trustee, "trustee must not be null");
                        this.score = score;
                        this.comment = comment;
                }
@@ -369,15 +340,11 @@ public class WebOfTrustUpdater extends AbstractService {
                public void run() {
                        try {
                                if (score != null) {
-                                       if (trustee instanceof DefaultIdentity) {
-                                               ((DefaultIdentity) trustee).setTrust(truster, new Trust(score, null, 0));
-                                       }
                                        webOfTrustConnector.setTrust(truster, trustee, score, comment);
+                                       trustee.setTrust(truster, new Trust(score, null, 0));
                                } else {
-                                       if (trustee instanceof DefaultIdentity) {
-                                               ((DefaultIdentity) trustee).setTrust(truster, null);
-                                       }
                                        webOfTrustConnector.removeTrust(truster, trustee);
+                                       trustee.removeTrust(truster);
                                }
                                finish(true);
                        } catch (WebOfTrustException wote1) {
@@ -397,19 +364,19 @@ public class WebOfTrustUpdater extends AbstractService {
                                return false;
                        }
                        SetTrustJob updateJob = (SetTrustJob) object;
-                       return ((truster == null) ? (updateJob.truster == null) : updateJob.truster.equals(truster)) && ((trustee == null) ? (updateJob.trustee == null) : updateJob.trustee.equals(trustee));
+                       return updateJob.truster.equals(truster) && updateJob.trustee.equals(trustee);
                }
 
                /** {@inheritDoc} */
                @Override
                public int hashCode() {
-                       return getClass().hashCode() ^ ((truster == null) ? 0 : truster.hashCode()) ^ ((trustee == null) ? 0 : trustee.hashCode());
+                       return getClass().hashCode() ^ truster.hashCode() ^ trustee.hashCode();
                }
 
                /** {@inheritDoc} */
                @Override
                public String toString() {
-                       return String.format("%s[truster=%s,trustee=%s]", getClass().getSimpleName(), (truster == null) ? null : truster.getId(), (trustee == null) ? null : trustee.getId());
+                       return String.format("%s[truster=%s,trustee=%s]", getClass().getSimpleName(), truster.getId(), trustee.getId());
                }
 
        }
@@ -419,7 +386,8 @@ public class WebOfTrustUpdater extends AbstractService {
         *
         * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
         */
-       private class WebOfTrustContextUpdateJob extends WebOfTrustUpdateJob {
+       @VisibleForTesting
+       class WebOfTrustContextUpdateJob extends WebOfTrustUpdateJob {
 
                /** The own identity whose contexts to manage. */
                protected final OwnIdentity ownIdentity;
@@ -474,7 +442,8 @@ public class WebOfTrustUpdater extends AbstractService {
         *
         * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
         */
-       private class AddContextJob extends WebOfTrustContextUpdateJob {
+       @VisibleForTesting
+       class AddContextJob extends WebOfTrustContextUpdateJob {
 
                /**
                 * Creates a new add-context job.
@@ -509,7 +478,8 @@ public class WebOfTrustUpdater extends AbstractService {
         *
         * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
         */
-       private class RemoveContextJob extends WebOfTrustContextUpdateJob {
+       @VisibleForTesting
+       class RemoveContextJob extends WebOfTrustContextUpdateJob {
 
                /**
                 * Creates a new remove-context job.
@@ -544,7 +514,8 @@ public class WebOfTrustUpdater extends AbstractService {
         *
         * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
         */
-       private class SetPropertyJob extends WebOfTrustUpdateJob {
+       @VisibleForTesting
+       class SetPropertyJob extends WebOfTrustUpdateJob {
 
                /** The own identity to update properties on. */
                private final OwnIdentity ownIdentity;