package com.bumptech.glide.provider; import com.bumptech.glide.util.MultiClassKey; import java.util.HashMap; import java.util.Map; /** * A class that allows {@link com.bumptech.glide.provider.DataLoadProvider}s to be registered and retrieved by the * data and resource classes they provide encoders and decoders for. */ public class DataLoadProviderRegistry { private static final MultiClassKey GET_KEY = new MultiClassKey(); private final Map> providers = new HashMap>(); /** * Registers the given {@link com.bumptech.glide.provider.DataLoadProvider} using the given classes so it can later * be retrieved using the given classes. * * @param dataClass The class of the data that the provider provides encoders and decoders for. * @param resourceClass The class of the resource that the provider provides encoders and decoders for. * @param provider The provider. * @param The type of the data that the provider provides encoders and decoders for. * @param The type of the resource that the provider provides encoders and decoders for. */ public void register(Class dataClass, Class resourceClass, DataLoadProvider provider) { //TODO: maybe something like DataLoadProvider may work here providers.put(new MultiClassKey(dataClass, resourceClass), provider); } /** * Returns the currently registered {@link com.bumptech.glide.provider.DataLoadProvider} for the given classes. * * @param dataClass The class of the data that the provider provides encoders and decoders for. * @param resourceClass The class of the resource that the provider provides encoders and decoders for. * @param The type of the data that the provider provides encoders and decoders for. * @param The type of the resource that the provider provides encoders and decoders for. */ @SuppressWarnings("unchecked") public DataLoadProvider get(Class dataClass, Class resourceClass) { DataLoadProvider result; synchronized (GET_KEY) { GET_KEY.set(dataClass, resourceClass); result = providers.get(GET_KEY); } if (result == null) { result = EmptyDataLoadProvider.get(); } return (DataLoadProvider) result; } }