Skip to content

Commit 541905f

Browse files
committed
Format source codes.
1 parent 4a2eb02 commit 541905f

File tree

20 files changed

+653
-487
lines changed

20 files changed

+653
-487
lines changed

examples/src/main/java/com/github/underscore/examples/Chaining.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,34 +44,36 @@ public static <T, E> List<T> map(final List<E> list, final Function<? super E, T
4444
return transformed;
4545
}
4646

47-
public static <E, T extends Comparable<? super T>> List<E> sortBy(final List<E> iterable,
48-
final Function<E, T> func) {
47+
public static <E, T extends Comparable<? super T>> List<E> sortBy(
48+
final List<E> iterable, final Function<E, T> func) {
4949
final List<E> sortedList = new ArrayList<>(iterable);
5050
sortedList.sort(Comparator.comparing(func::apply));
5151
return sortedList;
5252
}
5353

54-
/*
55-
var stooges = [{name: 'curly', age: 25}, {name: 'moe', age: 21}, {name: 'larry', age: 23}];
56-
var youngest = _.chain(stooges)
57-
.sortBy(function(stooge){ return stooge.age; })
58-
.map(function(stooge){ return stooge.name + ' is ' + stooge.age; })
59-
.first()
60-
.value();
61-
=> "moe is 21"
62-
*/
54+
/*
55+
var stooges = [{name: 'curly', age: 25}, {name: 'moe', age: 21}, {name: 'larry', age: 23}];
56+
var youngest = _.chain(stooges)
57+
.sortBy(function(stooge){ return stooge.age; })
58+
.map(function(stooge){ return stooge.name + ' is ' + stooge.age; })
59+
.first()
60+
.value();
61+
=> "moe is 21"
62+
*/
6363
public static <T> Chain<T> chain(final List<T> list) {
6464
return new Chaining.Chain<>(list);
6565
}
6666

6767
public static class Chain<T> {
6868
private final T item;
6969
private final List<T> list;
70+
7071
@SuppressWarnings("unchecked")
7172
public Chain(final T item) {
7273
this.item = item;
7374
this.list = null;
7475
}
76+
7577
public Chain(final List<T> list) {
7678
this.item = null;
7779
this.list = list;

examples/src/main/java/com/github/underscore/examples/FromJson.java

Lines changed: 74 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -84,32 +84,32 @@ public Object parse() {
8484

8585
private Object readValue() {
8686
switch (current) {
87-
case 'n':
88-
return readNull();
89-
case 't':
90-
return readTrue();
91-
case 'f':
92-
return readFalse();
93-
case '"':
94-
return readString();
95-
case '[':
96-
return readArray();
97-
case '{':
98-
return readObject();
99-
case '-':
100-
case '0':
101-
case '1':
102-
case '2':
103-
case '3':
104-
case '4':
105-
case '5':
106-
case '6':
107-
case '7':
108-
case '8':
109-
case '9':
110-
return readNumber();
111-
default:
112-
throw expected("value");
87+
case 'n':
88+
return readNull();
89+
case 't':
90+
return readTrue();
91+
case 'f':
92+
return readFalse();
93+
case '"':
94+
return readString();
95+
case '[':
96+
return readArray();
97+
case '{':
98+
return readObject();
99+
case '-':
100+
case '0':
101+
case '1':
102+
case '2':
103+
case '3':
104+
case '4':
105+
case '5':
106+
case '6':
107+
case '7':
108+
case '8':
109+
case '9':
110+
return readNumber();
111+
default:
112+
throw expected("value");
113113
}
114114
}
115115

@@ -215,45 +215,49 @@ private String readString() {
215215
private void readEscape() {
216216
read();
217217
switch (current) {
218-
case '"':
219-
case '/':
220-
case '\\':
221-
captureBuffer.append((char) current);
222-
break;
223-
case 'b':
224-
captureBuffer.append('\b');
225-
break;
226-
case 'f':
227-
captureBuffer.append('\f');
228-
break;
229-
case 'n':
230-
captureBuffer.append('\n');
231-
break;
232-
case 'r':
233-
captureBuffer.append('\r');
234-
break;
235-
case 't':
236-
captureBuffer.append('\t');
237-
break;
238-
case 'u':
239-
char[] hexChars = new char[4];
240-
boolean isHexCharsDigits = true;
241-
for (int i = 0; i < 4; i++) {
242-
read();
243-
if (!isHexDigit()) {
244-
isHexCharsDigits = false;
218+
case '"':
219+
case '/':
220+
case '\\':
221+
captureBuffer.append((char) current);
222+
break;
223+
case 'b':
224+
captureBuffer.append('\b');
225+
break;
226+
case 'f':
227+
captureBuffer.append('\f');
228+
break;
229+
case 'n':
230+
captureBuffer.append('\n');
231+
break;
232+
case 'r':
233+
captureBuffer.append('\r');
234+
break;
235+
case 't':
236+
captureBuffer.append('\t');
237+
break;
238+
case 'u':
239+
char[] hexChars = new char[4];
240+
boolean isHexCharsDigits = true;
241+
for (int i = 0; i < 4; i++) {
242+
read();
243+
if (!isHexDigit()) {
244+
isHexCharsDigits = false;
245+
}
246+
hexChars[i] = (char) current;
245247
}
246-
hexChars[i] = (char) current;
247-
}
248-
if (isHexCharsDigits) {
249-
captureBuffer.append((char) Integer.parseInt(new String(hexChars), 16));
250-
} else {
251-
captureBuffer.append("\\u").append(hexChars[0]).append(hexChars[1]).append(hexChars[2])
252-
.append(hexChars[3]);
253-
}
254-
break;
255-
default:
256-
throw expected("valid escape sequence");
248+
if (isHexCharsDigits) {
249+
captureBuffer.append((char) Integer.parseInt(new String(hexChars), 16));
250+
} else {
251+
captureBuffer
252+
.append("\\u")
253+
.append(hexChars[0])
254+
.append(hexChars[1])
255+
.append(hexChars[2])
256+
.append(hexChars[3]);
257+
}
258+
break;
259+
default:
260+
throw expected("valid escape sequence");
257261
}
258262
read();
259263
}
@@ -266,8 +270,7 @@ private Number readNumber() {
266270
throw expected("digit");
267271
}
268272
if (firstDigit != '0') {
269-
while (readDigit()) {
270-
}
273+
while (readDigit()) {}
271274
}
272275
readFraction();
273276
readExponent();
@@ -286,8 +289,7 @@ private boolean readFraction() {
286289
if (!readDigit()) {
287290
throw expected("digit");
288291
}
289-
while (readDigit()) {
290-
}
292+
while (readDigit()) {}
291293
return true;
292294
}
293295

@@ -301,8 +303,7 @@ private boolean readExponent() {
301303
if (!readDigit()) {
302304
throw expected("digit");
303305
}
304-
while (readDigit()) {
305-
}
306+
while (readDigit()) {}
306307
return true;
307308
}
308309

@@ -389,14 +390,14 @@ private boolean isDigit() {
389390
}
390391

391392
private boolean isHexDigit() {
392-
return isDigit() || current >= 'a' && current <= 'f' || current >= 'A'
393-
&& current <= 'F';
393+
return isDigit()
394+
|| current >= 'a' && current <= 'f'
395+
|| current >= 'A' && current <= 'F';
394396
}
395397

396398
private boolean isEndOfText() {
397399
return current == -1;
398400
}
399-
400401
}
401402

402403
public static Object fromJson(String string) {

examples/src/main/java/com/github/underscore/examples/FromXml.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ public class FromXml {
3535
@SuppressWarnings("unchecked")
3636
private static Object getValue(final Object value) {
3737
if (value instanceof Map && ((Map<String, Object>) value).entrySet().size() == 1) {
38-
final Map.Entry<String, Object> entry = ((Map<String, Object>) value).entrySet().iterator().next();
38+
final Map.Entry<String, Object> entry =
39+
((Map<String, Object>) value).entrySet().iterator().next();
3940
if (entry.getKey().equals("#text") || entry.getKey().equals("element")) {
4041
return entry.getValue();
4142
}
@@ -78,9 +79,10 @@ private static Map<String, Object> createMap(final org.w3c.dom.Node node) {
7879

7980
public static Object fromXml(final String xml) {
8081
try {
81-
final java.io.InputStream stream = new java.io.ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8));
82+
final java.io.InputStream stream =
83+
new java.io.ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8));
8284
final javax.xml.parsers.DocumentBuilderFactory factory =
83-
javax.xml.parsers.DocumentBuilderFactory.newInstance();
85+
javax.xml.parsers.DocumentBuilderFactory.newInstance();
8486
factory.setNamespaceAware(true);
8587
final org.w3c.dom.Document document = factory.newDocumentBuilder().parse(stream);
8688
return createMap(document.getDocumentElement());

examples/src/main/java/com/github/underscore/examples/Intersection.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,12 @@ public static <E> List<E> intersection(final List<E> list1, final List<E> list2)
6363
return filter(list1, elem -> contains(list2, elem));
6464
}
6565

66-
/*
67-
_.intersection([1, 2, 3], [101, 2, 1, 10], [2, 1]);
68-
=> [1, 2]
69-
*/
66+
/*
67+
_.intersection([1, 2, 3], [101, 2, 1, 10], [2, 1]);
68+
=> [1, 2]
69+
*/
7070
@SuppressWarnings("unchecked")
71-
public static <E> List<E> intersection(final List<E> list, final List<E> ... lists) {
71+
public static <E> List<E> intersection(final List<E> list, final List<E>... lists) {
7272
final Stack<List<E>> stack = new Stack<>();
7373
stack.push(list);
7474
for (List<E> es : lists) {

examples/src/main/java/com/github/underscore/examples/Optional.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,11 @@ public static <T> Optional<T> of(final T arg) {
4545
}
4646

4747
public static <T> Optional<T> fromNullable(final T nullableReference) {
48-
return nullableReference == null ? Optional.<T>absent()
49-
: new Optional<>(nullableReference);
48+
return nullableReference == null ? Optional.<T>absent() : new Optional<>(nullableReference);
5049
}
5150

5251
@SuppressWarnings("unchecked")
53-
public static<T> Optional<T> absent() {
52+
public static <T> Optional<T> absent() {
5453
return (Optional<T>) EMPTY;
5554
}
5655

0 commit comments

Comments
 (0)