1 // Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
2 package org.jetbrains.idea.maven.indices;
4 import com.intellij.openapi.util.io.FileUtilRt;
5 import org.jetbrains.annotations.NotNull;
6 import org.jetbrains.annotations.Nullable;
8 import java.util.ArrayList;
10 import java.util.Objects;
13 public class MavenIndexHolder {
14 private final @Nullable MavenIndex myLocalIndex;
15 private final @NotNull List<MavenIndex> myRemoteIndices;
16 private final @NotNull List<MavenIndex> myIndices;
18 MavenIndexHolder(@NotNull List<MavenIndex> remoteIndices, @Nullable MavenIndex localIndex) {
19 myLocalIndex = localIndex;
20 myRemoteIndices = List.copyOf(Objects.requireNonNull(remoteIndices));
22 List<MavenIndex> indices = new ArrayList<>(remoteIndices);
23 if (myLocalIndex != null) indices.add(myLocalIndex);
24 myIndices = List.copyOf(indices);
27 public @Nullable MavenIndex getLocalIndex() {
31 public @NotNull List<MavenIndex> getRemoteIndices() {
32 return myRemoteIndices;
35 public @NotNull List<MavenIndex> getIndices() {
39 public boolean isEquals(@NotNull Set<String> remoteUrls, @Nullable String localPath) {
40 if (!FileUtilRt.pathsEqual(myLocalIndex != null ? myLocalIndex.getRepositoryPathOrUrl() : null, localPath)) return false;
41 if (remoteUrls.size() != myRemoteIndices.size()) return false;
42 for (MavenSearchIndex index : myRemoteIndices) {
43 if (!remoteUrls.contains(index.getRepositoryPathOrUrl())) return false;
49 public String toString() {
50 return "MavenIndexHolder{" + myIndices + '}';