package com.timgroup.eventstore.merging;

import com.google.common.base.Preconditions;
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) {
        Preconditions.checkNotNull(name, "name cannot be null");
        Preconditions.checkArgument(!name.isEmpty(), "name cannot be empty");

        this.name = name;
        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 +
                '}';
    }
}

@@ -39,53 +39,8 @@
 g;%0A%0A
-import com.google.common.base.Preconditions;%0A
 impo
@@ -182,16 +182,148 @@
 Codec;%0A%0A
+import static com.google.common.base.Preconditions.checkArgument;%0Aimport static com.google.common.base.Preconditions.checkNotNull;%0A%0A
 public f
@@ -533,38 +533,24 @@
 ) %7B%0A        
-Preconditions.
 checkNotNull
@@ -580,24 +580,25 @@
 null%22);%0A
+%0A
         
 Precondi
@@ -589,30 +589,66 @@
         
-Preconditions.
+final String candidateName = name.trim();%0A        
 checkArg
@@ -654,17 +654,26 @@
 gument(!
-n
+candidateN
 ame.isEm
@@ -725,17 +725,26 @@
 .name = 
-n
+candidateN
 ame;%0A   

trim reader names