Skip to content

Commit 8c4fd64

Browse files
committed
Sync with underscore-java.
1 parent e946377 commit 8c4fd64

22 files changed

+8099
-5647
lines changed

pom.xml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,9 @@
6666
<version>3.2.0</version>
6767
<configuration>
6868
<archive>
69-
<manifestEntries>
70-
<Automatic-Module-Name>com.github.underscore</Automatic-Module-Name>
71-
<mainClass>com.github.underscore.U</mainClass>
72-
</manifestEntries>
69+
<manifest>
70+
<mainClass>com.github.underscore.U</mainClass>
71+
</manifest>
7372
</archive>
7473
</configuration>
7574
</plugin>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
public abstract class MemoizeFunction<F, T> implements Function<F, T> {
88
private final Map<F, T> cache = new LinkedHashMap<>();
9+
910
public abstract T calc(final F n);
1011

1112
public T apply(final F key) {

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,17 @@ public static <T> Optional<T> of(final T arg) {
2525
}
2626

2727
public static <T> Optional<T> fromNullable(final T nullableReference) {
28-
return nullableReference == null ? Optional.<T>absent()
29-
: new Optional<>(nullableReference);
28+
return nullableReference == null ? Optional.<T>empty() : new Optional<>(nullableReference);
3029
}
3130

3231
@SuppressWarnings("unchecked")
33-
public static <T> Optional<T> absent() {
32+
public static <T> Optional<T> empty() {
3433
return (Optional<T>) EMPTY;
3534
}
3635

3736
public T get() {
3837
if (absent) {
39-
throw new IllegalStateException("Optional.get() cannot be called on an absent value");
38+
throw new IllegalStateException("Optional.get() cannot be called on an empty value");
4039
}
4140
return arg;
4241
}
@@ -67,7 +66,7 @@ public boolean isPresent() {
6766
public Optional<T> filter(Predicate<? super T> predicate) {
6867
U.checkNotNull(predicate);
6968
if (isPresent()) {
70-
return predicate.test(arg) ? this : Optional.<T>absent();
69+
return predicate.test(arg) ? this : Optional.<T>empty();
7170
} else {
7271
return this;
7372
}
@@ -78,7 +77,7 @@ public <F> Optional<F> map(Function<? super T, F> mapper) {
7877
if (isPresent()) {
7978
return Optional.fromNullable(mapper.apply(arg));
8079
} else {
81-
return absent();
80+
return empty();
8281
}
8382
}
8483

@@ -90,6 +89,10 @@ public <X extends Throwable> T orThrow(Supplier<? extends X> exceptionFunction)
9089
}
9190
}
9291

92+
public java.util.Optional<T> toJavaOptional() {
93+
return java.util.Optional.ofNullable(arg);
94+
}
95+
9396
@Override
9497
public boolean equals(final Object o) {
9598
if (this == o) {
@@ -113,6 +116,6 @@ public int hashCode() {
113116

114117
@Override
115118
public String toString() {
116-
return absent ? "Optional.absent()" : "Optional.of(" + arg + ")";
119+
return absent ? "Optional.empty" : "Optional[" + arg + "]";
117120
}
118121
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public static class TrieNode {
2828
// Initialize your data structure here.
2929
TrieNode[] children;
3030
boolean isWord;
31+
3132
public TrieNode() {
3233
children = new TrieNode[1071];
3334
}

0 commit comments

Comments
 (0)