Rename dummy filter to basic filter.
[sonitus.git] / src / main / java / net / pterodactylus / sonitus / data / filter / TimeCounterFilter.java
index 6f31830..cfa93af 100644 (file)
@@ -31,7 +31,7 @@ import net.pterodactylus.sonitus.data.Metadata;
  *
  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
  */
-public class TimeCounterFilter extends DummyFilter {
+public class TimeCounterFilter extends BasicFilter {
 
        /** The byte counter. */
        private final AtomicLong counter = new AtomicLong();
@@ -95,25 +95,35 @@ public class TimeCounterFilter extends DummyFilter {
        }
 
        //
-       // DUMMYFILTER METHODS
+       // BASICFILTER METHODS
        //
 
        @Override
        public void metadataUpdated(Metadata metadata) {
-               super.metadataUpdated(metadata);
                parentMetadata.set(metadata);
                if (resetOnMetadataUpdate) {
                        reset();
                }
+               updateTimestamp(true);
        }
 
        @Override
        public void process(byte[] buffer) throws IOException {
                super.process(buffer);
                counter.getAndAdd(buffer.length);
+               updateTimestamp(false);
+       }
+
+       //
+       // PRIVATE METHODS
+       //
+
+       /** Updates the timestamp in the metadata. */
+       private void updateTimestamp(boolean now) {
                long timestamp = getMillis() / 1000;
-               if (lastTimestamp.get() != timestamp) {
-                       super.metadataUpdated(parentMetadata.get().title(String.format("%s (%02d:%02d)", parentMetadata.get().title(), timestamp / 60, timestamp % 60)));
+               if (now || (lastTimestamp.get() != timestamp)) {
+                       super.metadataUpdated(parentMetadata.get().comment(String.format("%02d:%02d", timestamp / 60, timestamp % 60)));
+                       lastTimestamp.set(timestamp);
                }
        }