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.
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());
}
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);
}
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