/**
 * Copyright (c) 2000-2017 Liferay, Inc. All rights reserved.
 *
 * The contents of this file are subject to the terms of the Liferay Enterprise
 * pSubscription License ("License"). You may not use this file except in
 * compliance with the License. You can obtain a copy of the License by
 * contacting Liferay, Inc. See the License for the specific language governing
 * permissions and limitations under the License, including but not limited to
 * distribution rights of the Software.
 *
 *
 *
 */package com.liferay.portal.kernel.lar;

import com.liferay.portal.kernel.util.AutoResetThreadLocal;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* @author Tamas Molnar
*/
public class StagingIndexingDeletionThreadLocal {

	public static Map<String, List<String>> getDeletionKeysMap() {
		return _deletionKeysMap.get();
	}

	public static void setDeletionKey(String className, String uid) {
		Map<String, List<String>> deletionKeysMap = _deletionKeysMap.get();

		if (!deletionKeysMap.containsKey(className)) {
			deletionKeysMap.put(className, new ArrayList<String>());
		}

		List<String> uids = deletionKeysMap.get(className);

		if (!uids.contains(uid)) {
			uids.add(uid);
		}
	}

	private static ThreadLocal<Map<String, List<String>>> _deletionKeysMap =
		new AutoResetThreadLocal<Map<String, List<String>>>(
			StagingIndexingDeletionThreadLocal.class + "._deletionKeysMap",
			new HashMap<String, List<String>>());

}