Package com.fitbit.api.client

Source Code of com.fitbit.api.client.FitbitApiCredentialsCacheMapImpl

package com.fitbit.api.client;

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

import com.fitbit.api.model.APIResourceCredentials;


public class FitbitApiCredentialsCacheMapImpl implements FitbitApiCredentialsCache {

    private final Map<LocalUserDetail, APIResourceCredentials> mapUserIdResourceCredentials =
              Collections.synchronizedMap(new HashMap<LocalUserDetail, APIResourceCredentials>());
    private final Map<String, APIResourceCredentials> mapTempTokenResourceCredentials =
              Collections.synchronizedMap(new HashMap<String, APIResourceCredentials>());

    @Override
    public APIResourceCredentials getResourceCredentials(LocalUserDetail user) {
        return mapUserIdResourceCredentials.get(user);
    }

    @Override
    public APIResourceCredentials getResourceCredentialsByTempToken(String tempToken) {
        return mapTempTokenResourceCredentials.get(tempToken);
    }

    @Override
    public APIResourceCredentials saveResourceCredentials(LocalUserDetail user, APIResourceCredentials resourceCredentials) {
        mapTempTokenResourceCredentials.put(resourceCredentials.getTempToken(), resourceCredentials);
        return mapUserIdResourceCredentials.put(user, resourceCredentials);
    }

    @Override
    public APIResourceCredentials expireResourceCredentials(LocalUserDetail user) {
        APIResourceCredentials resourceCredentials = mapUserIdResourceCredentials.get(user);
        if (resourceCredentials != null) {
            mapTempTokenResourceCredentials.remove(resourceCredentials.getTempToken());
        }
        return mapUserIdResourceCredentials.remove(user);
    }

}
TOP

Related Classes of com.fitbit.api.client.FitbitApiCredentialsCacheMapImpl

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.