当前位置: 首页>>代码示例>>Java>>正文


Java Hasher.putChar方法代码示例

本文整理汇总了Java中com.google.common.hash.Hasher.putChar方法的典型用法代码示例。如果您正苦于以下问题:Java Hasher.putChar方法的具体用法?Java Hasher.putChar怎么用?Java Hasher.putChar使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.common.hash.Hasher的用法示例。


在下文中一共展示了Hasher.putChar方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
}
 
开发者ID:cloudendpoints,项目名称:endpoints-management-java,代码行数:28,代码来源:CheckRequestAggregator.java

示例2: 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();
}
 
开发者ID:cloudendpoints,项目名称:endpoints-management-java,代码行数:19,代码来源:QuotaRequestAggregator.java

示例3: testBasics

import com.google.common.hash.Hasher; //导入方法依赖的package包/类
@Test
public void testBasics() {
    Hasher hasher = NullHasher.INSTANCE;
    assertEquals(0, hasher.hash().asInt());
    hasher.putBoolean(false);
    hasher.putByte((byte) 3);
    hasher.putBytes(new byte[0]);
    hasher.putBytes(null, 3, 3);
    hasher.putChar('c');
    hasher.putDouble(3.3);
    hasher.putFloat(3.4f);
    hasher.putInt(7);
    hasher.putLong(3);
    hasher.putObject(null, null);
    hasher.putShort((short) 7);
    hasher.putString(null, null);
    hasher.putUnencodedChars(null);
}
 
开发者ID:aws,项目名称:elastic-load-balancing-tools,代码行数:19,代码来源:NullHasherTest.java

示例4: 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();
}
 
开发者ID:dsldevkit,项目名称:dsl-devkit,代码行数:30,代码来源:DefaultInferredElementFragmentProvider.java

示例5: hashObject

import com.google.common.hash.Hasher; //导入方法依赖的package包/类
public void hashObject(Hasher hasher, boolean millisecondsRemoved) {
    hasher
        .putString("FileState", Charsets.UTF_8)
        .putChar(HASH_FIELD_SEPARATOR)
        .putString(fileName, Charsets.UTF_8)
        .putChar(HASH_FIELD_SEPARATOR)
        .putLong(fileLength);

    hasher.putChar(HASH_OBJECT_SEPARATOR);
    fileTime.hashObject(hasher, millisecondsRemoved);

    hasher.putChar(HASH_OBJECT_SEPARATOR);
    fileHash.hashObject(hasher);

    hasher.putChar(HASH_OBJECT_SEPARATOR);
    if (fileAttributes != null) {
        for (Map.Entry<String, String> entry : fileAttributes.entrySet()) {
            hasher
                .putString(entry.getKey(), Charsets.UTF_8)
                .putChar(':')
                .putChar(':')
                .putString(entry.getValue(), Charsets.UTF_8);
            hasher.putChar(HASH_OBJECT_SEPARATOR);
        }
    }
}
 
开发者ID:evrignaud,项目名称:fim,代码行数:27,代码来源:FileState.java

示例6: sign

import com.google.common.hash.Hasher; //导入方法依赖的package包/类
/**
 * Obtains the {@hashCode} for the contents of {@code value}.
 *
 * @param value a {@code Operation} to be signed
 * @return the {@code HashCode} corresponding to {@code value}
 */
private static HashCode sign(Operation value) {
  Hasher h = Hashing.md5().newHasher();
  h.putString(value.getConsumerId(), StandardCharsets.UTF_8);
  h.putChar('\0');
  h.putString(value.getOperationName(), StandardCharsets.UTF_8);
  h.putChar('\0');
  return Signing.putLabels(h, value.getLabels()).hash();
}
 
开发者ID:cloudendpoints,项目名称:endpoints-management-java,代码行数:15,代码来源:ReportRequestAggregator.java

示例7: hashObject

import com.google.common.hash.Hasher; //导入方法依赖的package包/类
@Override
public void hashObject(Hasher hasher) {
    hasher
        .putString("State", Charsets.UTF_8)
        .putChar(HASH_FIELD_SEPARATOR)
        .putString(modelVersion, Charsets.UTF_8)
        .putChar(HASH_FIELD_SEPARATOR)
        .putLong(timestamp)
        .putChar(HASH_FIELD_SEPARATOR)
        .putString(comment, Charsets.UTF_8)
        .putChar(HASH_FIELD_SEPARATOR)
        .putInt(fileCount)
        .putChar(HASH_FIELD_SEPARATOR)
        .putLong(filesContentLength)
        .putChar(HASH_FIELD_SEPARATOR)
        .putString(hashMode.name(), Charsets.UTF_8);

    hasher.putChar(HASH_OBJECT_SEPARATOR);
    for (String ignoredFile : ignoredFiles) {
        hasher
            .putString(ignoredFile, Charsets.UTF_8)
            .putChar(HASH_OBJECT_SEPARATOR);
    }

    hasher.putChar(HASH_OBJECT_SEPARATOR);
    for (FileState fileState : fileStates) {
        fileState.hashObject(hasher);
        hasher.putChar(HASH_OBJECT_SEPARATOR);
    }
}
 
