replaced google’s Preconditions.checkNotNull() with java.util.Objects.requireNonNull()
This commit is contained in:
parent
0f81fb82be
commit
0d7033d8c9
@ -1,5 +1,7 @@
|
|||||||
package fr.pandacube.lib.core.permissions;
|
package fr.pandacube.lib.core.permissions;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
|
|
||||||
import fr.pandacube.lib.core.db.DB;
|
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) {
|
/* package */ void addSelfPermission(String name, EntityType type, String permission, String server, String world) {
|
||||||
Preconditions.checkNotNull(name, "name cannot be null");
|
Objects.requireNonNull(name, "name cannot be null");
|
||||||
Preconditions.checkNotNull(type, "type cannot be null");
|
Objects.requireNonNull(type, "type cannot be null");
|
||||||
Preconditions.checkNotNull(permission, "permission cannot be null");
|
Objects.requireNonNull(permission, "permission cannot be null");
|
||||||
Preconditions.checkArgument(world == null || server != null, "world not null but server is null");
|
Preconditions.checkArgument(world == null || server != null, "world not null but server is null");
|
||||||
name = name.toLowerCase();
|
name = name.toLowerCase();
|
||||||
permission = permission.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) {
|
/* package */ void removeSelfPermission(String name, EntityType type, String permission, String server, String world) {
|
||||||
Preconditions.checkNotNull(name, "name cannot be null");
|
Objects.requireNonNull(name, "name cannot be null");
|
||||||
Preconditions.checkNotNull(type, "type cannot be null");
|
Objects.requireNonNull(type, "type cannot be null");
|
||||||
Preconditions.checkNotNull(permission, "permission cannot be null");
|
Objects.requireNonNull(permission, "permission cannot be null");
|
||||||
Preconditions.checkArgument(world == null || server != null, "world not null but server is null");
|
Preconditions.checkArgument(world == null || server != null, "world not null but server is null");
|
||||||
name = name.toLowerCase();
|
name = name.toLowerCase();
|
||||||
permission = permission.toLowerCase();
|
permission = permission.toLowerCase();
|
||||||
@ -47,7 +49,7 @@ import fr.pandacube.lib.core.permissions.SQLPermissions.EntityType;
|
|||||||
|
|
||||||
|
|
||||||
/* package */ void setGroupDefault(String name, boolean deflt) {
|
/* package */ void setGroupDefault(String name, boolean deflt) {
|
||||||
Preconditions.checkNotNull(name, "name cannot be null");
|
Objects.requireNonNull(name, "name cannot be null");
|
||||||
name = name.toLowerCase();
|
name = name.toLowerCase();
|
||||||
try {
|
try {
|
||||||
SQLPermissions entry = DB.getFirst(SQLPermissions.class,
|
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) {
|
/* package */ void setSelfPrefix(String name, EntityType type, String prefix) {
|
||||||
Preconditions.checkNotNull(name, "name cannot be null");
|
Objects.requireNonNull(name, "name cannot be null");
|
||||||
Preconditions.checkNotNull(type, "type cannot be null");
|
Objects.requireNonNull(type, "type cannot be null");
|
||||||
name = name.toLowerCase();
|
name = name.toLowerCase();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -118,8 +120,8 @@ import fr.pandacube.lib.core.permissions.SQLPermissions.EntityType;
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* package */ void setSelfSuffix(String name, EntityType type, String suffix) {
|
/* package */ void setSelfSuffix(String name, EntityType type, String suffix) {
|
||||||
Preconditions.checkNotNull(name, "name cannot be null");
|
Objects.requireNonNull(name, "name cannot be null");
|
||||||
Preconditions.checkNotNull(type, "type cannot be null");
|
Objects.requireNonNull(type, "type cannot be null");
|
||||||
name = name.toLowerCase();
|
name = name.toLowerCase();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -155,9 +157,9 @@ import fr.pandacube.lib.core.permissions.SQLPermissions.EntityType;
|
|||||||
|
|
||||||
|
|
||||||
/* package */ void addInheritance(String name, EntityType type, String inheritance) {
|
/* package */ void addInheritance(String name, EntityType type, String inheritance) {
|
||||||
Preconditions.checkNotNull(name, "name cannot be null");
|
Objects.requireNonNull(name, "name cannot be null");
|
||||||
Preconditions.checkNotNull(type, "type cannot be null");
|
Objects.requireNonNull(type, "type cannot be null");
|
||||||
Preconditions.checkNotNull(inheritance, "inheritance cannot be null");
|
Objects.requireNonNull(inheritance, "inheritance cannot be null");
|
||||||
name = name.toLowerCase();
|
name = name.toLowerCase();
|
||||||
inheritance = inheritance.toLowerCase();
|
inheritance = inheritance.toLowerCase();
|
||||||
String key = type == EntityType.Group ? "inheritances" : "groups";
|
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) {
|
/* package */ void removeInheritance(String name, EntityType type, String inheritance) {
|
||||||
Preconditions.checkNotNull(name, "name cannot be null");
|
Objects.requireNonNull(name, "name cannot be null");
|
||||||
Preconditions.checkNotNull(type, "type cannot be null");
|
Objects.requireNonNull(type, "type cannot be null");
|
||||||
Preconditions.checkNotNull(inheritance, "inheritance cannot be null");
|
Objects.requireNonNull(inheritance, "inheritance cannot be null");
|
||||||
name = name.toLowerCase();
|
name = name.toLowerCase();
|
||||||
inheritance = inheritance.toLowerCase();
|
inheritance = inheritance.toLowerCase();
|
||||||
String key = type == EntityType.Group ? "inheritances" : "groups";
|
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) {
|
/* package */ void setInheritance(String name, EntityType type, String inheritance) {
|
||||||
Preconditions.checkNotNull(name, "name cannot be null");
|
Objects.requireNonNull(name, "name cannot be null");
|
||||||
Preconditions.checkNotNull(type, "type cannot be null");
|
Objects.requireNonNull(type, "type cannot be null");
|
||||||
Preconditions.checkNotNull(inheritance, "inheritance cannot be null");
|
Objects.requireNonNull(inheritance, "inheritance cannot be null");
|
||||||
name = name.toLowerCase();
|
name = name.toLowerCase();
|
||||||
inheritance = inheritance.toLowerCase();
|
inheritance = inheritance.toLowerCase();
|
||||||
String key = type == EntityType.Group ? "inheritances" : "groups";
|
String key = type == EntityType.Group ? "inheritances" : "groups";
|
||||||
|
@ -80,8 +80,8 @@ public class PermissionsResolver {
|
|||||||
.build();
|
.build();
|
||||||
|
|
||||||
private String getEffectiveData(String name, EntityType type, DataType dataType) {
|
private String getEffectiveData(String name, EntityType type, DataType dataType) {
|
||||||
Preconditions.checkNotNull(name, "name can’t be null");
|
Objects.requireNonNull(name, "name can’t be null");
|
||||||
Preconditions.checkNotNull(type, "type can’t be null");
|
Objects.requireNonNull(type, "type can’t be null");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return effectiveDataCache.get(new DataCacheKey(name, type, dataType), () -> {
|
return effectiveDataCache.get(new DataCacheKey(name, type, dataType), () -> {
|
||||||
@ -239,8 +239,8 @@ public class PermissionsResolver {
|
|||||||
.build();
|
.build();
|
||||||
|
|
||||||
/* package */ Map<String, Boolean> getEffectivePermissionList(String name, EntityType type, String server, String world) {
|
/* package */ Map<String, Boolean> getEffectivePermissionList(String name, EntityType type, String server, String world) {
|
||||||
Preconditions.checkNotNull(name, "name can’t be null");
|
Objects.requireNonNull(name, "name can’t be null");
|
||||||
Preconditions.checkNotNull(type, "type can’t be null");
|
Objects.requireNonNull(type, "type can’t be null");
|
||||||
Preconditions.checkArgument(world == null || server != null, "world not null but server is null");
|
Preconditions.checkArgument(world == null || server != null, "world not null but server is null");
|
||||||
|
|
||||||
String fServer = server == null ? null : server.toLowerCase();
|
String fServer = server == null ? null : server.toLowerCase();
|
||||||
@ -271,9 +271,9 @@ public class PermissionsResolver {
|
|||||||
.build();
|
.build();
|
||||||
|
|
||||||
/* package */ Boolean getEffectivePermission(String name, EntityType type, String permission, String server, String world) {
|
/* package */ Boolean getEffectivePermission(String name, EntityType type, String permission, String server, String world) {
|
||||||
Preconditions.checkNotNull(name, "name can’t be null");
|
Objects.requireNonNull(name, "name can’t be null");
|
||||||
Preconditions.checkNotNull(type, "type can’t be null");
|
Objects.requireNonNull(type, "type can’t be null");
|
||||||
Preconditions.checkNotNull(permission, "permission can’t be null");
|
Objects.requireNonNull(permission, "permission can’t be null");
|
||||||
Preconditions.checkArgument(world == null || server != null, "world not null but server is null");
|
Preconditions.checkArgument(world == null || server != null, "world not null but server is null");
|
||||||
|
|
||||||
boolean reversed = false;
|
boolean reversed = false;
|
||||||
|
@ -5,10 +5,10 @@ import java.util.Collections;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
|
||||||
import com.google.common.cache.CacheBuilder;
|
import com.google.common.cache.CacheBuilder;
|
||||||
import com.google.common.cache.CacheLoader;
|
import com.google.common.cache.CacheLoader;
|
||||||
import com.google.common.cache.LoadingCache;
|
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.
|
* @throws IllegalArgumentException if message is null.
|
||||||
*/
|
*/
|
||||||
public static void broadcast(BaseComponent message, boolean prefix, boolean console, String permission, UUID sourcePlayer) {
|
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);
|
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.
|
* @throws IllegalArgumentException if message is null.
|
||||||
*/
|
*/
|
||||||
public static void broadcast(Chat message, boolean prefix, boolean console, String permission, UUID sourcePlayer) {
|
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);
|
broadcast(message.get(), prefix, console, permission, sourcePlayer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,12 +5,12 @@ import java.util.HashMap;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
|
||||||
import com.google.common.cache.Cache;
|
import com.google.common.cache.Cache;
|
||||||
import com.google.common.cache.CacheBuilder;
|
import com.google.common.cache.CacheBuilder;
|
||||||
|
|
||||||
@ -48,7 +48,7 @@ public class SearchEngine<R extends SearchResult> {
|
|||||||
Set<String> searchKw;
|
Set<String> searchKw;
|
||||||
try {
|
try {
|
||||||
searchKw = result.getSearchKeywords();
|
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()
|
searchKw = searchKw.stream()
|
||||||
.filter(e -> e != null)
|
.filter(e -> e != null)
|
||||||
.map(String::toLowerCase)
|
.map(String::toLowerCase)
|
||||||
@ -61,7 +61,7 @@ public class SearchEngine<R extends SearchResult> {
|
|||||||
Set<String> suggestsKw;
|
Set<String> suggestsKw;
|
||||||
try {
|
try {
|
||||||
suggestsKw = result.getSuggestionKeywords();
|
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 = new HashSet<>(suggestsKw);
|
||||||
suggestsKw.removeIf(e -> e == null);
|
suggestsKw.removeIf(e -> e == null);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
Loading…
Reference in New Issue
Block a user