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

package com.google.crypto.tink.internal;

import java.security.GeneralSecurityException;
import com.google.crypto.tink.Key;
import java.util.concurrent.atomic.AtomicReference;

public final class MutablePrimitiveRegistry
{
    private static MutablePrimitiveRegistry globalInstance;
    private final AtomicReference<PrimitiveRegistry> registry;
    
    public static MutablePrimitiveRegistry globalInstance() {
        return MutablePrimitiveRegistry.globalInstance;
    }
    
    public static void resetGlobalInstanceTestOnly() {
        MutablePrimitiveRegistry.globalInstance = new MutablePrimitiveRegistry();
    }
    
    MutablePrimitiveRegistry() {
        this.registry = new AtomicReference<PrimitiveRegistry>(PrimitiveRegistry.builder().build());
    }
    
    public synchronized <KeyT extends Key, PrimitiveT> void registerPrimitiveConstructor(final PrimitiveConstructor<KeyT, PrimitiveT> constructor) throws GeneralSecurityException {
        final PrimitiveRegistry newRegistry = PrimitiveRegistry.builder(this.registry.get()).registerPrimitiveConstructor(constructor).build();
        this.registry.set(newRegistry);
    }
    
    public synchronized <InputPrimitiveT, WrapperPrimitiveT> void registerPrimitiveWrapper(final PrimitiveWrapper<InputPrimitiveT, WrapperPrimitiveT> wrapper) throws GeneralSecurityException {
        final PrimitiveRegistry newRegistry = PrimitiveRegistry.builder(this.registry.get()).registerPrimitiveWrapper(wrapper).build();
        this.registry.set(newRegistry);
    }
    
    public <KeyT extends Key, PrimitiveT> PrimitiveT getPrimitive(final KeyT key, final Class<PrimitiveT> primitiveClass) throws GeneralSecurityException {
        return this.registry.get().getPrimitive(key, primitiveClass);
    }
    
    public <WrapperPrimitiveT> WrapperPrimitiveT wrap(final KeysetHandleInterface keysetHandle, final MonitoringAnnotations annotations, final Class<WrapperPrimitiveT> wrapperClassObject) throws GeneralSecurityException {
        return this.registry.get().wrap(keysetHandle, annotations, wrapperClassObject);
    }
    
    static {
        MutablePrimitiveRegistry.globalInstance = new MutablePrimitiveRegistry();
    }
}
