All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.intellij.openapi.vcs.ValueConsumer Maven / Gradle / Ivy

/*
 * Copyright 2000-2011 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.intellij.openapi.vcs;

import com.intellij.util.PairConsumer;

/**
 * @author irengrig
 *         Date: 6/29/11
 *         Time: 11:51 PM
 */
public class ValueConsumer {
  private Id myId;
  private Id mySetId;
  private final PairConsumer myConsumer;
  private PairConsumer myCacheConsumer;

  protected ValueConsumer(PairConsumer consumer) {
    myConsumer = consumer;
  }

  public void setCacheConsumer(PairConsumer 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;
    }
    mySetId = id;
    myConsumer.consume(id, data);
  }

  public void setId(Id id) {
    myId = id;
    mySetId = null;
  }

  public void reset() {
    mySetId = null;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy