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

package org.bson.codecs.pojo;

import java.util.HashMap;
import java.util.Collections;
import java.util.Map;

final class TypeParameterMap
{
    private final Map<Integer, Either<Integer, TypeParameterMap>> propertyToClassParamIndexMap;
    
    static Builder builder() {
        return new Builder();
    }
    
    Map<Integer, Either<Integer, TypeParameterMap>> getPropertyToClassParamIndexMap() {
        return this.propertyToClassParamIndexMap;
    }
    
    boolean hasTypeParameters() {
        return !this.propertyToClassParamIndexMap.isEmpty();
    }
    
    @Override
    public String toString() {
        return "TypeParameterMap{fieldToClassParamIndexMap=" + this.propertyToClassParamIndexMap + "}";
    }
    
    @Override
    public boolean equals(final Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || this.getClass() != o.getClass()) {
            return false;
        }
        final TypeParameterMap that = (TypeParameterMap)o;
        return this.getPropertyToClassParamIndexMap().equals(that.getPropertyToClassParamIndexMap());
    }
    
    @Override
    public int hashCode() {
        return this.getPropertyToClassParamIndexMap().hashCode();
    }
    
    private TypeParameterMap(final Map<Integer, Either<Integer, TypeParameterMap>> propertyToClassParamIndexMap) {
        this.propertyToClassParamIndexMap = Collections.unmodifiableMap((Map<? extends Integer, ? extends Either<Integer, TypeParameterMap>>)propertyToClassParamIndexMap);
    }
    
    static final class Builder
    {
        private final Map<Integer, Either<Integer, TypeParameterMap>> propertyToClassParamIndexMap;
        
        private Builder() {
            this.propertyToClassParamIndexMap = new HashMap<Integer, Either<Integer, TypeParameterMap>>();
        }
        
        Builder addIndex(final int classTypeParameterIndex) {
            this.propertyToClassParamIndexMap.put(-1, Either.left(classTypeParameterIndex));
            return this;
        }
        
        Builder addIndex(final int propertyTypeParameterIndex, final int classTypeParameterIndex) {
            this.propertyToClassParamIndexMap.put(propertyTypeParameterIndex, Either.left(classTypeParameterIndex));
            return this;
        }
        
        Builder addIndex(final int propertyTypeParameterIndex, final TypeParameterMap typeParameterMap) {
            this.propertyToClassParamIndexMap.put(propertyTypeParameterIndex, Either.right(typeParameterMap));
            return this;
        }
        
        TypeParameterMap build() {
            if (this.propertyToClassParamIndexMap.size() > 1 && this.propertyToClassParamIndexMap.containsKey(-1)) {
                throw new IllegalStateException("You cannot have a generic field that also has type parameters.");
            }
            return new TypeParameterMap(this.propertyToClassParamIndexMap, null);
        }
    }
}
