Search in sources :

Example 1 with EnumLite

use of com.google.protobuf.Internal.EnumLite in project Osmand by osmandapp.

the class AbstractMessage method hashFields.

/**
 * Get a hash code for given fields and values, using the given seed.
 */
@SuppressWarnings("unchecked")
protected int hashFields(int hash, Map<FieldDescriptor, Object> map) {
    for (Map.Entry<FieldDescriptor, Object> entry : map.entrySet()) {
        FieldDescriptor field = entry.getKey();
        Object value = entry.getValue();
        hash = (37 * hash) + field.getNumber();
        if (field.getType() != FieldDescriptor.Type.ENUM) {
            hash = (53 * hash) + value.hashCode();
        } else if (field.isRepeated()) {
            List<? extends EnumLite> list = (List<? extends EnumLite>) value;
            hash = (53 * hash) + hashEnumList(list);
        } else {
            hash = (53 * hash) + hashEnum((EnumLite) value);
        }
    }
    return hash;
}
Also used : EnumLite(com.google.protobuf.Internal.EnumLite) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) FieldDescriptor(com.google.protobuf.Descriptors.FieldDescriptor)

Example 2 with EnumLite

use of com.google.protobuf.Internal.EnumLite in project hpcourse by cscenter.

the class AbstractMessage method hashFields.

/**
 * Get a hash code for given fields and values, using the given seed.
 */
@SuppressWarnings("unchecked")
protected static int hashFields(int hash, Map<FieldDescriptor, Object> map) {
    for (Map.Entry<FieldDescriptor, Object> entry : map.entrySet()) {
        FieldDescriptor field = entry.getKey();
        Object value = entry.getValue();
        hash = (37 * hash) + field.getNumber();
        if (field.getType() != FieldDescriptor.Type.ENUM) {
            hash = (53 * hash) + value.hashCode();
        } else if (field.isRepeated()) {
            List<? extends EnumLite> list = (List<? extends EnumLite>) value;
            hash = (53 * hash) + Internal.hashEnumList(list);
        } else {
            hash = (53 * hash) + Internal.hashEnum((EnumLite) value);
        }
    }
    return hash;
}
Also used : EnumLite(com.google.protobuf.Internal.EnumLite) List(java.util.List) Map(java.util.Map) FieldDescriptor(com.google.protobuf.Descriptors.FieldDescriptor)

Aggregations

FieldDescriptor (com.google.protobuf.Descriptors.FieldDescriptor)2 EnumLite (com.google.protobuf.Internal.EnumLite)2 List (java.util.List)2 Map (java.util.Map)2 ArrayList (java.util.ArrayList)1