com.google.protobuf.Internal.hashEnum()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(4.9k)|赞(0)|评价(0)|浏览(108)

本文整理了Java中com.google.protobuf.Internal.hashEnum()方法的一些代码示例,展示了Internal.hashEnum()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Internal.hashEnum()方法的具体详情如下:
包路径:com.google.protobuf.Internal
类名称:Internal
方法名:hashEnum

Internal.hashEnum介绍

[英]Helper method for implementing MessageLite#hashCode() for enums.

This is needed because java.lang.Enum#hashCode() is final, but we need to use the field number as the hash code to ensure compatibility between statically and dynamically generated enum objects.
[中]用于为枚举实现MessageLite#hashCode()的助手方法。
这是必要的,因为java。lang.Enum#hashCode()是最终的,但我们需要使用字段号作为哈希代码,以确保静态和动态生成的枚举对象之间的兼容性。

代码示例

代码示例来源:origin: com.google.protobuf/protobuf-java

  1. /**
  2. * Helper method for implementing {@link Message#hashCode()} for
  3. * enum lists.
  4. */
  5. public static int hashEnumList(List<? extends EnumLite> list) {
  6. int hash = 1;
  7. for (EnumLite e : list) {
  8. hash = 31 * hash + hashEnum(e);
  9. }
  10. return hash;
  11. }

代码示例来源:origin: com.google.protobuf/protobuf-java

  1. /** Get a hash code for given fields and values, using the given seed. */
  2. @SuppressWarnings("unchecked")
  3. protected static int hashFields(int hash, Map<FieldDescriptor, Object> map) {
  4. for (Map.Entry<FieldDescriptor, Object> entry : map.entrySet()) {
  5. FieldDescriptor field = entry.getKey();
  6. Object value = entry.getValue();
  7. hash = (37 * hash) + field.getNumber();
  8. if (field.isMapField()) {
  9. hash = (53 * hash) + hashMapField(value);
  10. } else if (field.getType() != FieldDescriptor.Type.ENUM){
  11. hash = (53 * hash) + value.hashCode();
  12. } else if (field.isRepeated()) {
  13. List<? extends EnumLite> list = (List<? extends EnumLite>) value;
  14. hash = (53 * hash) + Internal.hashEnumList(list);
  15. } else {
  16. hash = (53 * hash) + Internal.hashEnum((EnumLite) value);
  17. }
  18. }
  19. return hash;
  20. }

代码示例来源:origin: WeAreFairphone/FP2-Launcher

  1. /** Get a hash code for given fields and values, using the given seed. */
  2. @SuppressWarnings("unchecked")
  3. protected static int hashFields(int hash, Map<FieldDescriptor, Object> map) {
  4. for (Map.Entry<FieldDescriptor, Object> entry : map.entrySet()) {
  5. FieldDescriptor field = entry.getKey();
  6. Object value = entry.getValue();
  7. hash = (MAGIC_NUMBER_37 * hash) + field.getNumber();
  8. if (field.getType() != FieldDescriptor.Type.ENUM){
  9. hash = (MAGIC_NUMBER_53 * hash) + value.hashCode();
  10. } else if (field.isRepeated()) {
  11. List<? extends EnumLite> list = (List<? extends EnumLite>) value;
  12. hash = (MAGIC_NUMBER_53 * hash) + Internal.hashEnumList(list);
  13. } else {
  14. hash = (MAGIC_NUMBER_53 * hash) + Internal.hashEnum((EnumLite) value);
  15. }
  16. }
  17. return hash;
  18. }

代码示例来源:origin: WeAreFairphone/FP2-Launcher

  1. /**
  2. * Helper method for implementing {@link MessageLite#hashCode()} for
  3. * enum lists.
  4. */
  5. public static int hashEnumList(List<? extends EnumLite> list) {
  6. int hash = 1;
  7. for (EnumLite e : list) {
  8. hash = 31 * hash + hashEnum(e);
  9. }
  10. return hash;
  11. }

