Skip to content

Commit 19e68fe

Browse files
authored
Improved source format
1 parent c1653b7 commit 19e68fe

File tree

12 files changed

+111
-95
lines changed

12 files changed

+111
-95
lines changed

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

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
*/
2424
package com.github.underscore;
2525

26+
import org.w3c.dom.NodeList;
27+
2628
import java.io.FileInputStream;
2729
import java.io.FileOutputStream;
2830
import java.io.IOException;
@@ -63,10 +65,10 @@
6365
import java.util.function.Function;
6466
import java.util.function.Predicate;
6567
import java.util.zip.GZIPInputStream;
68+
6669
import javax.xml.xpath.XPath;
6770
import javax.xml.xpath.XPathConstants;
6871
import javax.xml.xpath.XPathFactory;
69-
import org.w3c.dom.NodeList;
7072

7173
@SuppressWarnings({
7274
"java:S135",
@@ -2859,21 +2861,25 @@ public static void jsonFolderToXml(
28592861
throws IOException {
28602862
Path sourceRoot = Paths.get(jsonFolder);
28612863
Path targetRoot = Paths.get(xmlFolder);
2862-
Files.walkFileTree(sourceRoot, new SimpleFileVisitor<>() {
2863-
@Override
2864-
public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) throws IOException {
2865-
covertJsonToXml(path, sourceRoot, targetRoot, identStep);
2866-
return FileVisitResult.CONTINUE;
2867-
}
2868-
});
2864+
Files.walkFileTree(
2865+
sourceRoot,
2866+
new SimpleFileVisitor<>() {
2867+
@Override
2868+
public FileVisitResult visitFile(Path path, BasicFileAttributes attrs)
2869+
throws IOException {
2870+
covertJsonToXml(path, sourceRoot, targetRoot, identStep);
2871+
return FileVisitResult.CONTINUE;
2872+
}
2873+
});
28692874
}
28702875

28712876
public static void jsonFolderToXml(String jsonFolder, String xmlFolder) throws IOException {
28722877
jsonFolderToXml(jsonFolder, xmlFolder, Xml.XmlStringBuilder.Step.TWO_SPACES);
28732878
}
28742879

2875-
public static void covertJsonToXml(Path path, Path sourceRoot, Path targetRoot,
2876-
Xml.XmlStringBuilder.Step identStep) throws IOException {
2880+
public static void covertJsonToXml(
2881+
Path path, Path sourceRoot, Path targetRoot, Xml.XmlStringBuilder.Step identStep)
2882+
throws IOException {
28772883
Path relativePath = sourceRoot.relativize(path);
28782884
String fileName = relativePath.getFileName().toString();
28792885
String xmlFileName;
@@ -2892,21 +2898,25 @@ public static void xmlFolderToJson(
28922898
throws IOException {
28932899
Path sourceRoot = Paths.get(xmlFolder);
28942900
Path targetRoot = Paths.get(jsonFolder);
2895-
Files.walkFileTree(sourceRoot, new SimpleFileVisitor<>() {
2896-
@Override
2897-
public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) throws IOException {
2898-
covertXmlToJson(path, sourceRoot, targetRoot, identStep);
2899-
return FileVisitResult.CONTINUE;
2900-
}
2901-
});
2901+
Files.walkFileTree(
2902+
sourceRoot,
2903+
new SimpleFileVisitor<>() {
2904+
@Override
2905+
public FileVisitResult visitFile(Path path, BasicFileAttributes attrs)
2906+
throws IOException {
2907+
covertXmlToJson(path, sourceRoot, targetRoot, identStep);
2908+
return FileVisitResult.CONTINUE;
2909+
}
2910+
});
29022911
}
29032912

29042913
public static void xmlFolderToJson(String xmlFolder, String jsonFolder) throws IOException {
29052914
xmlFolderToJson(xmlFolder, jsonFolder, Json.JsonStringBuilder.Step.TWO_SPACES);
29062915
}
29072916

2908-
public static void covertXmlToJson(Path path, Path sourceRoot, Path targetRoot,
2909-
Json.JsonStringBuilder.Step identStep) throws IOException {
2917+
public static void covertXmlToJson(
2918+
Path path, Path sourceRoot, Path targetRoot, Json.JsonStringBuilder.Step identStep)
2919+
throws IOException {
29102920
Path relativePath = sourceRoot.relativize(path);
29112921
String fileName = relativePath.getFileName().toString();
29122922
String xmlFileName;
@@ -2984,11 +2994,11 @@ public static String detectEncoding(byte[] buffer) {
29842994
case 0x3C000000:
29852995
encoding = "UTF_32LE";
29862996
break;
2987-
// <?
2997+
// <?
29882998
case 0x3C003F00:
29892999
encoding = "UnicodeLittleUnmarked";
29903000
break;
2991-
// <?xm
3001+
// <?xm
29923002
case 0x3C3F786D:
29933003
encoding = "UTF8";
29943004
break;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1800,7 +1800,8 @@ protected static class Document {
18001800
private Document() {}
18011801

18021802
public static org.w3c.dom.Document createDocument(final String xml)
1803-
throws java.io.IOException, javax.xml.parsers.ParserConfigurationException,
1803+
throws java.io.IOException,
1804+
javax.xml.parsers.ParserConfigurationException,
18041805
org.xml.sax.SAXException {
18051806
final javax.xml.parsers.DocumentBuilderFactory factory =
18061807
javax.xml.parsers.DocumentBuilderFactory.newInstance();

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,15 @@
2323
*/
2424
package com.github.underscore;
2525

26-
import static java.util.Arrays.asList;
27-
import static java.util.Collections.singletonList;
2826
import static org.junit.jupiter.api.Assertions.assertEquals;
2927
import static org.junit.jupiter.api.Assertions.assertNull;
3028
import static org.junit.jupiter.api.Assertions.assertThrows;
3129

30+
import static java.util.Arrays.asList;
31+
import static java.util.Collections.singletonList;
32+
33+
import org.junit.jupiter.api.Test;
34+
3235
import java.util.ArrayList;
3336
import java.util.Arrays;
3437
import java.util.Collection;
@@ -38,7 +41,6 @@
3841
import java.util.Map;
3942
import java.util.NoSuchElementException;
4043
import java.util.Set;
41-
import org.junit.jupiter.api.Test;
4244

4345
/**
4446
* Underscore library unit test.
@@ -383,8 +385,7 @@ void interpose() {
383385
assertEquals("[a]", new Underscore<>(singletonList("a")).interpose("interpose").toString());
384386
assertEquals("[a, b]", new Underscore<>(singletonList("a, b")).interpose(null).toString());
385387
assertEquals("[a]", Underscore.chain(singletonList("a")).interpose("interpose").toString());
386-
assertEquals(
387-
"[]", Underscore.chain(new ArrayList<>()).interpose("interpose").toString());
388+
assertEquals("[]", Underscore.chain(new ArrayList<>()).interpose("interpose").toString());
388389
assertEquals(
389390
"[a, b, c]", Underscore.chain(asList("a", "b", "c")).interpose(null).toString());
390391
assertEquals(
@@ -650,6 +651,7 @@ void lastOrNull() {
650651
new Underscore<>(Collections.<Integer>emptyList())
651652
.lastOrNull(item -> item % 2 == 0));
652653
}
654+
653655
/*
654656
_.compact([0, 1, false, 2, '', 3]);
655657
=> [1, 2, 3]

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,12 @@
2323
*/
2424
package com.github.underscore;
2525

26-
import static java.util.Arrays.asList;
2726
import static org.junit.jupiter.api.Assertions.assertEquals;
2827

28+
import static java.util.Arrays.asList;
29+
30+
import org.junit.jupiter.api.Test;
31+
2932
import java.lang.reflect.Method;
3033
import java.util.ArrayList;
3134
import java.util.HashSet;
@@ -35,7 +38,6 @@
3538
import java.util.Set;
3639
import java.util.function.BiFunction;
3740
import java.util.function.Function;
38-
import org.junit.jupiter.api.Test;
3941

4042
/**
4143
* Underscore library unit test.

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,15 @@
2323
*/
2424
package com.github.underscore;
2525

26-
import static java.util.Arrays.asList;
2726
import static org.junit.jupiter.api.Assertions.assertEquals;
2827
import static org.junit.jupiter.api.Assertions.assertFalse;
2928
import static org.junit.jupiter.api.Assertions.assertThrows;
3029
import static org.junit.jupiter.api.Assertions.assertTrue;
3130

31+
import static java.util.Arrays.asList;
32+
33+
import org.junit.jupiter.api.Test;
34+
3235
import java.io.Serializable;
3336
import java.util.ArrayDeque;
3437
import java.util.ArrayList;
@@ -42,7 +45,6 @@
4245
import java.util.Optional;
4346
import java.util.Set;
4447
import java.util.function.Function;
45-
import org.junit.jupiter.api.Test;
4648

4749
/**
4850
* Underscore library unit test.

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,14 @@
2323
*/
2424
package com.github.underscore;
2525

26-
import static java.util.Arrays.asList;
2726
import static org.awaitility.Awaitility.await;
2827
import static org.junit.jupiter.api.Assertions.assertEquals;
2928
import static org.junit.jupiter.api.Assertions.assertTrue;
3029

30+
import static java.util.Arrays.asList;
31+
32+
import org.junit.jupiter.api.Test;
33+
3134
import java.util.ArrayList;
3235
import java.util.Arrays;
3336
import java.util.LinkedHashMap;
@@ -39,7 +42,6 @@
3942
import java.util.function.Predicate;
4043
import java.util.function.Supplier;
4144
import java.util.function.UnaryOperator;
42-
import org.junit.jupiter.api.Test;
4345

4446
@SuppressWarnings("java:S2925")
4547
class FunctionsTest {
@@ -199,7 +201,7 @@ void defer() {
199201
return null;
200202
});
201203
assertEquals(0, counter[0].intValue(), "incr was debounced");
202-
await().atMost(400, TimeUnit.MILLISECONDS)
204+
await().atMost(600, TimeUnit.MILLISECONDS)
203205
.until(
204206
() -> {
205207
assertEquals(1, counter[0].intValue(), "incr was debounced");

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

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,17 @@
2323
*/
2424
package com.github.underscore;
2525

26-
import static java.util.Arrays.asList;
27-
import static java.util.Collections.singletonList;
2826
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
2927
import static org.junit.jupiter.api.Assertions.assertEquals;
3028
import static org.junit.jupiter.api.Assertions.assertNull;
3129
import static org.junit.jupiter.api.Assertions.assertThrows;
3230
import static org.junit.jupiter.api.Assertions.assertTrue;
3331

32+
import static java.util.Arrays.asList;
33+
import static java.util.Collections.singletonList;
34+
35+
import org.junit.jupiter.api.Test;
36+
3437
import java.io.IOException;
3538
import java.net.URISyntaxException;
3639
import java.nio.file.Files;
@@ -45,7 +48,6 @@
4548
import java.util.LinkedHashSet;
4649
import java.util.List;
4750
import java.util.Map;
48-
import org.junit.jupiter.api.Test;
4951

5052
/**
5153
* Underscore library unit test.
@@ -688,13 +690,14 @@ void fetchResponseBlob() {
688690
@Test
689691
void fetchGetHttps() {
690692
U.FetchResponse result =
691-
U.fetch("https://support.oneskyapp.com/hc/en-us/article_attachments/202761627/example_1.json");
693+
U.fetch(
694+
"https://support.oneskyapp.com/hc/en-us/article_attachments/202761627/example_1.json");
692695
assertEquals(
693696
"{\n"
694-
+ " \"fruit\": \"Apple\",\n"
695-
+ " \"size\": \"Large\",\n"
696-
+ " \"color\": \"Red\"\n"
697-
+ "}",
697+
+ " \"fruit\": \"Apple\",\n"
698+
+ " \"size\": \"Large\",\n"
699+
+ " \"color\": \"Red\"\n"
700+
+ "}",
698701
result.text());
699702
}
700703

@@ -2009,10 +2012,7 @@ void chainMap() {
20092012
.toString());
20102013
assertEquals(
20112014
"{name1=one, name2=two, 1=2}",
2012-
com.github
2013-
.underscore
2014-
.U
2015-
.chain(
2015+
com.github.underscore.U.chain(
20162016
new LinkedHashMap<>() {
20172017
{
20182018
put("name1", "one");
@@ -2024,10 +2024,7 @@ void chainMap() {
20242024
.toString());
20252025
assertEquals(
20262026
"{name1=one, name2=two, 1=2}",
2027-
com.github
2028-
.underscore
2029-
.U
2030-
.of(
2027+
com.github.underscore.U.of(
20312028
new LinkedHashMap<>() {
20322029
{
20332030
put("name1", "one");

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

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,21 @@
2323
*/
2424
package com.github.underscore;
2525

26-
import static java.util.Arrays.asList;
2726
import static org.junit.jupiter.api.Assertions.assertEquals;
2827
import static org.junit.jupiter.api.Assertions.assertNull;
2928
import static org.junit.jupiter.api.Assertions.assertThrows;
3029

30+
import static java.util.Arrays.asList;
31+
32+
import org.junit.jupiter.api.Test;
33+
3134
import java.math.BigDecimal;
3235
import java.math.BigInteger;
3336
import java.util.ArrayList;
3437
import java.util.Collections;
3538
import java.util.HashSet;
3639
import java.util.List;
3740
import java.util.function.Function;
38-
import org.junit.jupiter.api.Test;
3941

4042
/**
4143
* Underscore library unit test.
@@ -222,8 +224,7 @@ void sum() {
222224
assertEquals("14.2", result12.toString());
223225
final Integer result13 = U.sum(asList(-1, -2, -3));
224226
assertEquals("-6", result13.toString());
225-
final Integer resultChain =
226-
(Integer) U.chain(asList(1, 2, 3)).sum().item();
227+
final Integer resultChain = (Integer) U.chain(asList(1, 2, 3)).sum().item();
227228
assertEquals("6", resultChain.toString());
228229
final Integer result14 = U.sum(new Integer[] {1, 2, 3});
229230
assertEquals("6", result14.toString());
@@ -249,8 +250,7 @@ void sum() {
249250
assertEquals("6", result20.toString());
250251
final Integer result21 = U.sum(new Integer[] {1, 2, null});
251252
assertEquals("3", result21.toString());
252-
final Integer resultChainFunc =
253-
U.chain(asList(1, 2, 3)).sum(item -> item * 2).item();
253+
final Integer resultChainFunc = U.chain(asList(1, 2, 3)).sum(item -> item * 2).item();
254254
assertEquals("12", resultChainFunc.toString());
255255
final Number resultObj = new U(asList(1, 2, 3)).sum();
256256
assertEquals("6", resultObj.toString());
@@ -350,8 +350,7 @@ void mean() {
350350
assertEquals("0.5", result.toString());
351351
final Double resultObj = new U(asList((double) 0, 0.5, (double) 1)).mean();
352352
assertEquals("0.5", resultObj.toString());
353-
final Double resultChain =
354-
U.chain(asList((double) 0, 0.5, (double) 1)).mean().item();
353+
final Double resultChain = U.chain(asList((double) 0, 0.5, (double) 1)).mean().item();
355354
assertEquals("0.5", resultChain.toString());
356355
final Double result2 = U.mean(asList((long) 0, (long) 1, (long) 2));
357356
assertEquals("1.0", result2.toString());
@@ -374,18 +373,15 @@ void mean() {
374373
void median() {
375374
final Double result = U.median(asList(0, 0, 0, 0, 5));
376375
assertEquals("0.0", result.toString());
377-
final Double resultObj =
378-
new U<>(asList(0, 0, 0, 0, 5)).median();
376+
final Double resultObj = new U<>(asList(0, 0, 0, 0, 5)).median();
379377
assertEquals("0.0", resultObj.toString());
380-
final Double resultChain =
381-
U.chain(asList(0, 0, 0, 0, 5)).median().item();
378+
final Double resultChain = U.chain(asList(0, 0, 0, 0, 5)).median().item();
382379
assertEquals("0.0", resultChain.toString());
383380
final Double result2 = U.median(asList(0, 0, 1, 2, 5));
384381
assertEquals("1.0", result2.toString());
385382
final Double result3 = U.median(asList(0, 0, 1, 2));
386383
assertEquals("0.5", result3.toString());
387-
final Double result4 =
388-
U.median(asList(0, 0, 1, 2, 3, 4));
384+
final Double result4 = U.median(asList(0, 0, 1, 2, 3, 4));
389385
assertEquals("1.5", result4.toString());
390386
}
391387

0 commit comments

Comments
 (0)