package org.monospark.spongematchers.parser.data;

import java.util.Optional;
import java.util.Set;

import org.monospark.spongematchers.matcher.data.DataEntry;
import org.monospark.spongematchers.matcher.data.DataValue.Type;
import org.monospark.spongematchers.parser.SpongeMatcherParseException;
import org.monospark.spongematchers.parser.SpongeMatcherParser;

import com.google.common.collect.Sets;

public abstract class DataEntryParser<T extends DataEntry> {

    public static final Set<DataEntryParser<?>> PARSERS = createDataEntryParsers();
    
    private static Set<DataEntryParser<?>> createDataEntryParsers() {
        Set<DataEntryParser<?>> parsers = Sets.newHashSet();
        parsers.add(new DataNullParser());
        parsers.add(new DataValueParser<Long>(Type.INTEGER, SpongeMatcherParser.INTEGER));
        parsers.add(new DataValueParser<String>(Type.STRING, SpongeMatcherParser.STRING));
        parsers.add(new DataListParser());
        parsers.add(new DataMapParser());
        return parsers;
    }
    
    static Optional<? extends DataEntry> parseDataEntry(String string) throws SpongeMatcherParseException {
        String trimmed = string.trim();
        for (DataEntryParser<?> parser : PARSERS) {
                Optional<? extends DataEntry> entry = parser.parse(trimmed);
                if (entry.isPresent()) {
                    return entry;
            }
        }
        return Optional.empty();
    }

    abstract Optional<T> parse(String string) throws SpongeMatcherParseException;
}

@@ -765,55 +765,256 @@
 ser%3C
-Long%3E(Type.INTEGER, SpongeMatcherParser.INTEGER
+Boolean%3E(Type.BOOLEAN, SpongeMatcherParser.BOOLEAN));%0A        parsers.add(new DataValueParser%3CLong%3E(Type.INTEGER, SpongeMatcherParser.INTEGER));%0A        parsers.add(new DataValueParser%3CDouble%3E(Type.FLOATING_POINT, SpongeMatcherParser.FLOATING_POINT
 ));%0A
@@ -1436,20 +1436,16 @@
         
-    
 Optional
@@ -1509,20 +1509,16 @@
         
-    
 if (entr
@@ -1530,28 +1530,24 @@
 resent()) %7B%0A
-    
             

Make all data value types parseable