From 7a92a11e8168c23b289f28edd2a4ec5e5c7c5c4d Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Tue, 22 Apr 2014 12:36:04 +0200 Subject: [PATCH] #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. --- java8/pom.xml | 30 +++++++++++++ java8/src/main/java/java/util/Optional.java | 47 +++++++++++++++++++++ pom.xml | 1 + 3 files changed, 78 insertions(+) create mode 100644 java8/pom.xml create mode 100644 java8/src/main/java/java/util/Optional.java diff --git a/java8/pom.xml b/java8/pom.xml new file mode 100644 index 00000000..37433fb4 --- /dev/null +++ b/java8/pom.xml @@ -0,0 +1,30 @@ + + + + 4.0.0 + spring-data-java8-stub + + + org.springframework.data.build + spring-data-build + 1.4.0.BUILD-SNAPSHOT + + + Spring Data Build - Java 8 Stubs + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.1 + + 1.6 + 1.6 + + + + + + diff --git a/java8/src/main/java/java/util/Optional.java b/java8/src/main/java/java/util/Optional.java new file mode 100644 index 00000000..087a3456 --- /dev/null +++ b/java8/src/main/java/java/util/Optional.java @@ -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 { + + private static final Optional EMPTY = new Optional(null); + + private final T value; + + private Optional(T value) { + this.value = value; + } + + public static Optional of(T value) { + return new Optional(value); + } + + public static Optional ofNullable(T value) { + return value == null ? Optional. empty() : of(value); + } + + @SuppressWarnings("unchecked") + public static Optional empty() { + Optional t = (Optional) EMPTY; + return t; + } +} diff --git a/pom.xml b/pom.xml index ac3c1198..96f26be8 100644 --- a/pom.xml +++ b/pom.xml @@ -18,6 +18,7 @@ resources + java8 parent bom