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

org.sonar.server.component.index.SuggestionQuery Maven / Gradle / Ivy

There is a newer version: 7.2.1
Show newest version
/*
 * SonarQube
 * Copyright (C) 2009-2018 SonarSource SA
 * mailto:info AT sonarsource DOT com
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */
package org.sonar.server.component.index;

import java.util.Collection;
import java.util.Collections;
import java.util.Set;

import static com.google.common.base.Preconditions.checkArgument;
import static java.util.Objects.requireNonNull;

public class SuggestionQuery {

  public static final int DEFAULT_LIMIT = 6;

  private final String query;
  private final Collection qualifiers;
  private final Set recentlyBrowsedKeys;
  private final Set favoriteKeys;
  private final int skip;
  private final int limit;

  private SuggestionQuery(Builder builder) {
    this.query = requireNonNull(builder.query);
    this.qualifiers = requireNonNull(builder.qualifiers);
    this.recentlyBrowsedKeys = requireNonNull(builder.recentlyBrowsedKeys);
    this.favoriteKeys = requireNonNull(builder.favoriteKeys);
    this.skip = builder.skip;
    this.limit = builder.limit;
  }

  public Collection getQualifiers() {
    return qualifiers;
  }

  public String getQuery() {
    return query;
  }

  public Set getRecentlyBrowsedKeys() {
    return recentlyBrowsedKeys;
  }

  public int getSkip() {
    return skip;
  }

  public int getLimit() {
    return limit;
  }

  public static Builder builder() {
    return new Builder();
  }

  public Set getFavoriteKeys() {
    return favoriteKeys;
  }

  public static class Builder {
    private String query;
    private Collection qualifiers = Collections.emptyList();
    private Set recentlyBrowsedKeys = Collections.emptySet();
    private Set favoriteKeys = Collections.emptySet();
    private int skip = 0;
    private int limit = DEFAULT_LIMIT;

    private Builder() {
    }

    public Builder setQuery(String query) {
      checkArgument(query.length() >= 2, "Query must be at least two characters long: %s", query);
      this.query = query;
      return this;
    }

    public Builder setQualifiers(Collection qualifiers) {
      this.qualifiers = Collections.unmodifiableCollection(qualifiers);
      return this;
    }

    public Builder setRecentlyBrowsedKeys(Set recentlyBrowsedKeys) {
      this.recentlyBrowsedKeys = Collections.unmodifiableSet(recentlyBrowsedKeys);
      return this;
    }

    public Builder setFavoriteKeys(Set favoriteKeys) {
      this.favoriteKeys = Collections.unmodifiableSet(favoriteKeys);
      return this;
    }

    public Builder setSkip(int skip) {
      checkArgument(limit > 0, "Skip has to be strictly positive: %s", limit);
      this.skip = skip;
      return this;
    }

    public Builder setLimit(int limit) {
      checkArgument(limit > 0, "Limit has to be strictly positive: %s", limit);
      this.limit = limit;
      return this;
    }

    public SuggestionQuery build() {
      return new SuggestionQuery(this);
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy