replaced google’s Preconditions.checkNotNull() with java.util.Objects.requireNonNull()

This commit is contained in:
Marc Baloup 2021-05-08 12:38:40 +02:00
parent 0f81fb82be
commit 0d7033d8c9
Signed by: marcbal
GPG Key ID: BBC0FE3ABC30B893
4 changed files with 35 additions and 33 deletions

View File

@ -1,5 +1,7 @@
package fr.pandacube.lib.core.permissions;
import java.util.Objects;
import com.google.common.base.Preconditions;
import fr.pandacube.lib.core.db.DB;
@ -10,9 +12,9 @@ import fr.pandacube.lib.core.permissions.SQLPermissions.EntityType;
/* package */ void addSelfPermission(String name, EntityType type, String permission, String server, String world) {
Preconditions.checkNotNull(name, "name cannot be null");
Preconditions.checkNotNull(type, "type cannot be null");
Preconditions.checkNotNull(permission, "permission cannot be null");
Objects.requireNonNull(name, "name cannot be null");
Objects.requireNonNull(type, "type cannot be null");
Objects.requireNonNull(permission, "permission cannot be null");
Preconditions.checkArgument(world == null || server != null, "world not null but server is null");
name = name.toLowerCase();
permission = permission.toLowerCase();
@ -25,9 +27,9 @@ import fr.pandacube.lib.core.permissions.SQLPermissions.EntityType;
}
/* package */ void removeSelfPermission(String name, EntityType type, String permission, String server, String world) {
Preconditions.checkNotNull(name, "name cannot be null");
Preconditions.checkNotNull(type, "type cannot be null");
Preconditions.checkNotNull(permission, "permission cannot be null");
Objects.requireNonNull(name, "name cannot be null");
Objects.requireNonNull(type, "type cannot be null");
Objects.requireNonNull(permission, "permission cannot be null");
Preconditions.checkArgument(world == null || server != null, "world not null but server is null");
name = name.toLowerCase();
permission = permission.toLowerCase();
@ -47,7 +49,7 @@ import fr.pandacube.lib.core.permissions.SQLPermissions.EntityType;
/* package */ void setGroupDefault(String name, boolean deflt) {
Preconditions.checkNotNull(name, "name cannot be null");
Objects.requireNonNull(name, "name cannot be null");
name = name.toLowerCase();
try {
SQLPermissions entry = DB.getFirst(SQLPermissions.class,
@ -85,8 +87,8 @@ import fr.pandacube.lib.core.permissions.SQLPermissions.EntityType;
/* package */ void setSelfPrefix(String name, EntityType type, String prefix) {
Preconditions.checkNotNull(name, "name cannot be null");
Preconditions.checkNotNull(type, "type cannot be null");
Objects.requireNonNull(name, "name cannot be null");
Objects.requireNonNull(type, "type cannot be null");
name = name.toLowerCase();
try {
@ -118,8 +120,8 @@ import fr.pandacube.lib.core.permissions.SQLPermissions.EntityType;
}
/* package */ void setSelfSuffix(String name, EntityType type, String suffix) {
Preconditions.checkNotNull(name, "name cannot be null");
Preconditions.checkNotNull(type, "type cannot be null");
Objects.requireNonNull(name, "name cannot be null");
Objects.requireNonNull(type, "type cannot be null");
name = name.toLowerCase();
try {
@ -155,9 +157,9 @@ import fr.pandacube.lib.core.permissions.SQLPermissions.EntityType;
/* package */ void addInheritance(String name, EntityType type, String inheritance) {
Preconditions.checkNotNull(name, "name cannot be null");
Preconditions.checkNotNull(type, "type cannot be null");
Preconditions.checkNotNull(inheritance, "inheritance cannot be null");
Objects.requireNonNull(name, "name cannot be null");
Objects.requireNonNull(type, "type cannot be null");
Objects.requireNonNull(inheritance, "inheritance cannot be null");
name = name.toLowerCase();
inheritance = inheritance.toLowerCase();
String key = type == EntityType.Group ? "inheritances" : "groups";
@ -179,9 +181,9 @@ import fr.pandacube.lib.core.permissions.SQLPermissions.EntityType;
}
/* package */ void removeInheritance(String name, EntityType type, String inheritance) {
Preconditions.checkNotNull(name, "name cannot be null");
Preconditions.checkNotNull(type, "type cannot be null");
Preconditions.checkNotNull(inheritance, "inheritance cannot be null");
Objects.requireNonNull(name, "name cannot be null");
Objects.requireNonNull(type, "type cannot be null");
Objects.requireNonNull(inheritance, "inheritance cannot be null");
name = name.toLowerCase();
inheritance = inheritance.toLowerCase();
String key = type == EntityType.Group ? "inheritances" : "groups";
@ -201,9 +203,9 @@ import fr.pandacube.lib.core.permissions.SQLPermissions.EntityType;
}
/* package */ void setInheritance(String name, EntityType type, String inheritance) {
Preconditions.checkNotNull(name, "name cannot be null");
Preconditions.checkNotNull(type, "type cannot be null");
Preconditions.checkNotNull(inheritance, "inheritance cannot be null");
Objects.requireNonNull(name, "name cannot be null");
Objects.requireNonNull(type, "type cannot be null");
Objects.requireNonNull(inheritance, "inheritance cannot be null");
name = name.toLowerCase();
inheritance = inheritance.toLowerCase();
String key = type == EntityType.Group ? "inheritances" : "groups";

View File

@ -80,8 +80,8 @@ public class PermissionsResolver {
.build();
private String getEffectiveData(String name, EntityType type, DataType dataType) {
Preconditions.checkNotNull(name, "name cant be null");
Preconditions.checkNotNull(type, "type cant be null");
Objects.requireNonNull(name, "name cant be null");
Objects.requireNonNull(type, "type cant be null");
try {
return effectiveDataCache.get(new DataCacheKey(name, type, dataType), () -> {
@ -239,8 +239,8 @@ public class PermissionsResolver {
.build();
/* package */ Map<String, Boolean> getEffectivePermissionList(String name, EntityType type, String server, String world) {
Preconditions.checkNotNull(name, "name cant be null");
Preconditions.checkNotNull(type, "type cant be null");
Objects.requireNonNull(name, "name cant be null");
Objects.requireNonNull(type, "type cant be null");
Preconditions.checkArgument(world == null || server != null, "world not null but server is null");
String fServer = server == null ? null : server.toLowerCase();
@ -271,9 +271,9 @@ public class PermissionsResolver {
.build();
/* package */ Boolean getEffectivePermission(String name, EntityType type, String permission, String server, String world) {
Preconditions.checkNotNull(name, "name cant be null");
Preconditions.checkNotNull(type, "type cant be null");
Preconditions.checkNotNull(permission, "permission cant be null");
Objects.requireNonNull(name, "name cant be null");
Objects.requireNonNull(type, "type cant be null");
Objects.requireNonNull(permission, "permission cant be null");
Preconditions.checkArgument(world == null || server != null, "world not null but server is null");
boolean reversed = false;

View File

@ -5,10 +5,10 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import com.google.common.base.Preconditions;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
@ -151,7 +151,7 @@ public abstract class IPlayerManager<OP extends IOnlinePlayer, OF extends IOffPl
* @throws IllegalArgumentException if message is null.
*/
public static void broadcast(BaseComponent message, boolean prefix, boolean console, String permission, UUID sourcePlayer) {
Preconditions.checkNotNull(message, "message cannot be null");
Objects.requireNonNull(message, "message cannot be null");
IOffPlayer oSourcePlayer = getInstance().getOffline(sourcePlayer);
@ -310,7 +310,7 @@ public abstract class IPlayerManager<OP extends IOnlinePlayer, OF extends IOffPl
* @throws IllegalArgumentException if message is null.
*/
public static void broadcast(Chat message, boolean prefix, boolean console, String permission, UUID sourcePlayer) {
Preconditions.checkNotNull(message, "message cannot be null");
Objects.requireNonNull(message, "message cannot be null");
broadcast(message.get(), prefix, console, permission, sourcePlayer);
}

View File

@ -5,12 +5,12 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;
import com.google.common.base.Preconditions;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
@ -48,7 +48,7 @@ public class SearchEngine<R extends SearchResult> {
Set<String> searchKw;
try {
searchKw = result.getSearchKeywords();
Preconditions.checkNotNull(searchKw, "SearchResult instance must provide a non null set of search keywords");
Objects.requireNonNull(searchKw, "SearchResult instance must provide a non null set of search keywords");
searchKw = searchKw.stream()
.filter(e -> e != null)
.map(String::toLowerCase)
@ -61,7 +61,7 @@ public class SearchEngine<R extends SearchResult> {
Set<String> suggestsKw;
try {
suggestsKw = result.getSuggestionKeywords();
Preconditions.checkNotNull(suggestsKw, "SearchResult instance must provide a non null set of suggestions keywords");
Objects.requireNonNull(suggestsKw, "SearchResult instance must provide a non null set of suggestions keywords");
suggestsKw = new HashSet<>(suggestsKw);
suggestsKw.removeIf(e -> e == null);
} catch (Exception e) {