com.fasterxml.jackson.databind.util.EnumResolver.java Source code

Java tutorial

Introduction

Here is the source code for com.fasterxml.jackson.databind.util.EnumResolver.java

Source

package com.fasterxml.jackson.databind.util;

import com.fasterxml.jackson.databind.AnnotationIntrospector;
import java.io.Serializable;
import java.lang.reflect.Method;
import java.util.HashMap;

public class EnumResolver<T extends Enum<T>> implements Serializable {
    protected final Class<T> _enumClass;
    protected final T[] _enums;
    protected final HashMap<String, T> _enumsById;

    protected EnumResolver(Class<T> paramClass, T[] paramArrayOfT, HashMap<String, T> paramHashMap) {
        this._enumClass = paramClass;
        this._enums = paramArrayOfT;
        this._enumsById = paramHashMap;
    }

    public static <ET extends Enum<ET>> EnumResolver<ET> constructFor(Class<ET> paramClass,
            AnnotationIntrospector paramAnnotationIntrospector) {
        Enum[] arrayOfEnum = (Enum[]) paramClass.getEnumConstants();
        if (arrayOfEnum == null)
            throw new IllegalArgumentException("No enum constants for class " + paramClass.getName());
        HashMap localHashMap = new HashMap();
        int i = arrayOfEnum.length;
        for (int j = 0; j < i; j++) {
            Enum localEnum = arrayOfEnum[j];
            localHashMap.put(paramAnnotationIntrospector.findEnumValue(localEnum), localEnum);
        }
        return new EnumResolver(paramClass, arrayOfEnum, localHashMap);
    }

    public static EnumResolver<?> constructUnsafe(Class<?> paramClass,
            AnnotationIntrospector paramAnnotationIntrospector) {
        return constructFor(paramClass, paramAnnotationIntrospector);
    }

    public static EnumResolver<?> constructUnsafeUsingMethod(Class<?> paramClass, Method paramMethod) {
        return constructUsingMethod(paramClass, paramMethod);
    }

    public static EnumResolver<?> constructUnsafeUsingToString(Class<?> paramClass) {
        return constructUsingToString(paramClass);
    }

    public static <ET extends Enum<ET>> EnumResolver<ET> constructUsingMethod(Class<ET> paramClass,
            Method paramMethod) {
        Enum[] arrayOfEnum = (Enum[]) paramClass.getEnumConstants();
        HashMap localHashMap = new HashMap();
        int i = arrayOfEnum.length;
        while (true) {
            i--;
            if (i >= 0) {
                Enum localEnum = arrayOfEnum[i];
                try {
                    Object localObject = paramMethod.invoke(localEnum, new Object[0]);
                    if (localObject != null)
                        localHashMap.put(localObject.toString(), localEnum);
                } catch (Exception localException) {
                    throw new IllegalArgumentException("Failed to access @JsonValue of Enum value " + localEnum
                            + ": " + localException.getMessage());
                }
            }
        }
        return new EnumResolver(paramClass, arrayOfEnum, localHashMap);
    }

    public static <ET extends Enum<ET>> EnumResolver<ET> constructUsingToString(Class<ET> paramClass) {
        Enum[] arrayOfEnum = (Enum[]) paramClass.getEnumConstants();
        HashMap localHashMap = new HashMap();
        int i = arrayOfEnum.length;
        while (true) {
            i--;
            if (i < 0)
                break;
            Enum localEnum = arrayOfEnum[i];
            localHashMap.put(localEnum.toString(), localEnum);
        }
        return new EnumResolver(paramClass, arrayOfEnum, localHashMap);
    }

    public T findEnum(String paramString) {
        return (Enum) this._enumsById.get(paramString);
    }

    public T getEnum(int paramInt) {
        if ((paramInt < 0) || (paramInt >= this._enums.length))
            return null;
        return this._enums[paramInt];
    }

    public Class<T> getEnumClass() {
        return this._enumClass;
    }

    public int lastValidIndex() {
        return -1 + this._enums.length;
    }
}

/* Location:           /Users/dantheman/src/fffffffffattttt/basis/classes_dex2jar.jar
 * Qualified Name:     com.fasterxml.jackson.databind.util.EnumResolver
 * JD-Core Version:    0.6.2
 */