Changeset 70b8949
- Timestamp:
- Jul 12, 2010, 12:13:33 PM (8 years ago)
- Branches:
- master
- Children:
- 39730c4
- Parents:
- cf52b31
- Location:
- src/main/java/de/erichseifert/warp
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/de/erichseifert/warp/WARP.java
rcf52b31 r70b8949 152 152 /** 153 153 * Returns a parsed replay with the specified file path. 154 * @param id Idof the replay.154 * @param descriptor Descriptor of the replay. 155 155 * @return Parsed replay. 156 156 */ 157 public Replay getReplay( long id) {158 return storage. load(id).get(0);157 public Replay getReplay(ReplayDescriptor descriptor) { 158 return storage.getReplay(descriptor); 159 159 } 160 160 -
src/main/java/de/erichseifert/warp/gui/ReplayParserGUI.java
rcf52b31 r70b8949 353 353 // FIXME: Renderer should be retrieved by a factory 354 354 ReplayDescriptor replayDescriptor = (ReplayDescriptor) replayTable.getValueAt(selectedIndex, 0); 355 Replay replay = ReplayParserGUI.this.warp.getReplay(replayDescriptor .getId());355 Replay replay = ReplayParserGUI.this.warp.getReplay(replayDescriptor); 356 356 splitPane.setLeftComponent(replayRenderer.getRendererComponent((SC2Replay) replay)); 357 357 // FIXME: Find better solution -
src/main/java/de/erichseifert/warp/io/AbstractReplayStorage.java
rcf52b31 r70b8949 40 40 public void save(Replay... replays) { 41 41 for (Replay replay : replays) { 42 fireReplayDataChanged(null, replay.getDescriptor()); 42 ReplayDescriptor descriptor = replay.getDescriptor(); 43 fireReplayDataChanged(null, descriptor); 43 44 } 44 45 } 45 46 46 47 @Override 47 public void delete(Replay... replays) { 48 for (Replay replay : replays) { 49 fireReplayDataChanged(replay.getDescriptor(), null); 48 public void delete(long... ids) { 49 for (long id : ids) { 50 ReplayDescriptor descriptorOld = load(id).get(0); 51 fireReplayDataChanged(descriptorOld, null); 50 52 } 51 53 } -
src/main/java/de/erichseifert/warp/io/BufferedStorage.java
rcf52b31 r70b8949 23 23 24 24 import java.io.File; 25 import java.util.ArrayList;26 25 import java.util.LinkedHashMap; 27 26 import java.util.List; … … 97 96 98 97 @Override 99 public List<? extends Replay> load(long... ids) { 100 List<Replay> replays = new ArrayList<Replay>(ids.length); 101 for (long id : ids) { 102 Replay replay = replayBuffer.get(id); 103 if (replay == null) { 104 replay = storage.load(id).get(0); 105 } 106 replayBuffer.put(id, replay); 107 replays.add(replay); 108 } 109 return replays; 98 public List<ReplayDescriptor> load(long... ids) { 99 return storage.load(ids); 110 100 } 111 101 … … 124 114 125 115 @Override 126 public void delete( Replay... replays) {127 storage.delete( replays);116 public void delete(long... ids) { 117 storage.delete(ids); 128 118 } 129 119 … … 160 150 } 161 151 } 152 153 @Override 154 public Replay getReplay(ReplayDescriptor descriptor) { 155 long id = descriptor.getId(); 156 Replay replay = replayBuffer.get(id); 157 if (replay == null) { 158 replay = storage.getReplay(descriptor); 159 } 160 replayBuffer.put(id, replay); 161 return replay; 162 } 162 163 } -
src/main/java/de/erichseifert/warp/io/MemoryStorage.java
rcf52b31 r70b8949 23 23 24 24 import java.io.File; 25 import java.util.ArrayList;26 25 import java.util.HashMap; 27 26 import java.util.HashSet; 27 import java.util.LinkedList; 28 28 import java.util.List; 29 29 import java.util.Map; … … 60 60 61 61 @Override 62 public List<? extends Replay> load(long... ids) {63 List<Replay> replays = new ArrayList<Replay>(ids.length);64 for (long id : ids) {65 Replay replay = cache.get(id);66 replays.add(replay);67 }68 return replays;69 }70 71 @Override72 62 public void save(Replay... replays) { 73 63 for (Replay replay : replays) { … … 78 68 79 69 @Override 80 public void delete( Replay... replays) {81 for ( Replay replay : replays) {82 cache.remove( replay.getDescriptor().getId());70 public void delete(long... ids) { 71 for (long id : ids) { 72 cache.remove(id); 83 73 } 84 super.delete( replays);74 super.delete(ids); 85 75 } 86 76 … … 92 82 @Override 93 83 public boolean contains(File replayFile) { 94 return cache.containsValue(replayFile); 84 for (Map.Entry<Long, Replay> entry : cache.entrySet()) { 85 Replay replay = entry.getValue(); 86 if (replay.getDescriptor().getFile().getAbsolutePath().equals(replayFile.getAbsolutePath())) { 87 return true; 88 } 89 } 90 return false; 95 91 } 96 92 … … 112 108 return null; 113 109 } 110 111 @Override 112 public Replay getReplay(ReplayDescriptor descriptor) { 113 long id = descriptor.getId(); 114 Replay replay = cache.get(id); 115 return replay; 116 } 117 118 @Override 119 public List<ReplayDescriptor> load(long... ids) { 120 List<ReplayDescriptor> descriptors = new LinkedList<ReplayDescriptor>(); 121 for (long id : ids) { 122 Replay replay = cache.get(id); 123 descriptors.add(replay.getDescriptor()); 124 } 125 return descriptors; 126 } 114 127 } -
src/main/java/de/erichseifert/warp/io/ReplayStorage.java
rcf52b31 r70b8949 42 42 * Returns the parsed replays which belong to the specified file paths. 43 43 * @param ids IDs of the unparsed replay files. 44 * @return Parsed replays in the same order as the specified paths.44 * @return Descriptors of the parsed replays in the same order as the specified paths. 45 45 */ 46 List< ? extends Replay> load(long... ids);46 List<ReplayDescriptor> load(long... ids); 47 47 /** 48 48 * Stores the specified replays. … … 52 52 /** 53 53 * Removes the specified replays. 54 * @param replays Replays.54 * @param ids Replay ids. 55 55 */ 56 void delete(Replay... replays); 56 void delete(long... ids); 57 58 Replay getReplay(ReplayDescriptor descriptor); 57 59 58 60 /** … … 76 78 /** 77 79 * Returns, whether the specified replay has already been stored or not. 78 * @param replay File to the unparsed replay.80 * @param replayFile File to the unparsed replay. 79 81 * @return <code>true</code> if the replay already has been stored. 80 82 */ -
src/main/java/de/erichseifert/warp/io/SerializingStorage.java
rcf52b31 r70b8949 62 62 private Replay lastSavedReplay; 63 63 64 private Map< String, ReplayDescriptor> descriptorsByPath;64 private Map<Long, ReplayDescriptor> descriptorsById; 65 65 private Statistics statistics; 66 66 private ReplayIndexer indexer; … … 92 92 93 93 @Override 94 public List<? extends Replay> load(long... ids) { 95 List<Replay> replays = new LinkedList<Replay>(); 96 for (long id : ids) { 97 // Check, if the requested replay can be retrieved by the buffer 98 if (lastSavedReplay != null && lastSavedReplay.getDescriptor().getId() == id) { 99 replays.add(lastSavedReplay); 100 } 101 else { 102 String replayFilePath = getSerializationPath(storageDir, id); 103 Replay replay = (Replay) deserialize(replayFilePath); 104 replays.add(replay); 105 } 106 } 107 return replays; 94 public Replay getReplay(ReplayDescriptor descriptor) { 95 Replay replay = null; 96 // Check, if the requested replay can be retrieved by the buffer 97 if (lastSavedReplay != null && lastSavedReplay.getDescriptor().getId() == descriptor.getId()) { 98 replay = lastSavedReplay; 99 } 100 else { 101 String replayFilePath = getSerializationPath(storageDir, descriptor.getId()); 102 replay = (Replay) deserialize(replayFilePath); 103 } 104 return replay; 108 105 } 109 106 … … 153 150 */ 154 151 private void initDescriptorCache() { 155 if (descriptorsBy Path!= null) {152 if (descriptorsById != null) { 156 153 return; 157 154 } 158 155 159 156 if (descriptorFile.exists()) { 160 descriptorsBy Path = (Map<String, ReplayDescriptor>) deserialize(descriptorFile.getAbsolutePath());157 descriptorsById = (Map<Long, ReplayDescriptor>) deserialize(descriptorFile.getAbsolutePath()); 161 158 } 162 159 else { 163 descriptorsBy Path = new HashMap<String, ReplayDescriptor>();160 descriptorsById = new HashMap<Long, ReplayDescriptor>(); 164 161 } 165 162 } … … 214 211 String replayFilePath = getSerializationPath(storageDir, replay.getDescriptor()); 215 212 serialize(replay, replayFilePath); 216 descriptorsBy Path.put(replay.getDescriptor().getFile().getAbsolutePath(), replay.getDescriptor());213 descriptorsById.put(replay.getDescriptor().getId(), replay.getDescriptor()); 217 214 lastSavedReplay = replay; 218 215 } … … 221 218 222 219 // Serialize replay descriptors 223 serialize(descriptorsBy Path, descriptorFile.getAbsolutePath());220 serialize(descriptorsById, descriptorFile.getAbsolutePath()); 224 221 225 222 // Serialize statistics … … 233 230 public boolean contains(File replayFile) { 234 231 initDescriptorCache(); 235 if (descriptorsByPath.containsKey(replayFile.getAbsolutePath())) { 236 return true; 232 for (ReplayDescriptor descriptor : descriptorsById.values()) { 233 if (descriptor.getFile().getAbsolutePath().equals(replayFile.getAbsolutePath())) { 234 return true; 235 } 237 236 } 238 237 return false; … … 242 241 public Set<ReplayDescriptor> getDescriptors() { 243 242 initDescriptorCache(); 244 return new HashSet<ReplayDescriptor>(descriptorsBy Path.values());245 } 246 247 @Override 248 public void delete( Replay... replays) {243 return new HashSet<ReplayDescriptor>(descriptorsById.values()); 244 } 245 246 @Override 247 public void delete(long... ids) { 249 248 initDescriptorCache(); 250 249 initStatistics(); 251 250 initIndexer(); 252 251 253 for (Replay replay : replays) { 254 String serPath = getSerializationPath(storageDir, replay.getDescriptor()); 252 for (long id : ids) { 253 ReplayDescriptor descriptor = load(id).get(0); 254 String serPath = getSerializationPath(storageDir, descriptor); 255 255 File serializedFile = new File(serPath); 256 256 serializedFile.delete(); 257 257 258 descriptorsBy Path.remove(replay.getDescriptor().getFile());259 } 260 261 super.delete( replays);258 descriptorsById.remove(descriptor.getId()); 259 } 260 261 super.delete(ids); 262 262 263 263 // Serialize replay descriptors 264 serialize(descriptorsBy Path, descriptorFile.getAbsolutePath());264 serialize(descriptorsById, descriptorFile.getAbsolutePath()); 265 265 266 266 // Serialize statistics … … 274 274 public int size() { 275 275 initDescriptorCache(); 276 return descriptorsBy Path.size();276 return descriptorsById.size(); 277 277 } 278 278 … … 342 342 return indexer.getIndexNames(); 343 343 } 344 345 @Override 346 public List<ReplayDescriptor> load(long... ids) { 347 List<ReplayDescriptor> descriptors = new LinkedList<ReplayDescriptor>(); 348 for (long id : ids) { 349 ReplayDescriptor descriptor = descriptorsById.get(id); 350 descriptors.add(descriptor); 351 } 352 return descriptors; 353 } 344 354 } -
src/main/java/de/erichseifert/warp/io/search/DefaultReplayIndexer.java
rcf52b31 r70b8949 67 67 if (evt.getType() == EventType.REMOVE || evt.getType() == EventType.CHANGE) { 68 68 ReplayDescriptor descriptor = evt.getDescriptorOld(); 69 Replay replay = storage. load(descriptor.getId()).get(0);69 Replay replay = storage.getReplay(descriptor); 70 70 //TODO removeIndex(replay); 71 71 } 72 72 if (evt.getType() == EventType.ADD || evt.getType() == EventType.CHANGE) { 73 73 ReplayDescriptor descriptor = evt.getDescriptorNew(); 74 Replay replay = storage. load(descriptor.getId()).get(0);74 Replay replay = storage.getReplay(descriptor); 75 75 try { 76 76 createIndices(replay, null, 0); … … 188 188 // The parent element of an index hierarchy must be a replay 189 189 long replayID = resultHierarchy.getFirstElement().getId(); 190 Replay parentElement = storage.load(replayID).get(0); 191 ReplayDescriptor descriptor = parentElement.getDescriptor(); 190 ReplayDescriptor descriptor = storage.load(replayID).get(0); 192 191 results.add(descriptor); 193 192 } … … 208 207 for (IndexHierarchy.Entry entry : hierarchy) { 209 208 if ("#replay".equals(entry.getPropertyGetterName())) { 210 parentObj = storage.load(entry.getId()).get(0); 209 ReplayDescriptor descriptor = storage.load(entry.getId()).get(0); 210 parentObj = storage.getReplay(descriptor); 211 211 continue; 212 212 } -
src/main/java/de/erichseifert/warp/io/search/IndexHierarchy.java
rcf52b31 r70b8949 1 /** 2 * WARP: WARP is a Replay Manager for Java(R) 3 * 4 * (C) Copyright 2010-2010 Michael Seifert <michael.seifert[at]gmx.net> 5 * 6 * This file is part of WARP. 7 * 8 * WARP is free software: you can redistribute it and/or modify 9 * it under the terms of the GNU General Public License as published by 10 * the Free Software Foundation, either version 3 of the License, or 11 * (at your option) any later version. 12 * 13 * WARP is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with WARP. If not, see <http://www.gnu.org/licenses/>. 20 */ 21 1 22 package de.erichseifert.warp.io.search; 2 23 … … 23 44 public long getId() { 24 45 return id; 46 } 47 48 @Override 49 public String toString() { 50 return propertyGetterName+"="+id; 25 51 } 26 52 }
Note: See TracChangeset
for help on using the changeset viewer.