c545d40b81a13f967f70b71decd87a69bc40e742
[idea/community.git] / platform / vcs-impl / src / com / intellij / openapi / vcs / changes / DeletedFilesHolder.java
1 /*
2  * Copyright 2000-2009 JetBrains s.r.o.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.intellij.openapi.vcs.changes;
17
18 import com.intellij.openapi.application.ApplicationManager;
19 import com.intellij.openapi.vcs.FilePath;
20
21 import java.util.*;
22
23 /**
24  * @author max
25  */
26 public class DeletedFilesHolder implements FileHolder {
27   private final Map<String, LocallyDeletedChange> myFiles = new HashMap<String, LocallyDeletedChange>();
28
29   public void cleanAll() {
30     myFiles.clear();
31   }
32   
33   public void takeFrom(final DeletedFilesHolder holder) {
34     myFiles.clear();
35     myFiles.putAll(holder.myFiles);
36   }
37
38   public void cleanScope(final VcsDirtyScope scope) {
39     ApplicationManager.getApplication().runReadAction(new Runnable() {
40       public void run() {
41         if (scope == null) {
42           myFiles.clear();
43         }
44         final List<LocallyDeletedChange> currentFiles = new ArrayList<LocallyDeletedChange>(myFiles.values());
45         for (LocallyDeletedChange change : currentFiles) {
46           if (scope.belongsTo(change.getPath())) {
47             myFiles.remove(change.getPresentableUrl());
48           }
49         }
50       }
51     });
52   }
53
54   public HolderType getType() {
55     return HolderType.DELETED;
56   }
57
58   public void addFile(final LocallyDeletedChange change) {
59     myFiles.put(change.getPresentableUrl(), change);
60   }
61
62   public List<LocallyDeletedChange> getFiles() {
63     return new ArrayList<LocallyDeletedChange>(myFiles.values());
64   }
65
66   public boolean isContainedInLocallyDeleted(final FilePath filePath) {
67     final String url = filePath.getPresentableUrl();
68     return myFiles.containsKey(url);
69   }
70
71   public DeletedFilesHolder copy() {
72     final DeletedFilesHolder copyHolder = new DeletedFilesHolder();
73     copyHolder.myFiles.putAll(myFiles);
74     return copyHolder;
75   }
76
77   public boolean equals(final Object o) {
78     if (this == o) return true;
79     if (o == null || getClass() != o.getClass()) return false;
80
81     final DeletedFilesHolder that = (DeletedFilesHolder)o;
82
83     if (!myFiles.equals(that.myFiles)) return false;
84
85     return true;
86   }
87
88   public int hashCode() {
89     return myFiles.hashCode();
90   }
91 }