Skip to content

Commit 4307cba

Browse files
authored
Merge pull request #291 from foodtiny/development
Hotfix for HashMap.entrySet
2 parents 1bf670d + a0c6749 commit 4307cba

4 files changed

Lines changed: 28 additions & 19 deletions

File tree

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44

55
**Native Library** brings productivity and maintainability for your C/C++ application as a Java program.
66

7-
* Blazing fast performance, small footprint with no dependency required
8-
* Provide rich Java Core classes compare to C++/STL
9-
* Zero memory leak and prevents segfaults via automatic storage
10-
* C++ and Java developers can use strength of two languages
7+
* Blazing fast, small footprint with no dependency required
8+
* Provide rich Java Core classes beside C++ Standard Library
9+
* Prevents nearly all memory leak and segfaults via automatic storage
1110
* Support bindings for NodeJS addon and Python module development (experimental)
1211
* Classes are strictly tested with unit tests, clean with Valgrind and follow Oracle documentation
1312
* Feel free to use in your commercial products and welcome for contributions
@@ -50,6 +49,7 @@ public:
5049
hashMap.put("argument " + String::valueOf(counter), argument);
5150
counter++;
5251
}
52+
System::out::println("We have 4 pairs:");
5353
String pairs = "Pairs: \n";
5454
for (Map<String, String>::Entry entry : hashMap.entrySet()) {
5555
pairs += entry.getKey() + String(" - ") + entry.getValue() + String("\n");

java/lang/Object/ObjectTest.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,7 @@
2525
*/
2626

2727
#include "../../../kernel/Test.hpp"
28-
#include "../String/String.hpp"
29-
#include "../Integer/Integer.hpp"
30-
#include "../Long/Long.hpp"
31-
#include "../System/System.hpp"
28+
#include "../../util/HashMap/HashMap.hpp"
3229

3330
using namespace Java::Lang;
3431

@@ -105,6 +102,14 @@ TEST (JavaLang, DataTypeArray) {
105102
// Retrieve elements from an existing array
106103
assertEquals("Food", initializedStrings.get(0).toString());
107104
assertEquals("Tiny", initializedStrings.get(1).toString());
105+
106+
Array<HashMap<String, String>*> arrayHashMap;
107+
HashMap<String, String> hashMap;
108+
hashMap.put("Key1", "Value1");
109+
arrayHashMap.push(&hashMap);
110+
for (auto hashMap : arrayHashMap) {
111+
assertEquals("Value1", hashMap->get("Key1").toString());
112+
}
108113
}
109114

110115
TEST (JavaLang, ArrayConstructorWithSize) {

java/util/HashMap/HashMap.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ namespace Java {
423423
Set<class Map<Key, Value>::Entry> entrySet;
424424

425425
for (auto const &pair : this->original) {
426-
Map<String, String>::Entry entry(pair.first, pair.second);
426+
class Map<Key, Value>::Entry entry(pair.first, pair.second);
427427
entrySet.add(entry);
428428
}
429429

java/util/HashMap/HashMapTest.cpp

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -146,17 +146,13 @@ TEST (JavaUtil, HashMapContainsValue) {
146146

147147
TEST (JavaUtil, HashMapEntrySet) {
148148
HashMap<String, String> hashMap;
149-
150149
int index = 1;
151-
152150
for (index; index <= 100; index++) {
153151
hashMap.put("Key " + String::valueOf(index),
154152
"Value " + String::valueOf(index));
155153
}
156-
157154
int counter = 0;
158155
Set<class Map<String, String>::Entry> entrySet = hashMap.entrySet();
159-
160156
// TODO - loint@foodtiny.com will improve entrySet
161157
// then we can put it inside foreach without any performance issue
162158
for (Map<String, String>::Entry entry : entrySet) {
@@ -170,9 +166,18 @@ TEST (JavaUtil, HashMapEntrySet) {
170166
assertEquals("Value 98", entry.getValue().toString());
171167
}
172168
}
173-
174169
// Make sure foreach is working
175170
assertEquals(100, counter);
171+
172+
HashMap<String, String*> hashMapStringPointer;
173+
hashMapStringPointer.put("test1", new String("test1"));
174+
hashMapStringPointer.put("test2", new String("test1"));
175+
hashMapStringPointer.put("test3", new String("test1"));
176+
for (Map<String, String*>::Entry entry : hashMapStringPointer.entrySet()) {
177+
assertEquals("test1", entry.getValue()->toString());
178+
String *stringValue = entry.getValue();
179+
delete stringValue;
180+
}
176181
}
177182

178183
TEST (JavaUtil, HashMapGet) {
@@ -849,7 +854,7 @@ TEST (JavaUtil, HashMapReinitialize) {
849854
// assertEquals(2, hashMap.size());
850855
// assertEquals(0, resultComputeIfPresentDefaultValueHashMap.intValue());
851856
//}
852-
//
857+
853858
//TEST(JavaUtil, HashMapForEach) {
854859
// /* Test HashMap<String, Integer> */
855860
// // Create a HashMap
@@ -859,10 +864,9 @@ TEST (JavaUtil, HashMapReinitialize) {
859864
// Integer result;
860865
//
861866
// // Create function
862-
// std::function<void(String, Integer)> function
863-
// = [] (String key, Integer value) {
864-
// printf("TEST(JavaUtil, HashMapForEach) is OK");
865-
// };
867+
// std::function<void(String, Integer)> function = [] (String key, Integer value) {
868+
// printf("TEST(JavaUtil, HashMapForEach) is OK");
869+
// };
866870
//
867871
// // foreach
868872
// hashMap.forEach(function);

0 commit comments

Comments
 (0)