From cb4056e351c195e1790ece1d48992d29906cac92 Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Wed, 5 Jun 2013 22:13:00 +0200 Subject: [PATCH] DATAREST-94 - Removed dependency to Guava. Introduced simple Function interface. Replaced usage of Multimap with Spring's MultiValueMap. --- build.gradle | 3 -- .../data/rest/core/util/Function.java | 26 ++++++++++ .../data/rest/core/util/MapUtils.java | 51 +++++++++++++++++++ .../data/rest/core/util/UriUtils.java | 1 - .../rest/core/util/UriUtilsUnitTests.java | 1 - .../AnnotatedHandlerBeanPostProcessor.java | 9 ++-- .../ValidatingRepositoryEventListener.java | 16 +++--- ...RepositoryPropertyReferenceController.java | 2 +- 8 files changed, 91 insertions(+), 18 deletions(-) create mode 100644 spring-data-rest-core/src/main/java/org/springframework/data/rest/core/util/Function.java create mode 100644 spring-data-rest-core/src/main/java/org/springframework/data/rest/core/util/MapUtils.java diff --git a/build.gradle b/build.gradle index e5f26a6dd..5c2e1269d 100644 --- a/build.gradle +++ b/build.gradle @@ -21,7 +21,6 @@ ext { sdNeo4jVersion = "2.3.0.BUILD-SNAPSHOT" // Libraries - guavaVersion = "14.0.1" jacksonVersion = "2.1.2" jodaVersion = "2.1" hibernateVersion = "4.2.0.Final" @@ -128,8 +127,6 @@ project("spring-data-rest-core") { } dependencies { - // Google Guava - compile "com.google.guava:guava:$guavaVersion" // Spring compile("org.springframework:spring-aop:$springVersion") { force = true } diff --git a/spring-data-rest-core/src/main/java/org/springframework/data/rest/core/util/Function.java b/spring-data-rest-core/src/main/java/org/springframework/data/rest/core/util/Function.java new file mode 100644 index 000000000..c099b0ae2 --- /dev/null +++ b/spring-data-rest-core/src/main/java/org/springframework/data/rest/core/util/Function.java @@ -0,0 +1,26 @@ +/* + * Copyright 2013 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 org.springframework.data.rest.core.util; + +/** + * Simple function interface. + * + * @author Oliver Gierke + */ +public interface Function { + + T apply(S input); +} diff --git a/spring-data-rest-core/src/main/java/org/springframework/data/rest/core/util/MapUtils.java b/spring-data-rest-core/src/main/java/org/springframework/data/rest/core/util/MapUtils.java new file mode 100644 index 000000000..c5c33203a --- /dev/null +++ b/spring-data-rest-core/src/main/java/org/springframework/data/rest/core/util/MapUtils.java @@ -0,0 +1,51 @@ +/* + * Copyright 2013 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 org.springframework.data.rest.core.util; + +import java.util.Collection; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import org.springframework.util.Assert; +import org.springframework.util.MultiValueMap; + +/** + * Helper methods to work with {@link Map}s. + * + * @author Oliver Gierke + */ +public abstract class MapUtils { + + /** + * Turns a {@link MultiValueMap} into its {@link Map} equivalent. + * + * @param map must not be {@literal null}. + * @return + */ + public static Map> toMap(MultiValueMap map) { + + Assert.notNull(map, "Given map must not be null!"); + Map> result = new LinkedHashMap>(map.size()); + + for (Entry> entry : map.entrySet()) { + result.put(entry.getKey(), entry.getValue()); + } + + return result; + } +} diff --git a/spring-data-rest-core/src/main/java/org/springframework/data/rest/core/util/UriUtils.java b/spring-data-rest-core/src/main/java/org/springframework/data/rest/core/util/UriUtils.java index e07d32c90..4739be5d7 100644 --- a/spring-data-rest-core/src/main/java/org/springframework/data/rest/core/util/UriUtils.java +++ b/spring-data-rest-core/src/main/java/org/springframework/data/rest/core/util/UriUtils.java @@ -4,7 +4,6 @@ import java.net.URI; import java.util.List; import java.util.Stack; -import com.google.common.base.Function; import org.springframework.util.StringUtils; import org.springframework.web.util.UriComponentsBuilder; diff --git a/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/util/UriUtilsUnitTests.java b/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/util/UriUtilsUnitTests.java index 98c7d018e..2c9be61fb 100644 --- a/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/util/UriUtilsUnitTests.java +++ b/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/util/UriUtilsUnitTests.java @@ -8,7 +8,6 @@ import java.util.ArrayList; import java.util.List; import java.util.Stack; -import com.google.common.base.Function; import org.junit.Test; /** diff --git a/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/context/AnnotatedHandlerBeanPostProcessor.java b/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/context/AnnotatedHandlerBeanPostProcessor.java index db1a682f2..14027896e 100644 --- a/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/context/AnnotatedHandlerBeanPostProcessor.java +++ b/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/context/AnnotatedHandlerBeanPostProcessor.java @@ -6,8 +6,6 @@ import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; -import com.google.common.collect.ArrayListMultimap; -import com.google.common.collect.Multimap; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.BeansException; @@ -26,6 +24,8 @@ import org.springframework.data.rest.repository.annotation.HandleBeforeLinkSave; import org.springframework.data.rest.repository.annotation.HandleBeforeSave; import org.springframework.data.rest.repository.annotation.RepositoryEventHandler; import org.springframework.util.ClassUtils; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; import org.springframework.util.ReflectionUtils; /** @@ -36,8 +36,7 @@ public class AnnotatedHandlerBeanPostProcessor implements ApplicationListener, EventHandlerMethod> handlerMethods = ArrayListMultimap - .create(); + private final MultiValueMap, EventHandlerMethod> handlerMethods = new LinkedMultiValueMap, AnnotatedHandlerBeanPostProcessor.EventHandlerMethod>(); @Override public void onApplicationEvent(RepositoryEvent event) { Class eventType = event.getClass(); @@ -140,7 +139,7 @@ public class AnnotatedHandlerBeanPostProcessor implements ApplicationListener validators = ArrayListMultimap.create(); + private MultiValueMap validators = new LinkedMultiValueMap(); @Override public void afterPropertiesSet() throws Exception { if(validators.size() == 0) { @@ -81,7 +83,7 @@ public class ValidatingRepositoryEventListener } if(null != name) { - this.validators.put(name, v); + this.validators.add(name, v); } } } @@ -93,7 +95,7 @@ public class ValidatingRepositoryEventListener * @return Validators assigned to events. */ public Map> getValidators() { - return validators.asMap(); + return MapUtils.toMap(validators); } /** @@ -106,7 +108,7 @@ public class ValidatingRepositoryEventListener */ public ValidatingRepositoryEventListener setValidators(Map> validators) { for(Map.Entry> entry : validators.entrySet()) { - this.validators.replaceValues(entry.getKey(), entry.getValue()); + this.validators.put(entry.getKey(), new ArrayList(entry.getValue())); } return this; } @@ -122,7 +124,7 @@ public class ValidatingRepositoryEventListener * @return @this */ public ValidatingRepositoryEventListener addValidator(String event, Validator validator) { - validators.put(event, validator); + validators.add(event, validator); return this; } diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositoryPropertyReferenceController.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositoryPropertyReferenceController.java index cce8d03ab..e0de70d2b 100644 --- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositoryPropertyReferenceController.java +++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositoryPropertyReferenceController.java @@ -10,7 +10,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import com.google.common.base.Function; import org.springframework.core.convert.ConversionService; import org.springframework.core.convert.TypeDescriptor; import org.springframework.data.mapping.PersistentEntity; @@ -20,6 +19,7 @@ import org.springframework.data.repository.support.DomainClassConverter; import org.springframework.data.repository.support.Repositories; import org.springframework.data.rest.config.RepositoryRestConfiguration; import org.springframework.data.rest.config.ResourceMapping; +import org.springframework.data.rest.core.util.Function; import org.springframework.data.rest.repository.PersistentEntityResource; import org.springframework.data.rest.repository.context.AfterLinkDeleteEvent; import org.springframework.data.rest.repository.context.AfterLinkSaveEvent;