// 
// Decompiled by Procyon v0.6.0
// 

package com.google.gson;

import com.google.gson.internal.NumberLimits;
import java.math.BigDecimal;
import com.google.gson.stream.MalformedJsonException;
import com.google.gson.internal.LazilyParsedNumber;
import java.io.IOException;
import com.google.gson.stream.JsonReader;

public enum ToNumberPolicy implements ToNumberStrategy
{
    DOUBLE {
        @Override
        public Double readNumber(final JsonReader in) throws IOException {
            return in.nextDouble();
        }
    }, 
    LAZILY_PARSED_NUMBER {
        @Override
        public Number readNumber(final JsonReader in) throws IOException {
            return new LazilyParsedNumber(in.nextString());
        }
    }, 
    LONG_OR_DOUBLE {
        @Override
        public Number readNumber(final JsonReader in) throws IOException, JsonParseException {
            final String value = in.nextString();
            if (value.indexOf(46) >= 0) {
                return this.parseAsDouble(value, in);
            }
            try {
                return Long.parseLong(value);
            }
            catch (final NumberFormatException e) {
                return this.parseAsDouble(value, in);
            }
        }
        
        private Number parseAsDouble(final String value, final JsonReader in) throws IOException {
            try {
                final Double d = Double.valueOf(value);
                if ((d.isInfinite() || d.isNaN()) && !in.isLenient()) {
                    throw new MalformedJsonException("JSON forbids NaN and infinities: " + d + "; at path " + in.getPreviousPath());
                }
                return d;
            }
            catch (final NumberFormatException e) {
                throw new JsonParseException("Cannot parse " + value + "; at path " + in.getPreviousPath(), e);
            }
        }
    }, 
    BIG_DECIMAL {
        @Override
        public BigDecimal readNumber(final JsonReader in) throws IOException {
            final String value = in.nextString();
            try {
                return NumberLimits.parseBigDecimal(value);
            }
            catch (final NumberFormatException e) {
                throw new JsonParseException("Cannot parse " + value + "; at path " + in.getPreviousPath(), e);
            }
        }
    };
}
