Search in sources :

Example 1 with EnumValueDescriptor

use of org.apache.hadoop.hbase.shaded.com.google.protobuf.Descriptors.EnumValueDescriptor in project hbase by apache.

the class AbstractMessage method convertMapEntryListToMap.

/**
   * Converts a list of MapEntry messages into a Map used for equals() and
   * hashCode().
   */
@SuppressWarnings({ "rawtypes", "unchecked" })
private static Map convertMapEntryListToMap(List list) {
    if (list.isEmpty()) {
        return Collections.emptyMap();
    }
    Map result = new HashMap();
    Iterator iterator = list.iterator();
    Message entry = (Message) iterator.next();
    Descriptors.Descriptor descriptor = entry.getDescriptorForType();
    Descriptors.FieldDescriptor key = descriptor.findFieldByName("key");
    Descriptors.FieldDescriptor value = descriptor.findFieldByName("value");
    Object fieldValue = entry.getField(value);
    if (fieldValue instanceof EnumValueDescriptor) {
        fieldValue = ((EnumValueDescriptor) fieldValue).getNumber();
    }
    result.put(entry.getField(key), fieldValue);
    while (iterator.hasNext()) {
        entry = (Message) iterator.next();
        fieldValue = entry.getField(value);
        if (fieldValue instanceof EnumValueDescriptor) {
            fieldValue = ((EnumValueDescriptor) fieldValue).getNumber();
        }
        result.put(entry.getField(key), fieldValue);
    }
    return result;
}
Also used : HashMap(java.util.HashMap) Iterator(java.util.Iterator) FieldDescriptor(org.apache.hadoop.hbase.shaded.com.google.protobuf.Descriptors.FieldDescriptor) Map(java.util.Map) HashMap(java.util.HashMap) EnumValueDescriptor(org.apache.hadoop.hbase.shaded.com.google.protobuf.Descriptors.EnumValueDescriptor)

Aggregations

HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 EnumValueDescriptor (org.apache.hadoop.hbase.shaded.com.google.protobuf.Descriptors.EnumValueDescriptor)1 FieldDescriptor (org.apache.hadoop.hbase.shaded.com.google.protobuf.Descriptors.FieldDescriptor)1