Changeset 2a40525


Ignore:
Timestamp:
Jun 10, 2010, 2:02:58 PM (10 years ago)
Author:
Michael Seifert <mseifert@…>
Branches:
master
Children:
3a1f9ee
Parents:
e58398c
Message:

Integrated buffering of parsed replays;

Added javadoc comments

Location:
src/main/java/de/erichseifert/warp
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/main/java/de/erichseifert/warp/WARP.java

    re58398c r2a40525  
    3131
    3232import de.erichseifert.warp.gui.ReplayParserGUI;
     33import de.erichseifert.warp.io.BufferedStorage;
    3334import de.erichseifert.warp.io.ReplayStorage;
    3435import de.erichseifert.warp.io.SerializingStorage;
     
    5354                listeners = new HashSet<ReplayDataChangeListener>();
    5455
    55                 storage = new SerializingStorage();
     56                ReplayStorage serStorage = new SerializingStorage();
     57                storage = new BufferedStorage(serStorage);
    5658
    5759                gui = new ReplayParserGUI(this);
     
    8890
    8991                // FIXME: Do not delete all files. Check them for being up-to-date
    90                 ((SerializingStorage) storage).deleteAll();
     92                //((SerializingStorage) storage).deleteAll();
    9193
    9294                // Store selected directory for the next startup
     
    119121        }
    120122
     123        /**
     124         * Notifies all listeners that new replay meta data is available.
     125         * @param replayDescriptors Replay descriptors.
     126         */
    121127        protected void fireReplayInfoChanged(Collection<ReplayDescriptor> replayDescriptors) {
    122128                for (ReplayDataChangeListener listener : listeners) {
  • src/main/java/de/erichseifert/warp/io/BufferedStorage.java

    re58398c r2a40525  
    1010import de.erichseifert.warp.ReplayDescriptor;
    1111
     12/**
     13 * Class that represents a buffer for any <code>ReplayStorage</code> object.
     14 * It caches the most recently used replays.
     15 */
    1216public class BufferedStorage implements ReplayStorage {
    13         private static final int BUFFER_SIZE = 20;
     17        private static final int BUFFER_SIZE_DEFAULT = 20;
    1418
    1519        private final ReplayStorage storage;
    1620        private final LinkedHashMap<String, Replay> buffer;
    1721
     22        private static final class StorageBuffer extends LinkedHashMap<String, Replay> {
     23                private final int bufferSize;
     24
     25                public StorageBuffer(int bufferSize) {
     26                        super(bufferSize+1, 0.75f, true);
     27                        this.bufferSize = bufferSize;
     28                }
     29
     30                @Override
     31                protected boolean removeEldestEntry(Map.Entry<String, Replay> eldest) {
     32                        return size() > bufferSize;
     33                }
     34        }
     35
     36        /**
     37         * Creates a new <code>BufferedStorage</code> object
     38         * buffering the specified storage and a default buffer size of 20.
     39         * @param storage ReplayStorage.
     40         */
    1841        public BufferedStorage(ReplayStorage storage) {
     42                this(storage, BUFFER_SIZE_DEFAULT);
     43        }
     44
     45        /**
     46         * Creates a new <code>BufferedStorage</code> object
     47         * buffering the specified storage.
     48         * @param storage ReplayStorage.
     49         * @param bufferSize Number of buffered elements.
     50         */
     51        public BufferedStorage(ReplayStorage storage, int bufferSize) {
    1952                this.storage = storage;
    20                 buffer = new LinkedHashMap<String, Replay>(BUFFER_SIZE+1, 0.75f, true) {
    21                         @Override
    22                         protected boolean removeEldestEntry(Map.Entry<String, Replay> eldest) {
    23                                 return size() > 20;
    24                         }
    25                 };
     53                buffer = new StorageBuffer(bufferSize);
    2654        }
    2755
     
    5078        }
    5179
     80        /**
     81         * Returns the underlying <code>ReplayStorage</code>.
     82         * @return Unbuffered storage.
     83         */
     84        public ReplayStorage getStorage() {
     85                return storage;
     86        }
    5287}
Note: See TracChangeset for help on using the changeset viewer.