001: package tide.project;
002:
003: import java.util.*;
004: import snow.utils.storage.*;
005:
006: /** manages (load/save) the sources storage.
007: * Remark: sources means here the infos stored about sources, not the sources themselves.
008: * Remark: must be recreated after project settings changed.
009: */
010: public final class SourcesInfoStorageManager {
011: /** Stored data for files.
012: */
013: private final Map<String, StorageVector> vectorRepOfSources = new Hashtable<String, StorageVector>();
014:
015: // since created
016: private boolean changed = false;
017:
018: boolean getHasChanged() {
019: return changed;
020: }
021:
022: void setChangedFalse() {
023: changed = false;
024: }
025:
026: SourcesInfoStorageManager() {
027: }
028:
029: /** @return a copy...
030: */
031: Set<String> getSourcesForWhichRepExist() {
032: return new HashSet<String>(vectorRepOfSources.keySet());
033: }
034:
035: StorageVector getSourceFileRep(String javaName) {
036: return vectorRepOfSources.get(javaName);
037: }
038:
039: /** Called for files that are no more existing at project load...
040: */
041: void removeFileReps(Set<String> javaNames) {
042: for (String jn : javaNames) {
043: vectorRepOfSources.remove(jn);
044: }
045: changed = true;
046:
047: }
048:
049: void remove(String jn) {
050: vectorRepOfSources.remove(jn);
051: changed = true;
052: }
053:
054: /** Deeply clears the storage representations.
055: */
056: public void clearReps() {
057: for (StorageVector sv : vectorRepOfSources.values()) {
058: sv.terminate();
059: }
060: vectorRepOfSources.clear();
061: changed = true;
062: }
063:
064: /** also called for folders...
065: */
066: void setSourceFileRep(String javeName, StorageVector rep) {
067: vectorRepOfSources.put(javeName, rep);
068: changed = true;
069: }
070:
071: @SuppressWarnings("unchecked")
072: void createFromVectorRepresentation_old(StorageVector rep) {
073: if (rep.size() > 2) {
074: ArrayList<String> srepKeys = (ArrayList<String>) rep.get(2);
075: ArrayList<ArrayList<Object>> srepVals = (ArrayList<ArrayList<Object>>) rep
076: .get(3);
077:
078: for (int i = 0; i < srepKeys.size(); i++) {
079: StorageVector srep = new StorageVector();
080: srep.addAll(srepVals.get(i));
081: vectorRepOfSources.put(srepKeys.get(i), srep);
082: }
083: }
084: System.out.println("read " + vectorRepOfSources.size()
085: + " sources reps (old method)");
086: changed = true;
087: }
088:
089: @SuppressWarnings("unchecked")
090: void createFromVectorRepresentation(StorageVector rep,
091: boolean clearRep) {
092: int version = (Integer) rep.get(0);
093: List<String> srepKeys = (List<String>) rep.get(1);
094: List<ArrayList<Object>> srepVals = (List<ArrayList<Object>>) rep
095: .get(2);
096: for (int i = 0; i < srepKeys.size(); i++) {
097: StorageVector srep = new StorageVector();
098: srep.addAll(srepVals.get(i));
099: vectorRepOfSources.put(srepKeys.get(i), srep);
100: }
101: System.out.println("read " + vectorRepOfSources.size()
102: + " sources reps");
103: changed = true;
104:
105: if (clearRep) {
106: rep.clear();
107: }
108: }
109:
110: StorageVector getVectorRepresentation() {
111: StorageVector sv = new StorageVector();
112: sv.add(1); // 0: version
113: Vector<String> srepKeys = new Vector<String>();
114: sv.add(srepKeys); // 1
115: Vector<Object> srepVals = new Vector<Object>();
116: sv.add(srepVals); // 2
117:
118: for (String k : vectorRepOfSources.keySet()) {
119: srepKeys.add(k);
120: srepVals.add(vectorRepOfSources.get(k));
121: }
122: System.out.println("stored " + vectorRepOfSources.size()
123: + " sources reps");
124:
125: return sv;
126: }
127:
128: }
|