#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.
This commit is contained in:
Oliver Gierke
2014-04-22 12:36:04 +02:00
parent facc762ba9
commit 7a92a11e81
3 changed files with 78 additions and 0 deletions

30
java8/pom.xml Normal file
View File

@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>spring-data-java8-stub</artifactId>
<parent>
<groupId>org.springframework.data.build</groupId>
<artifactId>spring-data-build</artifactId>
<version>1.4.0.BUILD-SNAPSHOT</version>
</parent>
<name>Spring Data Build - Java 8 Stubs</name>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@@ -0,0 +1,47 @@
/*
* Copyright 2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package java.util;
/**
* Stub implementation of JDK 8's {@link Optional}.
*
* @author Oliver Gierke
*/
@SuppressWarnings("unused")
public final class Optional<T> {
private static final Optional<?> EMPTY = new Optional<Object>(null);
private final T value;
private Optional(T value) {
this.value = value;
}
public static <T> Optional<T> of(T value) {
return new Optional<T>(value);
}
public static <T> Optional<T> ofNullable(T value) {
return value == null ? Optional.<T> empty() : of(value);
}
@SuppressWarnings("unchecked")
public static <T> Optional<T> empty() {
Optional<T> t = (Optional<T>) EMPTY;
return t;
}
}