代码示例来源:origin: yeriomin/play-store-api

  1. /** Get a hash code for given fields and values, using the given seed. */
  2. @SuppressWarnings("unchecked")
  3. protected static int hashFields(int hash, Map<FieldDescriptor, Object> map) {
  4. for (Map.Entry<FieldDescriptor, Object> entry : map.entrySet()) {
  5. FieldDescriptor field = entry.getKey();
  6. Object value = entry.getValue();
  7. hash = (37 * hash) + field.getNumber();
  8. if (field.isMapField()) {
  9. hash = (53 * hash) + hashMapField(value);
  10. } else if (field.getType() != FieldDescriptor.Type.ENUM){
  11. hash = (53 * hash) + value.hashCode();
  12. } else if (field.isRepeated()) {
  13. List<? extends EnumLite> list = (List<? extends EnumLite>) value;
  14. hash = (53 * hash) + Internal.hashEnumList(list);
  15. } else {
  16. hash = (53 * hash) + Internal.hashEnum((EnumLite) value);
  17. }
  18. }
  19. return hash;
  20. }

代码示例来源:origin: com.google.protobuf/protobuf-lite

  1. /**
  2. * Helper method for implementing {@link Message#hashCode()} for
  3. * enum lists.
  4. */
  5. public static int hashEnumList(List<? extends EnumLite> list) {
  6. int hash = 1;
  7. for (EnumLite e : list) {
  8. hash = 31 * hash + hashEnum(e);
  9. }
  10. return hash;
  11. }

代码示例来源:origin: com.github.protobufel/protobufel-protobuf-test-protos

  1. hash = (53 * hash) + com.google.protobuf.Internal.hashEnum(
  2. getEnumFieldCount12());

代码示例来源:origin: yeriomin/play-store-api

  1. /**
  2. * Helper method for implementing {@link Message#hashCode()} for
  3. * enum lists.
  4. */
  5. public static int hashEnumList(List<? extends EnumLite> list) {
  6. int hash = 1;
  7. for (EnumLite e : list) {
  8. hash = 31 * hash + hashEnum(e);
  9. }
  10. return hash;
  11. }

代码示例来源:origin: com.github.protobufel/protobufel-protobuf-test-protos

  1. @java.lang.Override
  2. public int hashCode() {
  3. if (memoizedHashCode != 0) {
  4. return memoizedHashCode;
  5. }
  6. int hash = 41;
  7. hash = (19 * hash) + getDescriptorForType().hashCode();
  8. if (hasParser()) {
  9. hash = (37 * hash) + PARSER_FIELD_NUMBER;
  10. hash = (53 * hash) + com.google.protobuf.Internal.hashEnum(
  11. getParser());
  12. }
  13. hash = (29 * hash) + getUnknownFields().hashCode();
  14. memoizedHashCode = hash;
  15. return hash;
  16. }

代码示例来源:origin: com.github.protobufel/protobufel-protobuf-test-protos

  1. @java.lang.Override
  2. public int hashCode() {
  3. if (memoizedHashCode != 0) {
  4. return memoizedHashCode;
  5. }
  6. int hash = 41;
  7. hash = (19 * hash) + getDescriptorForType().hashCode();
  8. if (hasField1()) {
  9. hash = (37 * hash) + FIELD1_FIELD_NUMBER;
  10. hash = (53 * hash) + getField1();
  11. }
  12. if (hasField2()) {
  13. hash = (37 * hash) + FIELD2_FIELD_NUMBER;
  14. hash = (53 * hash) + com.google.protobuf.Internal.hashEnum(
  15. getField2());
  16. }
  17. if (hasField3()) {
  18. hash = (37 * hash) + FIELD3_FIELD_NUMBER;
  19. hash = (53 * hash) + getField3().hashCode();
  20. }
  21. hash = (29 * hash) + getUnknownFields().hashCode();
  22. memoizedHashCode = hash;
  23. return hash;
  24. }

相关文章