// Path: src/main/java/com/nfl/glitr/exception/GlitrException.java
// public class GlitrException extends RuntimeException {
// 
//     public GlitrException(String message) {
//         super(message);
//     }
// 
//     public GlitrException(String message, Throwable cause) {
//         super(message, cause);
//     }
// }


import com.nfl.glitr.exception.GlitrException;
import graphql.schema.GraphQLType;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
package com.nfl.glitr.registry;



/**
 * A map implementation to sync the two kinds of registries currently in {@link com.nfl.glitr.registry.TypeRegistry}.
 * Syncs happen dynamically, keeping the nameRegistry appraised of classRegistry additions to ensure unique GraphQLTypes
 */
public class GlitrTypeMap implements ConcurrentMap {

    private final Map<Class, GraphQLType> classRegistry = new ConcurrentHashMap<>();
    private final Map<String, GraphQLType> nameRegistry = new ConcurrentHashMap<>();


    @Override
    public Object getOrDefault(Object key, Object defaultValue) {
        if (isClass(key)) {
            return classRegistry.getOrDefault(key, (GraphQLType) defaultValue);
        } else if (isString(key)) {
            return nameRegistry.getOrDefault(key, (GraphQLType) defaultValue);
        }
// Path: src/main/java/com/nfl/glitr/exception/GlitrException.java
// public class GlitrException extends RuntimeException {
// 
//     public GlitrException(String message) {
//         super(message);
//     }
// 
//     public GlitrException(String message, Throwable cause) {
//         super(message, cause);
//     }
// }


// Path: src/main/java/com/nfl/glitr/registry/GlitrTypeMap.java
import com.nfl.glitr.exception.GlitrException;
import graphql.schema.GraphQLType;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

package com.nfl.glitr.registry;



/**
 * A map implementation to sync the two kinds of registries currently in {@link com.nfl.glitr.registry.TypeRegistry}.
 * Syncs happen dynamically, keeping the nameRegistry appraised of classRegistry additions to ensure unique GraphQLTypes
 */
public class GlitrTypeMap implements ConcurrentMap {

    private final Map<Class, GraphQLType> classRegistry = new ConcurrentHashMap<>();
    private final Map<String, GraphQLType> nameRegistry = new ConcurrentHashMap<>();


    @Override
    public Object getOrDefault(Object key, Object defaultValue) {
        if (isClass(key)) {
            return classRegistry.getOrDefault(key, (GraphQLType) defaultValue);
        } else if (isString(key)) {
            return nameRegistry.getOrDefault(key, (GraphQLType) defaultValue);
        }
        throw new GlitrException("Unsupported type passed as key to GlitrTypeMap");