summaryrefslogtreecommitdiff
path: root/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/MapIgnoredFilesHolder.java
blob: 5ba7ce8cab0eb1ecf32db34b46fa4ddbded240d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
 * 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.changes;

import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vcs.AbstractVcs;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.containers.ContainerUtil;
import gnu.trove.THashSet;

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

/**
 * @author irengrig
 *         Date: 2/10/11
 *         Time: 4:20 PM
 */
public class MapIgnoredFilesHolder extends AbstractIgnoredFilesHolder {
  private final static Logger LOG = Logger.getInstance("#com.intellij.openapi.vcs.changes.MapIgnoredFilesHolder");

  private final Set<VirtualFile> mySet;
  private final Set<VirtualFile> myVcsIgnoredSet;
  private final Project myProject;

  public MapIgnoredFilesHolder(Project project) {
    super(project);
    myProject = project;
    mySet = new THashSet<VirtualFile>();
    myVcsIgnoredSet = new THashSet<VirtualFile>();    //collect ignored files from VcsChangeProvider -> processIgnored
  }

  @Override
  protected void removeFile(VirtualFile file) {
    mySet.remove(file);
    myVcsIgnoredSet.remove(file);
  }

  @Override
  protected Collection<VirtualFile> keys() {
    // if mySet has a big size ->  idea will process all of this on every typing. see cleanAndAdjustScope() in AbstractIgnoredFilesHolder
    return mySet;
  }

  @Override
  public void addFile(VirtualFile file) {
    // todo fix more. take from x0x branch
    //LOG.assertTrue(! file.isDirectory());
    mySet.add(file);
  }

  public void addByVcsChangeProvider(VirtualFile file) {
    myVcsIgnoredSet.add(file);
  }

  @Override
  public boolean containsFile(VirtualFile file) {
    return mySet.contains(file) || myVcsIgnoredSet.contains(file);
  }

  @Override
  public Collection<VirtualFile> values() {
    return ContainerUtil.union(mySet, myVcsIgnoredSet);
  }

  @Override
  public void cleanAll() {
    mySet.clear();
    myVcsIgnoredSet.clear();// not sure we need to delete
  }

  @Override
  public FileHolder copy() {
    final MapIgnoredFilesHolder result = new MapIgnoredFilesHolder(myProject);
    result.mySet.addAll(mySet);
    result.myVcsIgnoredSet.addAll(myVcsIgnoredSet);
    return result;
  }

  @Override
  public HolderType getType() {
    return HolderType.IGNORED;
  }

  @Override
  public void notifyVcsStarted(AbstractVcs scope) {
  }
}