Skip to content

Commit 06dd4d9

Browse files
committed
Sync with underscore-java
1 parent 5a390f1 commit 06dd4d9

File tree

6 files changed

+103
-3
lines changed

6 files changed

+103
-3
lines changed

pom-central17.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,12 @@
132132
<version>[5.10.0,)</version>
133133
<scope>test</scope>
134134
</dependency>
135+
<dependency>
136+
<groupId>org.junit.platform</groupId>
137+
<artifactId>junit-platform-launcher</artifactId>
138+
<version>[1.10.0,)</version>
139+
<scope>test</scope>
140+
</dependency>
135141
<dependency>
136142
<groupId>org.awaitility</groupId>
137143
<artifactId>awaitility</artifactId>

pom-central21.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,12 @@
132132
<version>[5.10.0,)</version>
133133
<scope>test</scope>
134134
</dependency>
135+
<dependency>
136+
<groupId>org.junit.platform</groupId>
137+
<artifactId>junit-platform-launcher</artifactId>
138+
<version>[1.10.0,)</version>
139+
<scope>test</scope>
140+
</dependency>
135141
<dependency>
136142
<groupId>org.awaitility</groupId>
137143
<artifactId>awaitility</artifactId>

pom-pack17.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,12 @@
241241
<version>[5.10.0,)</version>
242242
<scope>test</scope>
243243
</dependency>
244+
<dependency>
245+
<groupId>org.junit.platform</groupId>
246+
<artifactId>junit-platform-launcher</artifactId>
247+
<version>[1.10.0,)</version>
248+
<scope>test</scope>
249+
</dependency>
244250
<dependency>
245251
<groupId>org.awaitility</groupId>
246252
<artifactId>awaitility</artifactId>

pom.xml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>com.github.javadev</groupId>
5-
<artifactId>underscore11</artifactId>
5+
<artifactId>underscore17</artifactId>
66
<packaging>jar</packaging>
77
<version>1.51-SNAPSHOT</version>
88
<name>java 17 port of Underscore.js</name>
@@ -145,7 +145,7 @@
145145
<plugin>
146146
<groupId>org.jacoco</groupId>
147147
<artifactId>jacoco-maven-plugin</artifactId>
148-
<version>0.8.10</version>
148+
<version>0.8.11</version>
149149
<configuration>
150150
<excludes>
151151
<exclude>**/U$BaseHttpSslSocketFactory*.class</exclude>
@@ -162,7 +162,7 @@
162162
<plugin>
163163
<groupId>org.apache.maven.plugins</groupId>
164164
<artifactId>maven-jxr-plugin</artifactId>
165-
<version>3.1.1</version>
165+
<version>3.3.1</version>
166166
</plugin>
167167
<plugin>
168168
<groupId>org.apache.maven.plugins</groupId>
@@ -214,6 +214,12 @@
214214
<version>[5.10.0,)</version>
215215
<scope>test</scope>
216216
</dependency>
217+
<dependency>
218+
<groupId>org.junit.platform</groupId>
219+
<artifactId>junit-platform-launcher</artifactId>
220+
<version>[1.10.0,)</version>
221+
<scope>test</scope>
222+
</dependency>
217223
<dependency>
218224
<groupId>org.awaitility</groupId>
219225
<artifactId>awaitility</artifactId>

src/main/java/com/github/underscore/U.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import java.util.Collection;
4141
import java.util.Collections;
4242
import java.util.Comparator;
43+
import java.util.Enumeration;
4344
import java.util.HashMap;
4445
import java.util.HashSet;
4546
import java.util.Iterator;
@@ -48,6 +49,7 @@
4849
import java.util.Locale;
4950
import java.util.Map;
5051
import java.util.Optional;
52+
import java.util.Properties;
5153
import java.util.Set;
5254
import java.util.function.BiConsumer;
5355
import java.util.function.BiFunction;
@@ -3491,4 +3493,28 @@ public String toString() {
34913493
return data.toString();
34923494
}
34933495
}
3496+
3497+
public static Map<String, Object> propertiesToMap(Properties properties) {
3498+
Map<String, Object> map = new LinkedHashMap<>();
3499+
if (properties != null && !properties.isEmpty()) {
3500+
Enumeration<?> enumProperties = properties.propertyNames();
3501+
while (enumProperties.hasMoreElements()) {
3502+
String name = (String)enumProperties.nextElement();
3503+
map.put(name, properties.getProperty(name));
3504+
}
3505+
}
3506+
return map;
3507+
}
3508+
3509+
public static Properties mapToProperties(Map<String, Object> map) {
3510+
Properties properties = new Properties();
3511+
if (map != null) {
3512+
for (final Map.Entry<String, Object> entry : map.entrySet()) {
3513+
if (!isNull(entry.getValue())) {
3514+
properties.put(entry.getKey(), String.valueOf(entry.getValue()));
3515+
}
3516+
}
3517+
}
3518+
return properties;
3519+
}
34943520
}

src/test/java/com/github/underscore/UnderscoreTest.java

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import java.util.NoSuchElementException;
4141
import java.util.Objects;
4242
import java.util.Optional;
43+
import java.util.Properties;
4344
import java.util.function.Predicate;
4445
import org.junit.jupiter.api.Test;
4546

@@ -745,4 +746,53 @@ void jobtest() {
745746
+ "{string=Hear it all the time, come back rewind, longestWord=6}]",
746747
result.toString());
747748
}
749+
750+
@Test
751+
void testPropertiesToMap() {
752+
Properties properties = new Properties();
753+
properties.setProperty("key1", "value1");
754+
properties.setProperty("key2", "value2");
755+
properties.setProperty("key3", "value3");
756+
Map<String, Object> map = U.propertiesToMap(properties);
757+
assertEquals(3, map.size());
758+
assertEquals("value1", map.get("key1"));
759+
assertEquals("value2", map.get("key2"));
760+
assertEquals("value3", map.get("key3"));
761+
}
762+
763+
@Test
764+
void testPropertiesToMapWithEmptyProperties() {
765+
Properties properties = new Properties();
766+
Map<String, Object> map = U.propertiesToMap(properties);
767+
assertEquals(0, map.size());
768+
Map<String, Object> map2 = U.propertiesToMap(null);
769+
assertEquals(0, map.size());
770+
}
771+
772+
@Test
773+
void testMapToProperties() {
774+
Map<String, Object> map = new LinkedHashMap<>();
775+
map.put("key1", "value1");
776+
map.put("key2", "value2");
777+
map.put("key3", "value3");
778+
Properties properties = U.mapToProperties(map);
779+
assertEquals(3, properties.size());
780+
assertEquals("value1", properties.getProperty("key1"));
781+
assertEquals("value2", properties.getProperty("key2"));
782+
assertEquals("value3", properties.getProperty("key3"));
783+
}
784+
785+
@Test
786+
void testMapToPropertiesWithNullValues() {
787+
Map<String, Object> map = new LinkedHashMap<>();
788+
map.put("key1", "value1");
789+
map.put("key2", null);
790+
map.put("key3", "value3");
791+
Properties properties = U.mapToProperties(map);
792+
assertEquals(2, properties.size());
793+
assertEquals("value1", properties.getProperty("key1"));
794+
assertEquals("value3", properties.getProperty("key3"));
795+
Properties properties2 = U.mapToProperties(null);
796+
assertEquals(0, properties2.size());
797+
}
748798
}

0 commit comments

Comments
 (0)