Skip to content

Commit

Permalink
Polishing
Browse files Browse the repository at this point in the history
  • Loading branch information
jhoeller committed May 14, 2024
1 parent e81c788 commit ee3e159
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 39 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2024 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.
Expand Down Expand Up @@ -124,10 +124,16 @@ public AspectMetadata(Class<?> aspectClass, String aspectName) {
* Extract contents from String of form {@code pertarget(contents)}.
*/
private String findPerClause(Class<?> aspectClass) {
String str = aspectClass.getAnnotation(Aspect.class).value();
int beginIndex = str.indexOf('(') + 1;
int endIndex = str.length() - 1;
return str.substring(beginIndex, endIndex);
Aspect ann = aspectClass.getAnnotation(Aspect.class);
if (ann == null) {
return "";
}
String value = ann.value();
int beginIndex = value.indexOf('(');
if (beginIndex < 0) {
return "";
}
return value.substring(beginIndex + 1, value.length() - 1);
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 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.
Expand Down Expand Up @@ -59,7 +59,7 @@ public MultiValueMapAdapter(Map<K, List<V>> targetMap) {
@Nullable
public V getFirst(K key) {
List<V> values = this.targetMap.get(key);
return (values != null && !values.isEmpty() ? values.get(0) : null);
return (!CollectionUtils.isEmpty(values) ? values.get(0) : null);
}

@Override
Expand Down Expand Up @@ -95,7 +95,7 @@ public void setAll(Map<K, V> values) {
public Map<K, V> toSingleValueMap() {
Map<K, V> singleValueMap = CollectionUtils.newLinkedHashMap(this.targetMap.size());
this.targetMap.forEach((key, values) -> {
if (values != null && !values.isEmpty()) {
if (!CollectionUtils.isEmpty(values)) {
singleValueMap.put(key, values.get(0));
}
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 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.
Expand Down Expand Up @@ -123,7 +123,7 @@ public static boolean isEmpty(@Nullable Object str) {
* @see #hasText(CharSequence)
*/
public static boolean hasLength(@Nullable CharSequence str) {
return (str != null && str.length() > 0);
return (str != null && !str.isEmpty()); // as of JDK 15
}

/**
Expand Down Expand Up @@ -791,6 +791,7 @@ public static boolean pathEquals(String path1, String path2) {
* and {@code "0"} through {@code "9"} stay the same.</li>
* <li>Special characters {@code "-"}, {@code "_"}, {@code "."}, and {@code "*"} stay the same.</li>
* <li>A sequence "{@code %<i>xy</i>}" is interpreted as a hexadecimal representation of the character.</li>
* <li>For all other characters (including those already decoded), the output is undefined.</li>
* </ul>
* @param source the encoded String
* @param charset the character set
Expand Down Expand Up @@ -839,7 +840,7 @@ public static String uriDecode(String source, Charset charset) {
* the {@link Locale#toString} format as well as BCP 47 language tags as
* specified by {@link Locale#forLanguageTag}.
* @param localeValue the locale value: following either {@code Locale's}
* {@code toString()} format ("en", "en_UK", etc), also accepting spaces as
* {@code toString()} format ("en", "en_UK", etc.), also accepting spaces as
* separators (as an alternative to underscores), or BCP 47 (e.g. "en-UK")
* @return a corresponding {@code Locale} instance, or {@code null} if none
* @throws IllegalArgumentException in case of an invalid locale specification
Expand Down Expand Up @@ -868,15 +869,15 @@ public static Locale parseLocale(String localeValue) {
* <p><b>Note: This delegate does not accept the BCP 47 language tag format.
* Please use {@link #parseLocale} for lenient parsing of both formats.</b>
* @param localeString the locale {@code String}: following {@code Locale's}
* {@code toString()} format ("en", "en_UK", etc), also accepting spaces as
* {@code toString()} format ("en", "en_UK", etc.), also accepting spaces as
* separators (as an alternative to underscores)
* @return a corresponding {@code Locale} instance, or {@code null} if none
* @throws IllegalArgumentException in case of an invalid locale specification
*/
@SuppressWarnings("deprecation") // for Locale constructors on JDK 19
@Nullable
public static Locale parseLocaleString(String localeString) {
if (localeString.equals("")) {
if (localeString.isEmpty()) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 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.
Expand Down Expand Up @@ -32,7 +32,7 @@
import org.springframework.util.CollectionUtils;

/**
* The default implementation of Spring's {@link SqlRowSet} interface, wrapping a
* The common implementation of Spring's {@link SqlRowSet} interface, wrapping a
* {@link java.sql.ResultSet}, catching any {@link SQLException SQLExceptions} and
* translating them to a corresponding Spring {@link InvalidResultSetAccessException}.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2024 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.
Expand Down Expand Up @@ -189,11 +189,6 @@ public void send(Message<?> message) {
}
}

@Override
public void convertAndSend(Object payload) throws MessagingException {
convertAndSend(payload, null);
}

@Override
public void convertAndSend(Object payload, @Nullable MessagePostProcessor postProcessor) throws MessagingException {
Destination defaultDestination = getDefaultDestination();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2024 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.
Expand Down Expand Up @@ -290,7 +290,7 @@ void convertAndSend(String destinationName, Object message, MessagePostProcessor
* <p>This method should be used carefully, since it will block the thread
* until the message becomes available or until the timeout value is exceeded.
* <p>This will only work with a default destination specified!
* @return the message produced for the consumer or {@code null} if the timeout expires.
* @return the message produced for the consumer, or {@code null} if the timeout expires
* @throws JmsException checked JMSException converted to unchecked
*/
@Nullable
Expand All @@ -303,7 +303,7 @@ void convertAndSend(String destinationName, Object message, MessagePostProcessor
* <p>This method should be used carefully, since it will block the thread
* until the message becomes available or until the timeout value is exceeded.
* @param destination the destination to receive a message from
* @return the message produced for the consumer or {@code null} if the timeout expires.
* @return the message produced for the consumer, or {@code null} if the timeout expires
* @throws JmsException checked JMSException converted to unchecked
*/
@Nullable
Expand All @@ -317,7 +317,7 @@ void convertAndSend(String destinationName, Object message, MessagePostProcessor
* until the message becomes available or until the timeout value is exceeded.
* @param destinationName the name of the destination to send this message to
* (to be resolved to an actual destination by a DestinationResolver)
* @return the message produced for the consumer or {@code null} if the timeout expires.
* @return the message produced for the consumer, or {@code null} if the timeout expires
* @throws JmsException checked JMSException converted to unchecked
*/
@Nullable
Expand All @@ -332,7 +332,7 @@ void convertAndSend(String destinationName, Object message, MessagePostProcessor
* <p>This will only work with a default destination specified!
* @param messageSelector the JMS message selector expression (or {@code null} if none).
* See the JMS specification for a detailed definition of selector expressions.
* @return the message produced for the consumer or {@code null} if the timeout expires.
* @return the message produced for the consumer, or {@code null} if the timeout expires
* @throws JmsException checked JMSException converted to unchecked
*/
@Nullable
Expand All @@ -347,7 +347,7 @@ void convertAndSend(String destinationName, Object message, MessagePostProcessor
* @param destination the destination to receive a message from
* @param messageSelector the JMS message selector expression (or {@code null} if none).
* See the JMS specification for a detailed definition of selector expressions.
* @return the message produced for the consumer or {@code null} if the timeout expires.
* @return the message produced for the consumer, or {@code null} if the timeout expires
* @throws JmsException checked JMSException converted to unchecked
*/
@Nullable
Expand All @@ -363,7 +363,7 @@ void convertAndSend(String destinationName, Object message, MessagePostProcessor
* (to be resolved to an actual destination by a DestinationResolver)
* @param messageSelector the JMS message selector expression (or {@code null} if none).
* See the JMS specification for a detailed definition of selector expressions.
* @return the message produced for the consumer or {@code null} if the timeout expires.
* @return the message produced for the consumer, or {@code null} if the timeout expires
* @throws JmsException checked JMSException converted to unchecked
*/
@Nullable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 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.
Expand Down Expand Up @@ -168,8 +168,7 @@ protected Message<?> doConvert(Object payload, @Nullable Map<String, Object> hea

Map<String, Object> headersToUse = processHeadersToSend(headers);
if (headersToUse != null) {
messageHeaders = (headersToUse instanceof MessageHeaders _messageHeaders ?
_messageHeaders : new MessageHeaders(headersToUse));
messageHeaders = (headersToUse instanceof MessageHeaders mh ? mh : new MessageHeaders(headersToUse));
}

MessageConverter converter = getMessageConverter();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 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.
Expand Down Expand Up @@ -277,7 +277,6 @@ public static <T> ResponseEntity<T> of(Optional<T> body) {
*/
public static HeadersBuilder<?> of(ProblemDetail body) {
return new DefaultBuilder(body.getStatus()) {

@SuppressWarnings("unchecked")
@Override
public <T> ResponseEntity<T> build() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 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.
Expand Down Expand Up @@ -124,7 +124,6 @@ public Mono<Void> setComplete() {
@Override
protected void applyHeaders() {
HttpHeaders headers = getHeaders();

headers.entrySet()
.stream()
.filter(entry -> !HttpHeaders.CONTENT_LENGTH.equals(entry.getKey()))
Expand All @@ -133,7 +132,6 @@ protected void applyHeaders() {
if (!this.httpRequest.containsHeader(HttpHeaders.ACCEPT)) {
this.httpRequest.addHeader(HttpHeaders.ACCEPT, MediaType.ALL_VALUE);
}

this.contentLength = headers.getContentLength();
}

Expand All @@ -144,7 +142,6 @@ protected void applyCookies() {
}

CookieStore cookieStore = this.context.getCookieStore();

getCookies().values()
.stream()
.flatMap(Collection::stream)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2024 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.
Expand Down Expand Up @@ -220,7 +220,7 @@ public final void saveOutputFlashMap(FlashMap flashMap, HttpServletRequest reque

@Nullable
private String decodeAndNormalizePath(@Nullable String path, HttpServletRequest request) {
if (path != null && !path.isEmpty()) {
if (StringUtils.hasLength(path)) {
path = getUrlPathHelper().decodeRequestString(request, path);
if (path.charAt(0) != '/') {
String requestUri = getUrlPathHelper().getRequestUri(request);
Expand Down

0 comments on commit ee3e159

Please sign in to comment.