001
014
015 package com.liferay.portal.cache.key;
016
017 import com.liferay.portal.kernel.cache.key.CacheKeyGenerator;
018 import com.liferay.portal.kernel.util.StringBundler;
019
020
024 public class HashCodeCacheKeyGenerator extends BaseCacheKeyGenerator {
025
026 @Override
027 public CacheKeyGenerator clone() {
028 return new HashCodeCacheKeyGenerator();
029 }
030
031 @Override
032 public Long getCacheKey(String key) {
033 long hashCode = 0;
034
035 for (int i = 0; i < key.length(); i++) {
036 hashCode = 31 * hashCode + key.charAt(i);
037 }
038
039 return hashCode;
040 }
041
042 @Override
043 public Long getCacheKey(String[] keys) {
044 long hashCode = 0;
045
046 for (String key : keys) {
047 if (key == null) {
048 continue;
049 }
050
051 for (int i = 0; i < key.length(); i++) {
052 hashCode = 31 * hashCode + key.charAt(i);
053 }
054 }
055
056 return hashCode;
057 }
058
059 @Override
060 public Long getCacheKey(StringBundler sb) {
061 long hashCode = 0;
062
063 for (int i = 0; i < sb.index(); i++) {
064 String key = sb.stringAt(i);
065
066 for (int j = 0; j < key.length(); j++) {
067 hashCode = 31 * hashCode + key.charAt(j);
068 }
069 }
070
071 return hashCode;
072 }
073
074 }