本文整理汇总了Java中com.google.common.hash.Hasher.hash方法的典型用法代码示例。如果您正苦于以下问题:Java Hasher.hash方法的具体用法?Java Hasher.hash怎么用?Java Hasher.hash使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.hash.Hasher
的用法示例。
在下文中一共展示了Hasher.hash方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sign
import com.google.common.hash.Hasher; //导入方法依赖的package包/类
/**
* Obtains the {@code HashCode} for the contents of {@code value}.
*
* @param value a {@code CheckRequest} to be signed
* @return the {@code HashCode} corresponding to {@code value}
*/
public static HashCode sign(CheckRequest value) {
Hasher h = Hashing.md5().newHasher();
Operation o = value.getOperation();
if (o == null || Strings.isNullOrEmpty(o.getConsumerId())
|| Strings.isNullOrEmpty(o.getOperationName())) {
throw new IllegalArgumentException("CheckRequest should have a valid operation");
}
h.putString(o.getConsumerId(), StandardCharsets.UTF_8);
h.putChar('\0');
h.putString(o.getOperationName(), StandardCharsets.UTF_8);
h.putChar('\0');
Signing.putLabels(h, o.getLabels());
for (MetricValueSet mvSet : o.getMetricValueSetsList()) {
h.putString(mvSet.getMetricName(), StandardCharsets.UTF_8);
h.putChar('\0');
for (MetricValue metricValue : mvSet.getMetricValuesList()) {
MetricValues.putMetricValue(h, metricValue);
}
}
return h.hash();
}
示例2: getCacheKey
import com.google.common.hash.Hasher; //导入方法依赖的package包/类
public String getCacheKey() {
Hasher hasher = hf.newHasher();
hasher.putUnencodedChars(queryKey);
for (Number id : ids) {
if (id instanceof Integer) {
hasher.putInt(id.intValue());
} else if (id instanceof Long) {
hasher.putLong(id.longValue());
} else if (id instanceof Short) {
hasher.putLong(id.shortValue());
} else if (id instanceof Double) {
hasher.putDouble(id.doubleValue());
} else if (id instanceof Float) {
hasher.putFloat(id.floatValue());
} else if (id instanceof Byte) {
hasher.putFloat(id.byteValue());
}
}
HashCode hashcode = hasher.hash();
return hashcode.toString();
}
示例3: sign
import com.google.common.hash.Hasher; //导入方法依赖的package包/类
@VisibleForTesting
static HashCode sign(AllocateQuotaRequest req) {
Hasher h = Hashing.md5().newHasher();
QuotaOperation o = req.getAllocateOperation();
h.putString(o.getMethodName(), StandardCharsets.UTF_8);
h.putChar('\0');
h.putString(o.getConsumerId(), StandardCharsets.UTF_8);
ImmutableSortedSet.Builder<String> builder =
new ImmutableSortedSet.Builder<>(Ordering.natural());
for (MetricValueSet mvSet : o.getQuotaMetricsList()) {
builder.add(mvSet.getMetricName());
}
for (String metricName : builder.build()) {
h.putChar('\0');
h.putString(metricName, StandardCharsets.UTF_8);
}
return h.hash();
}
示例4: createCoordinatorRegistryCenter
import com.google.common.hash.Hasher; //导入方法依赖的package包/类
/**
* 创建注册中心.
*
* @param connectString 注册中心连接字符串
* @param namespace 注册中心命名空间
* @param digest 注册中心凭证
* @return 注册中心对象
*/
public static CoordinatorRegistryCenter createCoordinatorRegistryCenter(final String connectString, final String namespace, final Optional<String> digest) {
Hasher hasher = Hashing.md5().newHasher().putString(connectString, Charsets.UTF_8).putString(namespace, Charsets.UTF_8);
if (digest.isPresent()) {
hasher.putString(digest.get(), Charsets.UTF_8);
}
HashCode hashCode = hasher.hash();
if (registryCenterMap.containsKey(hashCode)) {
return registryCenterMap.get(hashCode);
}
ZookeeperConfiguration zkConfig = new ZookeeperConfiguration(connectString, namespace);
if (digest.isPresent()) {
zkConfig.setDigest(digest.get());
}
CoordinatorRegistryCenter result = new ZookeeperRegistryCenter(zkConfig);
result.init();
registryCenterMap.putIfAbsent(hashCode, result);
return result;
}
示例5: computeHash
import com.google.common.hash.Hasher; //导入方法依赖的package包/类
/**
* Computes a hash code for the given {@link #getEClass(EObject) EClass} and {@link #getQualifiedName(EObject) qualified name}.
*
* @param eClass
* EClass to base hash on, must not be {@code null}
* @param name
* qualified name of inferred model element, can be {@code null}
* @return hash code, never {@code null}
*/
protected HashCode computeHash(final EClass eClass, final QualifiedName name) {
byte[] eClassUriBytes = eClassToUriBytesMap.get(eClass);
if (eClassUriBytes == null) {
eClassUriBytes = EcoreUtil.getURI(eClass).toString().getBytes(Charsets.UTF_8);
eClassToUriBytesMap.put(eClass, eClassUriBytes);
}
Hasher hasher = hashFunction.newHasher(HASHER_CAPACITY);
hasher.putBytes(eClassUriBytes);
if (name != null) {
hasher.putChar('/');
for (int j = 0; j < name.getSegmentCount(); j++) {
hasher.putUnencodedChars(name.getSegment(j)).putChar('.');
}
}
return hasher.hash();
}
示例6: createCoordinatorRegistryCenter
import com.google.common.hash.Hasher; //导入方法依赖的package包/类
/**
* 创建注册中心.
*
* @param connectString 注册中心连接字符串
* @param namespace 注册中心命名空间
* @param digest 注册中心凭证
* @return 注册中心对象
*/
public static ElasticConfigRegistryCenter createCoordinatorRegistryCenter(final String connectString,
final String namespace, final Optional<String> digest) {
Hasher hasher = Hashing.md5().newHasher().putString(connectString, Charsets.UTF_8)
.putString(namespace, Charsets.UTF_8);
if (digest.isPresent()) {
hasher.putString(digest.get(), Charsets.UTF_8);
}
HashCode hashCode = hasher.hash();
if (registryCenterMap.containsKey(hashCode)) {
return registryCenterMap.get(hashCode);
}
ZookeeperConfiguration zkConfig = new ZookeeperConfiguration(connectString, namespace);
if (digest.isPresent()) {
zkConfig.setDigest(digest.get());
}
ElasticConfigRegistryCenter result = new ZookeeperRegistryCenter(zkConfig);
result.init();
registryCenterMap.putIfAbsent(hashCode, result);
return result;
}
示例7: generateHash
import com.google.common.hash.Hasher; //导入方法依赖的package包/类
private HashCode generateHash() {
final Hasher hasher = HASH_FUNCTION.newHasher();
if (key != null) {
hasher.putString(key, Charsets.UTF_8);
}
for (final Map.Entry<String, String> kv : tags.entrySet()) {
final String k = kv.getKey();
final String v = kv.getValue();
if (k != null) {
hasher.putString(k, Charsets.UTF_8);
}
if (v != null) {
hasher.putString(v, Charsets.UTF_8);
}
}
return hasher.hash();
}
示例8: computeHashes
import com.google.common.hash.Hasher; //导入方法依赖的package包/类
public static long[] computeHashes(String item, int numWords, int seed)
{
long[] hashes = new long[numWords];
for (int word = 0; word < numWords; word += 2)
{
HashFunction hashFunc = Hashing.murmur3_128(seed + word);
Hasher hasher = hashFunc.newHasher();
hasher.putUnencodedChars(item);
// get the two longs out
HashCode hc = hasher.hash();
ByteBuffer bb = ByteBuffer.wrap(hc.asBytes());
hashes[word] = bb.getLong(0);
if (word + 1 < numWords)
hashes[word + 1] = bb.getLong(8);
}
return hashes;
}
示例9: getComponentHash
import com.google.common.hash.Hasher; //导入方法依赖的package包/类
@Override
public HashCode getComponentHash(ComponentModel src, HashCode parentHashCode) {
Hasher hasher = hf.newHasher();
if (parentHashCode != null)
hasher.putBytes(parentHashCode.asBytes());
Map<String, String> srcProperties = src.getProperties();
hasher.putString(srcProperties.get("title"), Charsets.UTF_8);
for (String key : structuralPropertyList) {
String value = srcProperties.get(key);
if (value != null)
hasher.putString(value, Charsets.UTF_8);
else
hasher.putBoolean(false);
}
return hasher.hash();
}
示例10: getEventHash
import com.google.common.hash.Hasher; //导入方法依赖的package包/类
@Override
public HashCode getEventHash(EventModel src) {
Hasher hasher = hf.newHasher();
String id = src.getComponentModel().get("id");
if (id != null)
hasher.putString(id, Charsets.UTF_8);
else
hasher.putBoolean(false);
hasher.putInt(src.getValueHash());
String componentIdx = src.getComponentModel().get("componentIndex");
if (componentIdx != null)
hasher.putString(componentIdx, Charsets.UTF_8);
else
hasher.putBoolean(false);
return hasher.hash();
}
示例11: calculateFilterSpecHash
import com.google.common.hash.Hasher; //导入方法依赖的package包/类
private static HashCode calculateFilterSpecHash(FilteringClassLoader.Spec spec) {
Hasher hasher = Hashing.md5().newHasher();
addToHash(hasher, spec.getClassNames());
addToHash(hasher, spec.getPackageNames());
addToHash(hasher, spec.getPackagePrefixes());
addToHash(hasher, spec.getResourcePrefixes());
addToHash(hasher, spec.getResourceNames());
addToHash(hasher, spec.getDisallowedClassNames());
addToHash(hasher, spec.getDisallowedPackagePrefixes());
return hasher.hash();
}
示例12: calculateActionClassLoaderHash
import com.google.common.hash.Hasher; //导入方法依赖的package包/类
private static HashCode calculateActionClassLoaderHash(Collection<ClassLoader> taskActionClassLoaders, ClassLoaderHierarchyHasher classLoaderHierarchyHasher) {
if (taskActionClassLoaders.isEmpty()) {
return NO_ACTION_LOADERS;
}
Hasher hasher = Hashing.md5().newHasher();
for (ClassLoader taskActionClassLoader : taskActionClassLoaders) {
HashCode actionLoaderHash = classLoaderHierarchyHasher.getClassLoaderHash(taskActionClassLoader);
if (actionLoaderHash == null) {
return null;
}
hasher.putBytes(actionLoaderHash.asBytes());
}
return hasher.hash();
}
示例13: hash
import com.google.common.hash.Hasher; //导入方法依赖的package包/类
@Override
public HashCode hash(File file) {
try {
Hasher hasher = createFileHasher();
Files.copy(file, Funnels.asOutputStream(hasher));
return hasher.hash();
} catch (IOException e) {
throw new UncheckedIOException(String.format("Failed to create MD5 hash for file '%s'.", file), e);
}
}
示例14: combinedHashOf
import com.google.common.hash.Hasher; //导入方法依赖的package包/类
private HashCode combinedHashOf(Object[] components) {
Hasher hasher = hashFunction.newHasher();
for (Object c : components) {
hasher.putBytes(hashOf(c).asBytes());
}
return hasher.hash();
}
示例15: build
import com.google.common.hash.Hasher; //导入方法依赖的package包/类
public CacheEntry build() {
Path baseDir = cacheDir.resolve(name);
if (!keys.isEmpty()) {
HashFunction hf = Hashing.md5();
Hasher h = hf.newHasher();
for (String key : keys) {
h.putString(key, Charsets.UTF_8);
}
HashCode hc = h.hash();
baseDir = baseDir.resolve(hc.toString());
}
cacheEntriesLock.lock();
try {
CacheEntry cacheEntry = cacheEntries.get(baseDir.toString());
if (cacheEntry != null) {
if (!cacheEntry.getKeys().equals(keys)) {
throw new PowsyblException("Inconsistent hash");
}
} else {
cacheEntry = new CacheEntry(baseDir, keys);
cacheEntries.put(baseDir.toString(), cacheEntry);
}
return cacheEntry;
} finally {
cacheEntriesLock.unlock();
}
}