package com.timgroup.eventstore.merging;

import com.timgroup.eventstore.api.EventReader;
import com.timgroup.eventstore.api.EventSource;
import com.timgroup.eventstore.api.PositionCodec;

public final class NamedReaderWithCodec {
    final String name;
    final EventReader reader;
    final PositionCodec codec;

    public NamedReaderWithCodec(String name, EventReader reader, PositionCodec codec) {
        this.name = name;  //TODO: enforce name is not null or empty
        this.reader = reader;
        this.codec = codec;
    }

    public static NamedReaderWithCodec fromEventSource(String name, EventSource source) {
        return new NamedReaderWithCodec(name, source.readAll(), source.positionCodec());
    }

    EventReader toReader() {
        return reader;
    }

    @Override
    public String toString() {
        return "NamedReaderWithCodec{" +
                "name='" + name + '\'' +
                ", reader=" + reader +
                ", codec=" + codec +
                '}';
    }
}

@@ -35,16 +35,61 @@
 rging;%0A%0A
+import com.google.common.base.Preconditions;%0A
 import c
@@ -454,68 +454,169 @@
     
-this.
+Preconditions.checkNotNull(
 name
- = 
+, %22
 name
-;  //TODO: enforce 
+ cannot be null%22);%0A        Preconditions.checkArgument(!
 name
- is not null or empty
+.isEmpty(), %22name cannot be empty%22);%0A%0A        this.name = name;
 %0A   

enforce constraints on the reader name