@Test public void protobufAttrsToMapTest() { List<Internal.Attr> attrs = new ArrayList<>(3); attrs.add(Internal.Attr.newBuilder() .setType(Util.PROTOBUF_STRING_TYPE) .setKey("stringval") .setStringValue("somestr") .build()); attrs.add(Internal.Attr.newBuilder() .setType(Util.PROTOBUF_INT_TYPE) .setKey("intval") .setIntValue(5) .build()); attrs.add(Internal.Attr.newBuilder() .setType(Util.PROTOBUF_BOOL_TYPE) .setKey("boolval") .setBoolValue(true) .build()); attrs.add(Internal.Attr.newBuilder() .setKey("doubleval") .setType(Util.PROTOBUF_DOUBLE_TYPE) .setFloatValue(123.5678) .build()); Map<String, Object> m = protobufAttrsToMap(attrs); assertEquals(4, m.size()); assertEquals("somestr", m.get("stringval")); assertEquals(5L, m.get("intval")); assertEquals(true, m.get("boolval")); assertEquals(123.5678, m.get("doubleval")); }
static Map<String, Object> protobufAttrsToMap(List<Internal.Attr> attrList) { Map<String, Object> attrs = new HashMap<>(attrList.size()); for (Internal.Attr attr : attrList) { Object value; switch ((int) attr.getType()) { case PROTOBUF_STRING_TYPE: value = attr.getStringValue(); break; case PROTOBUF_INT_TYPE: value = attr.getIntValue(); break; case PROTOBUF_BOOL_TYPE: value = attr.getBoolValue(); break; case PROTOBUF_DOUBLE_TYPE: value = attr.getFloatValue(); break; default: throw new PilosaException("Unknown attribute type: " + attr.getType()); } attrs.put(attr.getKey(), value); } return attrs; }
Util { static Map<String, Object> protobufAttrsToMap(List<Internal.Attr> attrList) { Map<String, Object> attrs = new HashMap<>(attrList.size()); for (Internal.Attr attr : attrList) { Object value; switch ((int) attr.getType()) { case PROTOBUF_STRING_TYPE: value = attr.getStringValue(); break; case PROTOBUF_INT_TYPE: value = attr.getIntValue(); break; case PROTOBUF_BOOL_TYPE: value = attr.getBoolValue(); break; case PROTOBUF_DOUBLE_TYPE: value = attr.getFloatValue(); break; default: throw new PilosaException("Unknown attribute type: " + attr.getType()); } attrs.put(attr.getKey(), value); } return attrs; } }
Util { static Map<String, Object> protobufAttrsToMap(List<Internal.Attr> attrList) { Map<String, Object> attrs = new HashMap<>(attrList.size()); for (Internal.Attr attr : attrList) { Object value; switch ((int) attr.getType()) { case PROTOBUF_STRING_TYPE: value = attr.getStringValue(); break; case PROTOBUF_INT_TYPE: value = attr.getIntValue(); break; case PROTOBUF_BOOL_TYPE: value = attr.getBoolValue(); break; case PROTOBUF_DOUBLE_TYPE: value = attr.getFloatValue(); break; default: throw new PilosaException("Unknown attribute type: " + attr.getType()); } attrs.put(attr.getKey(), value); } return attrs; }  }
Util { static Map<String, Object> protobufAttrsToMap(List<Internal.Attr> attrList) { Map<String, Object> attrs = new HashMap<>(attrList.size()); for (Internal.Attr attr : attrList) { Object value; switch ((int) attr.getType()) { case PROTOBUF_STRING_TYPE: value = attr.getStringValue(); break; case PROTOBUF_INT_TYPE: value = attr.getIntValue(); break; case PROTOBUF_BOOL_TYPE: value = attr.getBoolValue(); break; case PROTOBUF_DOUBLE_TYPE: value = attr.getFloatValue(); break; default: throw new PilosaException("Unknown attribute type: " + attr.getType()); } attrs.put(attr.getKey(), value); } return attrs; }   }
Util { static Map<String, Object> protobufAttrsToMap(List<Internal.Attr> attrList) { Map<String, Object> attrs = new HashMap<>(attrList.size()); for (Internal.Attr attr : attrList) { Object value; switch ((int) attr.getType()) { case PROTOBUF_STRING_TYPE: value = attr.getStringValue(); break; case PROTOBUF_INT_TYPE: value = attr.getIntValue(); break; case PROTOBUF_BOOL_TYPE: value = attr.getBoolValue(); break; case PROTOBUF_DOUBLE_TYPE: value = attr.getFloatValue(); break; default: throw new PilosaException("Unknown attribute type: " + attr.getType()); } attrs.put(attr.getKey(), value); } return attrs; }    }