diff --git a/hazelcast/include/hazelcast/client/HazelcastJsonValue.h b/hazelcast/include/hazelcast/client/HazelcastJsonValue.h index fdbc0de3bc..f7ca0c7457 100644 --- a/hazelcast/include/hazelcast/client/HazelcastJsonValue.h +++ b/hazelcast/include/hazelcast/client/HazelcastJsonValue.h @@ -69,6 +69,8 @@ namespace hazelcast { bool operator!=(const HazelcastJsonValue &rhs) const; + bool operator<(const HazelcastJsonValue &rhs) const; + friend std::ostream HAZELCAST_API &operator<<(std::ostream &os, const HazelcastJsonValue &value); private: diff --git a/hazelcast/include/hazelcast/client/map/ClientMapProxy.h b/hazelcast/include/hazelcast/client/map/ClientMapProxy.h index a40c3f9e78..e1a0bd8d27 100644 --- a/hazelcast/include/hazelcast/client/map/ClientMapProxy.h +++ b/hazelcast/include/hazelcast/client/map/ClientMapProxy.h @@ -654,10 +654,11 @@ namespace hazelcast { std::vector keySet() { std::vector dataResult = proxy::IMapImpl::keySetData(); size_t size = dataResult.size(); - std::vector keys(size); + std::vector keys; + keys.reserve(size); for (size_t i = 0; i < size; ++i) { std::unique_ptr key = toObject(dataResult[i]); - keys[i] = *key; + keys.push_back(*key); } return keys; } @@ -693,10 +694,11 @@ namespace hazelcast { std::vector keySet(const query::Predicate &predicate) { std::vector dataResult = proxy::IMapImpl::keySetData(predicate); size_t size = dataResult.size(); - std::vector keys(size); + std::vector keys; + keys.reserve(size); for (size_t i = 0; i < size; ++i) { std::unique_ptr key = toObject(dataResult[i]); - keys[i] = *key; + keys.push_back(*key); } return keys; } @@ -747,10 +749,11 @@ namespace hazelcast { std::vector values() { std::vector dataResult = proxy::IMapImpl::valuesData(); size_t size = dataResult.size(); - std::vector values(size); + std::vector values; + values.reserve(size); for (size_t i = 0; i < size; ++i) { std::unique_ptr value = toObject(dataResult[i]); - values[i] = *value; + values.push_back(*value); } return values; } @@ -782,6 +785,7 @@ namespace hazelcast { std::vector dataResult = proxy::IMapImpl::valuesData(predicate); size_t size = dataResult.size(); std::vector values; + values.reserve(size); for (size_t i = 0; i < size; ++i) { std::unique_ptr value = toObject(dataResult[i]); values.push_back(*value); @@ -826,11 +830,12 @@ namespace hazelcast { std::vector > entrySet() { std::vector > dataResult = proxy::IMapImpl::entrySetData(); size_t size = dataResult.size(); - std::vector > entries(size); + std::vector > entries; + entries.reserve(size); for (size_t i = 0; i < size; ++i) { std::unique_ptr key = toObject(dataResult[i].first); std::unique_ptr value = toObject(dataResult[i].second); - entries[i] = std::make_pair(*key, *value); + entries.emplace_back(*key, *value); } return entries; } @@ -851,11 +856,12 @@ namespace hazelcast { std::vector > dataResult = proxy::IMapImpl::entrySetData( predicate); size_t size = dataResult.size(); - std::vector > entries(size); + std::vector > entries; + entries.reserve(size); for (size_t i = 0; i < size; ++i) { std::unique_ptr key = toObject(dataResult[i].first); std::unique_ptr value = toObject(dataResult[i].second); - entries[i] = std::make_pair(*key, *value); + entries.emplace_back(*key, *value); } return entries; } @@ -874,11 +880,12 @@ namespace hazelcast { std::vector > dataResult = proxy::IMapImpl::entrySetData( predicate); size_t size = dataResult.size(); - std::vector > entries(size); + std::vector > entries; + entries.reserve(size); for (size_t i = 0; i < size; ++i) { std::unique_ptr key = toObject(dataResult[i].first); std::unique_ptr value = toObject(dataResult[i].second); - entries[i] = std::make_pair(*key, *value); + entries.emplace_back(*key, *value); } return entries; } diff --git a/hazelcast/src/hazelcast/client/serialization.cpp b/hazelcast/src/hazelcast/client/serialization.cpp index 8bf8242a13..aa10b07e2c 100644 --- a/hazelcast/src/hazelcast/client/serialization.cpp +++ b/hazelcast/src/hazelcast/client/serialization.cpp @@ -60,6 +60,10 @@ namespace hazelcast { return jsonString == rhs.jsonString; } + bool HazelcastJsonValue::operator<(const HazelcastJsonValue &rhs) const { + return jsonString < rhs.jsonString; + } + bool HazelcastJsonValue::operator!=(const HazelcastJsonValue &rhs) const { return !(rhs == *this); } diff --git a/hazelcast/test/src/HazelcastTests5.cpp b/hazelcast/test/src/HazelcastTests5.cpp index 2f9522b529..ea31b7dd5d 100644 --- a/hazelcast/test/src/HazelcastTests5.cpp +++ b/hazelcast/test/src/HazelcastTests5.cpp @@ -2391,6 +2391,7 @@ namespace hazelcast { static const char *intMapName; static const char *employeesMapName; static const char *imapName; + static const char *jsonMapName; static const std::string ONE_SECOND_MAP_NAME; MapClientConfig() { @@ -2403,6 +2404,7 @@ namespace hazelcast { const char *MapClientConfig::intMapName = "IntMap"; const char *MapClientConfig::employeesMapName = "EmployeesMap"; + const char *MapClientConfig::jsonMapName = "jsonMapTest"; const char *MapClientConfig::imapName = "clientMapTest"; const std::string MapClientConfig::ONE_SECOND_MAP_NAME = "OneSecondTtlMap"; @@ -2450,7 +2452,8 @@ namespace hazelcast { ClientMapTest() : client(HazelcastClient(GetParam())), imap(client.getMap(MapClientConfig::imapName)), intMap(client.getMap(MapClientConfig::intMapName)), - employees(client.getMap(MapClientConfig::employeesMapName)) { + employees(client.getMap(MapClientConfig::employeesMapName)), + jsonMap(client.getMap(MapClientConfig::jsonMapName)) { } static void SetUpTestCase() { @@ -2738,6 +2741,7 @@ namespace hazelcast { IMap imap; IMap intMap; IMap employees; + IMap jsonMap; static HazelcastServer *instance; static HazelcastServer *instance2; @@ -3293,6 +3297,26 @@ namespace hazelcast { } + TEST_P(ClientMapTest, testJsonValues) { + const int numItems = 5; + for (int i = 0; i < numItems; ++i) { + jsonMap.put("key_" + std::to_string(i), HazelcastJsonValue("{ \"value\"=\"value_" + std::to_string(i) + "\"}")); + } + std::vector values = jsonMap.values(); + ASSERT_EQ(numItems, (int) values.size()); + } + + TEST_P(ClientMapTest, testJsonValuesWithPagingPredicate) { + const int numItems = 5; + const int predSize = 3; + for (int i = 0; i < numItems; ++i) { + jsonMap.put("key_" + std::to_string(i), HazelcastJsonValue("{ \"value\"=\"value_" + std::to_string(i) + "\"}")); + } + query::PagingPredicate predicate((size_t) predSize); + std::vector values = jsonMap.values(predicate); + ASSERT_EQ(predSize, (int) values.size()); + } + TEST_P(ClientMapTest, testValues) { fillMap(); std::vector tempVector;