开发者ID:evrignaud,项目名称:fim,代码行数:31,代码来源:State.java

示例8: apply

import com.google.common.hash.Hasher; //导入方法依赖的package包/类
@Override
public Sha1HashCode apply(Iterable<HasAndroidResourceDeps> deps) {
  Hasher hasher = Hashing.sha1().newHasher();
  for (HasAndroidResourceDeps dep : deps) {
    hasher.putUnencodedChars(dep.getPathToTextSymbolsFile().toString());
    // Avoid collisions by marking end of path explicitly.
    hasher.putChar('\0');
    hasher.putUnencodedChars(dep.getTextSymbolsAbiKey().getHash());
    hasher.putUnencodedChars(dep.getRDotJavaPackage());
    hasher.putChar('\0');
  }
  return new Sha1HashCode(hasher.hash().toString());
}
 
开发者ID:saleehk,项目名称:buck-cutom,代码行数:14,代码来源:HasAndroidResourceDeps.java

示例9: putChar

import com.google.common.hash.Hasher; //导入方法依赖的package包/类
@Override
public Hasher putChar(char c) {
  for (Hasher hasher : hashers) {
    hasher.putChar(c);
  }
  return this;
}
 
开发者ID:saleehk,项目名称:buck-cutom,代码行数:8,代码来源:AppendingHasher.java

示例10: hash

import com.google.common.hash.Hasher; //导入方法依赖的package包/类
/**
 * Utility method to compute an hash string from a vararg list of objects. The returned string
 * is 16 characters long, starts with {@code A-Za-z} and contains only characters
 * {@code A-Za-z0-9}.
 *
 * @param objects
 *            the objects to compute the hash from
 * @return the computed hash string
 */
public static String hash(final Object... objects) {
    final Hasher hasher = Hashing.md5().newHasher();
    for (final Object object : objects) {
        if (object instanceof CharSequence) {
            hasher.putString((CharSequence) object, Charsets.UTF_16LE);
        } else if (object instanceof byte[]) {
            hasher.putBytes((byte[]) object);
        } else if (object instanceof Character) {
            hasher.putChar((Character) object);
        } else if (object instanceof Boolean) {
            hasher.putBoolean((Boolean) object);
        } else if (object instanceof Integer) {
            hasher.putInt(((Integer) object).intValue());
        } else if (object instanceof Long) {
            hasher.putLong(((Long) object).longValue());
        } else if (object instanceof Double) {
            hasher.putDouble(((Double) object).doubleValue());
        } else if (object instanceof Float) {
            hasher.putFloat(((Float) object).floatValue());
        } else if (object instanceof Byte) {
            hasher.putByte(((Byte) object).byteValue());
        } else {
            hasher.putString(object.toString(), Charsets.UTF_16LE);
        }
    }
    final byte[] bytes = hasher.hash().asBytes();
    final StringBuilder builder = new StringBuilder(16);
    int max = 52;
    for (int i = 0; i < bytes.length; ++i) {
        final int n = (bytes[i] & 0x7F) % max;
        if (n < 26) {
            builder.append((char) (65 + n));
        } else if (n < 52) {
            builder.append((char) (71 + n));
        } else {
            builder.append((char) (n - 4));
        }
        max = 62;
    }
    return builder.toString();
}
 
开发者ID:dkmfbk,项目名称:knowledgestore,代码行数:51,代码来源:Data.java

示例11: putLabels

import com.google.common.hash.Hasher; //导入方法依赖的package包/类
/**
 * Updates {@code h} with the contents of {@code labels}.
 *
 * {@code labels} can be any Map&lt;String, String&gt;, but intended to be used for the labels of
 * one of the model protobufs.
 *
 * @param h a {@link Hasher}
 * @param labels some labels
 * @return the {@code Hasher}, to allow fluent-style usage
 */
public static Hasher putLabels(Hasher h, Map<String, String> labels) {
  for (Map.Entry<String, String> labelsEntry : labels.entrySet()) {
    h.putChar('\0');
    h.putString(labelsEntry.getKey(), StandardCharsets.UTF_8);
    h.putChar('\0');
    h.putString(labelsEntry.getValue(), StandardCharsets.UTF_8);
  }
  return h;
}
 
开发者ID:cloudendpoints,项目名称:endpoints-management-java,代码行数:20,代码来源:Signing.java


注:本文中的com.google.common.hash.Hasher.putChar方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。