Skip to content

Commit 7a92a11

Browse files
committed
#65 - Added stub module for JDK 8 types.
Added a build module to contain an abbreviated version of JDK 8's Optional to be able to add support for it as query method result in Spring Data Commons. Client modules should refer to it with a provided scope to make sure it's not leaking into the user's projects classpath.
1 parent facc762 commit 7a92a11

File tree

3 files changed

+78
-0
lines changed

3 files changed

+78
-0
lines changed

Diff for: java8/pom.xml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
5+
<modelVersion>4.0.0</modelVersion>
6+
<artifactId>spring-data-java8-stub</artifactId>
7+
8+
<parent>
9+
<groupId>org.springframework.data.build</groupId>
10+
<artifactId>spring-data-build</artifactId>
11+
<version>1.4.0.BUILD-SNAPSHOT</version>
12+
</parent>
13+
14+
<name>Spring Data Build - Java 8 Stubs</name>
15+
16+
<build>
17+
<plugins>
18+
<plugin>
19+
<groupId>org.apache.maven.plugins</groupId>
20+
<artifactId>maven-compiler-plugin</artifactId>
21+
<version>3.1</version>
22+
<configuration>
23+
<source>1.6</source>
24+
<target>1.6</target>
25+
</configuration>
26+
</plugin>
27+
</plugins>
28+
</build>
29+
30+
</project>

Diff for: java8/src/main/java/java/util/Optional.java

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright 2014 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package java.util;
17+
18+
/**
19+
* Stub implementation of JDK 8's {@link Optional}.
20+
*
21+
* @author Oliver Gierke
22+
*/
23+
@SuppressWarnings("unused")
24+
public final class Optional<T> {
25+
26+
private static final Optional<?> EMPTY = new Optional<Object>(null);
27+
28+
private final T value;
29+
30+
private Optional(T value) {
31+
this.value = value;
32+
}
33+
34+
public static <T> Optional<T> of(T value) {
35+
return new Optional<T>(value);
36+
}
37+
38+
public static <T> Optional<T> ofNullable(T value) {
39+
return value == null ? Optional.<T> empty() : of(value);
40+
}
41+
42+
@SuppressWarnings("unchecked")
43+
public static <T> Optional<T> empty() {
44+
Optional<T> t = (Optional<T>) EMPTY;
45+
return t;
46+
}
47+
}

Diff for: pom.xml

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
<modules>
2020
<module>resources</module>
21+
<module>java8</module>
2122
<module>parent</module>
2223
<module>bom</module>
2324
</modules>

0 commit comments

Comments
 (0)