update copyright
[fedora-idea.git] / plugins / svn4idea / src / org / jetbrains / idea / svn / SvnMapping.java
blobb39a782962d689a9c1160166db4345528bc9c889
1 /*
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 org.jetbrains.idea.svn;
18 import com.intellij.openapi.vfs.VirtualFile;
20 import java.io.File;
21 import java.util.*;
23 public class SvnMapping {
24 private final List<VirtualFile> myLonelyRoots;
25 private final Map<String, RootUrlInfo> myFile2UrlMap;
26 private final Map<String, RootUrlInfo> myUrl2FileMap;
27 //private final List<VirtualFile> myPhysicalCopies;
28 private boolean myRootsDifferFromSettings;
29 // no additional info. for caching only (convert roots)
30 private List<VirtualFile> myPreCalculatedUnderVcsRoots;
32 public SvnMapping() {
33 myFile2UrlMap = new HashMap<String, RootUrlInfo>();
34 myUrl2FileMap = new HashMap<String, RootUrlInfo>();
35 myLonelyRoots = new ArrayList<VirtualFile>();
36 //myPhysicalCopies = new ArrayList<VirtualFile>();
38 myPreCalculatedUnderVcsRoots = null;
40 myRootsDifferFromSettings = false;
43 public void copyFrom(final SvnMapping other) {
44 myFile2UrlMap.clear();
45 myUrl2FileMap.clear();
46 myLonelyRoots.clear();
47 //myPhysicalCopies.clear();
49 myFile2UrlMap.putAll(other.myFile2UrlMap);
50 myUrl2FileMap.putAll(other.myUrl2FileMap);
51 myLonelyRoots.addAll(other.myLonelyRoots);
52 //myPhysicalCopies.addAll(other.myPhysicalCopies);
53 myRootsDifferFromSettings = other.myRootsDifferFromSettings;
54 myPreCalculatedUnderVcsRoots = null;
57 public void addAll(final Collection<RootUrlInfo> roots) {
58 for (RootUrlInfo rootInfo : roots) {
59 final VirtualFile file = rootInfo.getVirtualFile();
60 final File ioFile = new File(file.getPath());
62 myRootsDifferFromSettings |= ! rootInfo.getRoot().getPath().equals(file.getPath());
64 myFile2UrlMap.put(ioFile.getAbsolutePath(), rootInfo);
65 myUrl2FileMap.put(rootInfo.getAbsoluteUrl(), rootInfo);
69 public void add(final RootUrlInfo rootInfo) {
70 final VirtualFile file = rootInfo.getVirtualFile();
71 final File ioFile = new File(file.getPath());
73 myRootsDifferFromSettings |= ! rootInfo.getRoot().getPath().equals(file.getPath());
75 myFile2UrlMap.put(ioFile.getAbsolutePath(), rootInfo);
76 myUrl2FileMap.put(rootInfo.getAbsoluteUrl(), rootInfo);
80 // todo check called. dont forget
81 public void setPhysicalCopies(final List<VirtualFile> roots) {
82 myPhysicalCopies.clear();
83 myPhysicalCopies.addAll(roots);
84 }*/
86 public List<VirtualFile> getUnderVcsRoots() {
87 if (myPreCalculatedUnderVcsRoots == null) {
88 myPreCalculatedUnderVcsRoots = new ArrayList<VirtualFile>();
89 for (RootUrlInfo info : myFile2UrlMap.values()) {
90 myPreCalculatedUnderVcsRoots.add(info.getVirtualFile());
93 return myPreCalculatedUnderVcsRoots;
96 public List<RootUrlInfo> getAllCopies() {
97 return new ArrayList<RootUrlInfo>(myFile2UrlMap.values());
100 public Collection<String> getFileRoots() {
101 return myFile2UrlMap.keySet();
104 public Collection<String> getUrls() {
105 return myUrl2FileMap.keySet();
108 public RootUrlInfo byFile(final String path) {
109 return myFile2UrlMap.get(path);
112 public RootUrlInfo byUrl(final String url) {
113 return myUrl2FileMap.get(url);
116 public boolean isEmpty() {
117 return myUrl2FileMap.isEmpty();
120 /*public List<VirtualFile> getPhysicalCopies() {
121 return myPhysicalCopies;
124 public boolean isRootsDifferFromSettings() {
125 return myRootsDifferFromSettings;
128 public void reportLonelyRoots(final Collection<VirtualFile> roots) {
129 myLonelyRoots.addAll(roots);
132 public List<VirtualFile> getLonelyRoots() {
133 return myLonelyRoots;