/*
 * Apache HTTPD & NGINX Access log parsing made easy
 * Copyright (C) 2011-2017 Niels Basjes
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package nl.basjes.parse.core.test;

import nl.basjes.parse.core.Casts;
import nl.basjes.parse.core.Parsable;
import nl.basjes.parse.core.SimpleDissector;
import nl.basjes.parse.core.Value;
import nl.basjes.parse.core.exceptions.DissectionFailure;

import java.util.EnumSet;
import java.util.HashMap;

/**
 * A dummy dissector to ensure retrieving all types works in the various wrappers
 */
public class UltimateDummyDissector extends SimpleDissector {

    private static HashMap<String, EnumSet<Casts>> dissectorConfig = new HashMap<>();
    static {
        dissectorConfig.put("ANY:any",         Casts.STRING_OR_LONG_OR_DOUBLE);
        dissectorConfig.put("STRING:string",   Casts.STRING_ONLY);
        dissectorConfig.put("INT:int",         Casts.STRING_OR_LONG);
        dissectorConfig.put("LONG:long",       Casts.STRING_OR_LONG);
        dissectorConfig.put("FLOAT:float",     Casts.STRING_OR_DOUBLE);
        dissectorConfig.put("DOUBLE:double",   Casts.STRING_OR_DOUBLE);
    }

    public UltimateDummyDissector() {
        super("INPUT", dissectorConfig);
    }

    @Override
    public void dissect(Parsable<?> parsable, String inputname, Value value) throws DissectionFailure {
        parsable.addDissection(inputname, "ANY",    "any",    "42");
        parsable.addDissection(inputname, "STRING", "string", "42");
        parsable.addDissection(inputname, "INT",    "int",    42);
        parsable.addDissection(inputname, "LONG",   "long",   42L);
        parsable.addDissection(inputname, "FLOAT",  "float",  42F);
        parsable.addDissection(inputname, "DOUBLE", "double", 42D);
    }

}

@@ -718,16 +718,55 @@
 .Casts;%0A
+import nl.basjes.parse.core.Dissector;%0A
 import n
@@ -932,16 +932,82 @@
 Failure;
+%0Aimport nl.basjes.parse.core.exceptions.InvalidDissectorException;
 %0A%0Aimport
@@ -1051,16 +1051,38 @@
 HashMap;
+%0Aimport java.util.Map;
 %0A%0A/**%0A *
@@ -1847,24 +1847,272 @@
 ig);%0A    %7D%0A%0A
+    public UltimateDummyDissector(String inputType) %7B%0A        super(inputType, dissectorConfig);%0A    %7D%0A%0A    @Override%0A    public boolean initializeFromSettingsParameter(String settings) %7B%0A        setInputType(settings);%0A        return true;%0A    %7D%0A%0A
     @Overrid

Allow overriding the input field for the test dissector