vcs: Refactored "ValueConsumer", "GenericDetailsLoader"
authorKonstantin Kolosovsky <konstantin.kolosovsky@jetbrains.com>
Thu, 3 Nov 2016 14:36:51 +0000 (17:36 +0300)
committerKonstantin Kolosovsky <konstantin.kolosovsky@jetbrains.com>
Wed, 16 Nov 2016 18:01:56 +0000 (21:01 +0300)
platform/vcs-api/src/com/intellij/openapi/vcs/GenericDetailsLoader.java
platform/vcs-api/src/com/intellij/openapi/vcs/ValueConsumer.java
platform/vcs-impl/src/com/intellij/openapi/vcs/changes/AbstractRefreshablePanel.java

index 611b8fa67218e26d1e0538c47274fbbc5ba18425..460358ef31f3372cf517a3c3fb029dbde46f2a38 100644 (file)
  */
 package com.intellij.openapi.vcs;
 
-import com.intellij.openapi.Disposable;
-import com.intellij.openapi.application.ApplicationManager;
 import com.intellij.openapi.util.Comparing;
 import com.intellij.util.Consumer;
 import com.intellij.util.PairConsumer;
-import org.jetbrains.annotations.CalledInAny;
 import org.jetbrains.annotations.CalledInAwt;
 import org.jetbrains.annotations.Nullable;
 
-import java.util.concurrent.atomic.AtomicReference;
-
-/**
- * @author irengrig
- *         Date: 6/29/11
- *         Time: 11:38 PM
- */
-public class GenericDetailsLoader<Id, Data> implements Details<Id,Data>, Disposable {
+public class GenericDetailsLoader<Id, Data> implements Details<Id, Data> {
   private final Consumer<Id> myLoader;
   private final ValueConsumer<Id, Data> myValueConsumer;
-  private final AtomicReference<Id> myCurrentlySelected;
-  private boolean myIsDisposed;
+  private Id myCurrentlySelected;
 
   /**
    * @param loader - is called in AWT. Should call {@link #take} with data when ready. Also in AWT
    * @param valueConsumer - is called in AWT. passive, just benefits from details loading
    */
-  public GenericDetailsLoader(final Consumer<Id> loader, final PairConsumer<Id, Data> valueConsumer) {
+  public GenericDetailsLoader(Consumer<Id> loader, PairConsumer<Id, Data> valueConsumer) {
     myLoader = loader;
     myValueConsumer = new ValueConsumer<>(valueConsumer);
-    myCurrentlySelected = new AtomicReference<>(null);
   }
 
   @CalledInAwt
-  public void updateSelection(@Nullable final Id id, boolean force) {
-    ApplicationManager.getApplication().assertIsDispatchThread();
-    if (myIsDisposed) return;
+  public void updateSelection(@Nullable Id id, boolean force) {
     myValueConsumer.setId(id);
 
-    final Id wasId = myCurrentlySelected.getAndSet(id);
-    if (force || ! Comparing.equal(id, wasId)) {
+    Id previousId = myCurrentlySelected;
+    myCurrentlySelected = id;
+    if (force || !Comparing.equal(id, previousId)) {
       myLoader.consume(id);
     }
   }
 
-  public void setCacheConsumer(final PairConsumer<Id, Data>  cacheConsumer) {
-    myValueConsumer.setCacheConsumer(cacheConsumer);
-  }
-
   @CalledInAwt
   @Override
-  public void take(Id id, Data data) throws AlreadyDisposedException {
-    ApplicationManager.getApplication().assertIsDispatchThread();
-    if (myIsDisposed) throw new AlreadyDisposedException();
+  public void take(Id id, Data data) {
     myValueConsumer.consume(id, data);
   }
 
-  public void resetValueConsumer() {
-    myValueConsumer.reset();
-  }
-
-  @CalledInAny
+  @CalledInAwt
   @Override
   public Id getCurrentlySelected() {
-    return myCurrentlySelected.get();
-  }
-
-  @Override
-  public void dispose() {
-    myIsDisposed = true;
+    return myCurrentlySelected;
   }
 }
index 83c9c9b67ad7fa8236298539f81e50df65d5f64a..9c53d5cc8633edd22c2a23ba79d7abe8a3a8b79c 100644 (file)
@@ -17,42 +17,24 @@ package com.intellij.openapi.vcs;
 
 import com.intellij.util.PairConsumer;
 
-/**
- * @author irengrig
- *         Date: 6/29/11
- *         Time: 11:51 PM
- */
 public class ValueConsumer<Id, Data> {
   private Id myId;
   private Id mySetId;
   private final PairConsumer<Id, Data> myConsumer;
-  private PairConsumer<Id, Data> myCacheConsumer;
 
   protected ValueConsumer(PairConsumer<Id, Data> consumer) {
     myConsumer = consumer;
   }
 
-  public void setCacheConsumer(PairConsumer<Id, Data> cacheConsumer) {
-    myCacheConsumer = cacheConsumer;
-  }
-
-  public void consume(final Id id, final Data data) {
-    if (id.equals(mySetId) || ! id.equals(myId)) {
-      if (myCacheConsumer != null) {
-        myCacheConsumer.consume(id, data);
-      }
-      return;
+  public void consume(Id id, Data data) {
+    if (!id.equals(mySetId) && id.equals(myId)) {
+      mySetId = id;
+      myConsumer.consume(id, data);
     }
-    mySetId = id;
-    myConsumer.consume(id, data);
   }
 
   public void setId(Id id) {
     myId = id;
     mySetId = null;
   }
-
-  public void reset() {
-    mySetId = null;
-  }
 }
index 615b07b1c9069f15b446e7053f40a6975d3f8220..1b9e4f7059d6856f2e3c0fa2641838631faeecfb 100644 (file)
@@ -22,7 +22,6 @@ import com.intellij.openapi.progress.ProgressIndicator;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.ui.MessageType;
 import com.intellij.openapi.util.Comparing;
-import com.intellij.openapi.vcs.Details;
 import com.intellij.openapi.vcs.GenericDetailsLoader;
 import com.intellij.openapi.vcs.VcsException;
 import com.intellij.openapi.vcs.ui.VcsBalloonProblemNotifier;
@@ -146,12 +145,7 @@ public abstract class AbstractRefreshablePanel<T> implements RefreshablePanel<Ch
     @Override
     protected void doInAwtIfSuccess() {
       if (myDisposed) return;
-      try {
-        myDetailsLoader.take(myTicketCopy, myT);
-      }
-      catch (Details.AlreadyDisposedException e) {
-        // t is not disposable
-      }
+      myDetailsLoader.take(myTicketCopy, myT);
     }
 
     @Override