package com.sunxung.factoring.component.cache;

public class CacheKeyGenerator {
	/**
	 * 从id生成缓存键
	 * 
	 * @param clazz
	 * @param id
	 * @return
	 */
	public static String generateCacheKeyFromId(@SuppressWarnings("rawtypes") Class clazz, Long id) {
		return clazz.getName() + "_" + id.toString();
	}

	/**
	 * 生成缓存键
	 * 
	 * @param clazz
	 * @param name
	 * @return
	 */
	public static String generateCacheKeyFromString(@SuppressWarnings("rawtypes") Class clazz, String name) {
		return clazz.getName() + "_keystring:" + name;
	}

	/**
	 * 获取类型对应缓存数据
	 * 
	 * @param clazz
	 * @return
	 */
	public static String generateCacheKeyFromList(@SuppressWarnings("rawtypes") Class clazz) {
		return clazz.getName() + "_keystring:";
	}

	/**
	 * 从方法名称生成缓存键
	 * 
	 * @param clazz
	 * @param methodname
	 * @param paramText
	 * @return
	 */
	public static String generateCacheKeyFromMethodName(@SuppressWarnings("rawtypes") Class clazz, String methodname,
			String paramText) {
		return clazz.getName() + ":" + methodname + ",param:" + paramText;
	}

	/**
	 * 由int数组转至字符串
	 * 
	 * @param ints
	 * @return
	 */
	public static String intArrayToString(int[] ints) {
		StringBuffer result = new StringBuffer();
		if (ints != null && ints.length > 0) {
			for (int value : ints) {
				result.append(",").append(value);
			}
		}
		return result.toString();
	}
}
