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

com.intellij.util.QueryFactory Maven / Gradle / Ivy

There is a newer version: 2.1.0-Beta1-1.0.25
Show newest version
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.util;

import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;

import java.util.List;

public class QueryFactory {
  private final List> myExecutors = ContainerUtil.createLockFreeCopyOnWriteList();

  public void registerExecutor(@NotNull QueryExecutor executor) {
    myExecutors.add(executor);
  }

  public void unregisterExecutor(@NotNull QueryExecutor executor) {
    myExecutors.remove(executor);
  }

  /**
   * @return query to perform the search. @param parameters of the search
   */
  @NotNull
  public final Query createQuery(@NotNull Parameters parameters) {
    return new ExecutorsQuery<>(parameters, getExecutors());
  }

  @NotNull
  protected List> getExecutors() {
    return myExecutors;
  }

  public boolean hasAnyExecutors() {
    return !getExecutors().isEmpty();
  }

  /**
   * @param parameters of the search
   * @return query to perform the search. Obtained results are automatically filtered wrt. equals() relation.
   */
  @NotNull
  public final Query createUniqueResultsQuery(@NotNull Parameters parameters) {
    return new UniqueResultsQuery(createQuery(parameters));
  }

  /**
   * @param parameters      of the search
   * @param mapper          function that maps results to their mapping counterparts.
   * @return query to perform the search. Obtained results are mapped to whatever objects that are automatically filtered wrt. equals()
   *         relation. Storing mapped objects instead of original elements may be wise wrt to memory consumption.
   */
  public final @NotNull  Query createUniqueResultsQuery(@NotNull Parameters parameters, @NotNull Function mapper) {
    return new UniqueResultsQuery<>(createQuery(parameters), mapper);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy