// Path: src/main/java/uk/elementarysoftware/quickcsv/api/CSVParserBuilder.java
// public static class CSVFileMetadata {
//         
//     public static CSVFileMetadata RFC_4180 = new CSVFileMetadata(',', Optional.of('"'));
//     public static CSVFileMetadata TABS = new CSVFileMetadata('\t', Optional.empty());
//         
//     public final char separator;
//     public final Optional<Character> quote;
// 
//     public CSVFileMetadata(char separator, Optional<Character> quote) {
//         this.separator = separator;
//         this.quote = quote;
//     }
// }


import java.util.ArrayList;
import java.util.Arrays;
import java.util.EnumMap;
import java.util.List;
import java.util.Map;
import uk.elementarysoftware.quickcsv.api.CSVParserBuilder.CSVFileMetadata;

package uk.elementarysoftware.quickcsv.parser;



/**
 * Provides view on the CSVRecord that focuses on particular subset of fields.
 * 
 * Within the view fields can be accessed by index in order of the subset or by field enumeration K.   
 * @param <K> - enum containing list of fields that form the subset
 */
public class FieldSubsetView<K extends Enum<K>> {
    
    private final HeaderSource headerSource;
    private final Class<K> fieldSubset;
    
    private boolean isFirstSlice = true;
    
    private int[] headerIndexesOfK;
    private int[] parseOrderToSourceOrder;
    private int[] fieldSkipSchedule;

    private FieldSubsetView(HeaderSource headerSource, Class<K> fieldSubset) {
        this.headerSource = headerSource;
        this.fieldSubset = fieldSubset;
    }
    
    public static <K extends Enum<K>> FieldSubsetView<K> forExplicitHeader(Class<K> fieldsToSource, String... header) {
        return new FieldSubsetView<>(new HeaderSource.ExplicitHeader(header), fieldsToSource);
    }
    
    public static <K extends Enum<K>> FieldSubsetView<K> forSourceSuppliedHeader(Class<K> fieldsToSource) {
        return forSourceSuppliedHeader(fieldsToSource, 0);
    }
    
    public static <K extends Enum<K>> FieldSubsetView<K>  forSourceSuppliedHeader(Class<K> fieldsToSource, int headerRowIndexInFile) {
        return new FieldSubsetView<>(new HeaderSource.SourceSuppliedHeader(headerRowIndexInFile), fieldsToSource);
    }
    

// Path: src/main/java/uk/elementarysoftware/quickcsv/api/CSVParserBuilder.java
// public static class CSVFileMetadata {
//         
//     public static CSVFileMetadata RFC_4180 = new CSVFileMetadata(',', Optional.of('"'));
//     public static CSVFileMetadata TABS = new CSVFileMetadata('\t', Optional.empty());
//         
//     public final char separator;
//     public final Optional<Character> quote;
// 
//     public CSVFileMetadata(char separator, Optional<Character> quote) {
//         this.separator = separator;
//         this.quote = quote;
//     }
// }


// Path: src/main/java/uk/elementarysoftware/quickcsv/parser/FieldSubsetView.java
import java.util.ArrayList;
import java.util.Arrays;
import java.util.EnumMap;
import java.util.List;
import java.util.Map;
import uk.elementarysoftware.quickcsv.api.CSVParserBuilder.CSVFileMetadata;

package uk.elementarysoftware.quickcsv.parser;



/**
 * Provides view on the CSVRecord that focuses on particular subset of fields.
 * 
 * Within the view fields can be accessed by index in order of the subset or by field enumeration K.   
 * @param <K> - enum containing list of fields that form the subset
 */
public class FieldSubsetView<K extends Enum<K>> {
    
    private final HeaderSource headerSource;
    private final Class<K> fieldSubset;
    
    private boolean isFirstSlice = true;
    
    private int[] headerIndexesOfK;
    private int[] parseOrderToSourceOrder;
    private int[] fieldSkipSchedule;

    private FieldSubsetView(HeaderSource headerSource, Class<K> fieldSubset) {
        this.headerSource = headerSource;
        this.fieldSubset = fieldSubset;
    }
    
    public static <K extends Enum<K>> FieldSubsetView<K> forExplicitHeader(Class<K> fieldsToSource, String... header) {
        return new FieldSubsetView<>(new HeaderSource.ExplicitHeader(header), fieldsToSource);
    }
    
    public static <K extends Enum<K>> FieldSubsetView<K> forSourceSuppliedHeader(Class<K> fieldsToSource) {
        return forSourceSuppliedHeader(fieldsToSource, 0);
    }
    
    public static <K extends Enum<K>> FieldSubsetView<K>  forSourceSuppliedHeader(Class<K> fieldsToSource, int headerRowIndexInFile) {
        return new FieldSubsetView<>(new HeaderSource.SourceSuppliedHeader(headerRowIndexInFile), fieldsToSource);
    }
    

    public void onSlice(ByteSlice slice, CSVFileMetadata metadata) {
