[JAVA] [Spring Boot] If you use Spring Boot, it was convenient to use a lot of util.

As I conclude in the title, if you are doing with Spring Boot, it was convenient to be able to use various util functions set in the ʻorg.springframework.util` package.

Here are two functions and implementations I've used.

List null / empty check

It's a null / empty check in the list that gives the impression that the implementation is slamming, but it's defined in ʻorg.springframework.util.CollectionUtils.isEmpty`.

/**
 * Return {@code true} if the supplied Collection is {@code null} or empty.
 * Otherwise, return {@code false}.
 * @param collection the Collection to check
 * @return whether the given Collection is empty
 */
public static boolean isEmpty(@Nullable Collection<?> collection) {
	return (collection == null || collection.isEmpty());
}

Get file extension

Even if I googled, it came out with the feeling that I should put Guava or implement it myself, but it was implemented.

/**
 * Extract the filename extension from the given Java resource path,
 * e.g. "mypath/myfile.txt" -> "txt".
 * @param path the file path (may be {@code null})
 * @return the extracted filename extension, or {@code null} if none
 */
@Nullable
public static String getFilenameExtension(@Nullable String path) {
	if (path == null) {
		return null;
	}

	int extIndex = path.lastIndexOf(EXTENSION_SEPARATOR);
	if (extIndex == -1) {
		return null;
	}

	int folderIndex = path.lastIndexOf(FOLDER_SEPARATOR);
	if (folderIndex > extIndex) {
		return null;
	}

	return path.substring(extIndex + 1);
}

Conclusion

It's not limited to Spring, but I thought it was important to "check if it was implemented in the util of the library that was already installed" before implementing it by yourself or considering the introduction of a new library. It's hard to tell what functions are implemented because of their low gurgability, but you can find individual functions unexpectedly by searching. I think that you should read the code at least once if you bring the implementation of the library, but it is better than the trouble of implementing and testing by yourself, and it will be a learning experience.

Later, I thought that the idea that I could easily find that area was great.

Recommended Posts

[Spring Boot] If you use Spring Boot, it was convenient to use a lot of util.
If you want to make a Java application a Docker image, it is convenient to use jib.
Volume that wants to use a lot of logical operators in if statements
A memorandum of addiction to Spring Boot2 x Doma2
How to use CommandLineRunner in Spring Batch of Spring Boot
Until you create a Spring Boot project in Intellij and push it to Github
How to use ModelMapper (Spring boot)
Spring Boot 2.0 Actuator, 3 changes you need to know to get it working
If you get tired of "Spring Boot", why not try "jooby"?
[Swift] If you want to use a URL that includes Japanese, use addingPercentEncoding.
How to make @Transactional work that does not work if you use it incorrectly
If you use Spring's DataSourceTransactionManager, it may be committed in case of error! ??
I tried to clone a web application full of bugs with Spring Boot
How to use MyBatis2 (iBatis) with Spring Boot 1.4 (Spring 4)
How to use built-in h2db with spring boot
You use context to use MDC with Spring WebFlux
How to use Spring Boot session attributes (@SessionAttributes)
The story of raising Spring Boot 1.5 series to 2.1 series
How to add a classpath in Spring Boot
[Swift] If the support of the application is iOS 11 or later, it was not necessary to use Int and Int64 properly
If you use SQLite with VSCode, use the extension (how to see the binary file of sqlite3)
What to do if you get a wrong number of arguments error in binding.pry
What I was addicted to when developing a Spring Boot application with VS Code
A memo that I was addicted to when making batch processing with Spring Boot
A site that was easy to understand when I was a beginner when I started learning Spring Boot
How to write a unit test for Spring Boot 2
05. I tried to stub the source of Spring Boot
How to create a Spring Boot project in IntelliJ
I tried to reduce the capacity of Spring Boot
[Spring Boot] How to create a project (for beginners)
What to do if you accidentally create a model
If you want to use Mockito with Kotlin, use mockito-kotlin
[Introduction to Spring Boot] Submit a form using thymeleaf
Program to determine if it is a leap year
How to boot by environment with Spring Boot of Maven
JAWJAW is convenient if you use WordNet from Java
A memo to check when you try to use Lombok
The story of raising Spring Boot from 1.5 series to 2.1 series part2
About the function of Spring Boot due to different versions
What I fixed when updating to Spring Boot 1.5.12 ・ What I was addicted to
Port C code with a lot of typecasts to Swift
A story packed with the basics of Spring Boot (solved)
Extract SQL to property file with jdbcTemplate of spring boot
Convenient use of Map that you do not know unexpectedly
How to call and use API in Java (Spring Boot)
Delegate is convenient to use when you want to reuse parts
Use @ControllerAdvice, @ExceptionHandler, HandlerExceptionResolver in Spring Boot to catch exceptions
What to do if you can't use the rails command
Rails was difficult, so I made something like a controller of Spring Framework to take a break
[Java] What to do if a lot of "File is opened too much" is displayed due to FileNotFoundException
If you want to mock a method in RSpec, you should use the allow method for mock and the singleton method.
A trick when you want to insert a lot of line breaks and tabs when substituting a character string
Create a Spring Boot web app that uses IBM Cloudant and deploy it to Cloud Foundry
I want to know the Method of the Controller where the Exception was thrown in the ExceptionHandler of Spring Boot