2 * Copyright 2000-2009 JetBrains s.r.o.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package com
.intellij
.openapi
.vcs
.changes
;
18 import com
.intellij
.openapi
.project
.Project
;
19 import org
.jetbrains
.annotations
.NotNull
;
21 import java
.util
.HashMap
;
24 public class FileHolderComposite
implements FileHolder
{
25 private final Map
<HolderType
, FileHolder
> myHolders
;
27 public FileHolderComposite(final Project project
) {
28 myHolders
= new HashMap
<HolderType
, FileHolder
>();
29 myHolders
.put(FileHolder
.HolderType
.UNVERSIONED
, new VirtualFileHolder(project
, FileHolder
.HolderType
.UNVERSIONED
));
30 myHolders
.put(FileHolder
.HolderType
.ROOT_SWITCH
, new SwitchedFileHolder(project
, HolderType
.ROOT_SWITCH
));
31 myHolders
.put(FileHolder
.HolderType
.MODIFIED_WITHOUT_EDITING
, new VirtualFileHolder(project
, FileHolder
.HolderType
.MODIFIED_WITHOUT_EDITING
));
32 myHolders
.put(FileHolder
.HolderType
.IGNORED
, new RecursiveFileHolder(project
, FileHolder
.HolderType
.IGNORED
));
33 myHolders
.put(FileHolder
.HolderType
.LOCKED
, new VirtualFileHolder(project
, FileHolder
.HolderType
.LOCKED
));
34 myHolders
.put(FileHolder
.HolderType
.LOGICALLY_LOCKED
, new LogicallyLockedHolder(project
));
37 public FileHolderComposite(final FileHolderComposite holder
) {
38 myHolders
= new HashMap
<HolderType
, FileHolder
>();
39 for (FileHolder fileHolder
: holder
.myHolders
.values()) {
40 myHolders
.put(fileHolder
.getType(), fileHolder
.copy());
44 public FileHolder
add(@NotNull final FileHolder fileHolder
, final boolean copy
) {
45 final FileHolder added
= copy ? fileHolder
.copy() : fileHolder
;
46 myHolders
.put(fileHolder
.getType(), added
);
50 public void cleanAll() {
51 for (FileHolder holder
: myHolders
.values()) {
56 public void cleanScope(final VcsDirtyScope scope
) {
57 for (FileHolder holder
: myHolders
.values()) {
58 holder
.cleanScope(scope
);
62 public FileHolder
copy() {
63 return new FileHolderComposite(this);
66 public FileHolder
get(final HolderType type
) {
67 return myHolders
.get(type
);
70 public VirtualFileHolder
getVFHolder(final HolderType type
) {
71 return (VirtualFileHolder
) myHolders
.get(type
);
75 public boolean equals(final Object o
) {
76 if (this == o
) return true;
77 if (o
== null || getClass() != o
.getClass()) return false;
79 final FileHolderComposite another
= (FileHolderComposite
) o
;
80 if (another
.myHolders
.size() != myHolders
.size()) {
84 for (Map
.Entry
<HolderType
, FileHolder
> entry
: myHolders
.entrySet()) {
85 if (! entry
.getValue().equals(another
.myHolders
.get(entry
.getKey()))) {
94 public int hashCode() {
95 return myHolders
!= null ? myHolders
.hashCode() : 0;
98 public HolderType
getType() {
99 throw new UnsupportedOperationException();
102 public RecursiveFileHolder
getIgnoredFileHolder() {
103 return (RecursiveFileHolder
) myHolders
.get(HolderType
.IGNORED
);