Code style: move private constructors for singleton classes to the top of the file

This commit is contained in:
Luck 2019-03-05 12:36:09 +00:00
parent 3726f6de41
commit 0a50df6557
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
43 changed files with 53 additions and 82 deletions

View File

@ -42,6 +42,7 @@ import java.util.List;
* checks made by plugins.
*/
public final class PermissibleInjector {
private PermissibleInjector() {}
/**
* All permission checks made on standard Bukkit objects are effectively proxied to a
@ -151,6 +152,4 @@ public final class PermissibleInjector {
}
}
private PermissibleInjector() {}
}

View File

@ -33,6 +33,7 @@ import org.bukkit.Bukkit;
import java.util.UUID;
public final class BukkitUuids {
private BukkitUuids() {}
public static UUID lookupUuid(ProgressLogger log, String s) {
UUID uuid = Uuids.parse(s);
@ -50,6 +51,4 @@ public final class BukkitUuids {
return uuid;
}
private BukkitUuids() {}
}

View File

@ -31,6 +31,7 @@ import java.util.Optional;
import java.util.UUID;
public final class RedisBungeeUtil {
private RedisBungeeUtil() {}
/**
* Looks up a UUID from username via RedisBungee's uuid cache.
@ -46,6 +47,4 @@ public final class RedisBungeeUtil {
return Optional.ofNullable(RedisBungee.getApi()).map(a -> a.getNameFromUuid(uuid, true));
}
private RedisBungeeUtil() {}
}

View File

@ -35,6 +35,7 @@ import me.lucko.luckperms.api.LogEntry;
import java.util.UUID;
public final class LogEntryJsonSerializer {
private LogEntryJsonSerializer() {}
public static JsonObject serialize(LogEntry logEntry) {
JsonObject data = new JsonObject();
@ -68,5 +69,4 @@ public final class LogEntryJsonSerializer {
return builder.build();
}
private LogEntryJsonSerializer() {}
}

View File

@ -34,6 +34,7 @@ import me.lucko.luckperms.common.storage.misc.DataConstraints;
import java.util.function.Predicate;
public final class ApiUtils {
private ApiUtils() {}
public static String checkUsername(String s, LuckPermsPlugin plugin) {
if (s == null) {
@ -57,6 +58,4 @@ public final class ApiUtils {
return s.toLowerCase();
}
private ApiUtils() {}
}

View File

@ -47,6 +47,8 @@ import java.util.function.Function;
* Implements argument based permission checks for use in command implementations.
*/
public final class ArgumentPermissions {
private ArgumentPermissions() {}
private static final String USER_MODIFY_SELF = CommandPermission.ROOT + "modify.user.self";
private static final String USER_MODIFY_OTHERS = CommandPermission.ROOT + "modify.user.others";
private static final Function<String, String> GROUP_MODIFY = s -> CommandPermission.ROOT + "modify.group." + s;
@ -302,6 +304,4 @@ public final class ArgumentPermissions {
return !permissionData.getPermissionValue(NodeFactory.groupNode(targetGroupName), PermissionCheckEvent.Origin.INTERNAL).result().asBoolean();
}
private ArgumentPermissions() {}
}

View File

@ -38,6 +38,7 @@ import java.util.List;
import java.util.Map;
public final class MessageUtils {
private MessageUtils() {}
/**
* Sends a message to the sender, formatted with the plugin prefix and color scheme
@ -177,6 +178,4 @@ public final class MessageUtils {
return sb.delete(sb.length() - Message.CONTEXT_PAIR_SEP.asString(localeManager).length(), sb.length()).toString();
}
private MessageUtils() {}
}

View File

@ -41,6 +41,7 @@ import java.util.Optional;
* Utility methods for saving users, groups and tracks.
*/
public final class StorageAssistant {
private StorageAssistant() {}
public static Group loadGroup(String target, Sender sender, LuckPermsPlugin plugin, boolean auditTemporary) {
// special handling for the importer
@ -176,5 +177,4 @@ public final class StorageAssistant {
}
}
private StorageAssistant() {}
}

View File

@ -31,6 +31,7 @@ import me.lucko.luckperms.common.model.Group;
import me.lucko.luckperms.common.node.factory.NodeFactory;
public final class MigrationUtils {
private MigrationUtils() {}
public static Node.Builder parseNode(String permission, boolean value) {
if (permission.startsWith("-") || permission.startsWith("!")) {
@ -61,6 +62,4 @@ public final class MigrationUtils {
return string.trim().replace(':', '-').replace(' ', '-').replace('.', '-').toLowerCase();
}
private MigrationUtils() {}
}

View File

@ -70,6 +70,7 @@ import static me.lucko.luckperms.common.config.ConfigKeyTypes.stringKey;
* to function a bit like an enum, but with generics.</p>
*/
public final class ConfigKeys {
private ConfigKeys() {}
/**
* The name of the server
@ -593,6 +594,4 @@ public final class ConfigKeys {
return SIZE;
}
private ConfigKeys() {}
}

View File

@ -39,6 +39,7 @@ import java.util.List;
import java.util.Map;
public final class ContextSetConfigurateSerializer {
private ContextSetConfigurateSerializer() {}
public static ConfigurationNode serializeContextSet(ContextSet contextSet) {
ConfigurationNode data = SimpleConfigurationNode.root();
@ -84,6 +85,4 @@ public final class ContextSetConfigurateSerializer {
return map;
}
private ContextSetConfigurateSerializer() {}
}

View File

@ -42,6 +42,7 @@ import java.util.Map;
import java.util.Objects;
public final class ContextSetJsonSerializer {
private ContextSetJsonSerializer() {}
public static JsonObject serializeContextSet(ContextSet contextSet) {
JsonObject data = new JsonObject();
@ -104,6 +105,4 @@ public final class ContextSetJsonSerializer {
return map;
}
private ContextSetJsonSerializer() {}
}

View File

@ -57,6 +57,7 @@ import java.util.Set;
* @author Jens Nyman
*/
public final class GraphTraversers {
private GraphTraversers() {}
/**
* Returns an unmodifiable {@code Iterable} over the nodes reachable from
@ -210,6 +211,4 @@ public final class GraphTraversers {
POST_ORDER
}
private GraphTraversers() {}
}

View File

@ -44,6 +44,7 @@ import java.util.Objects;
* Contains the standard {@link MetaStackElement}s provided by LuckPerms.
*/
public final class StandardStackElements {
private StandardStackElements() {}
public static MetaStackElement parseFromString(LuckPermsPlugin plugin, String s) {
s = s.toLowerCase();
@ -317,6 +318,4 @@ public final class StandardStackElements {
}
}
private StandardStackElements() {}
}

View File

@ -36,6 +36,7 @@ import java.util.Optional;
* Utility class for creating instances of {@link DemotionResult}.
*/
public final class DemotionResults {
private DemotionResults() {}
public static DemotionResult success(String groupFrom, String groupTo) {
return new Impl(DemotionResult.Status.SUCCESS, groupFrom, groupTo);
@ -115,7 +116,4 @@ public final class DemotionResults {
}
}
private DemotionResults() {}
}

View File

@ -36,6 +36,7 @@ import java.util.Optional;
* Utility class for creating instances of {@link PromotionResult}.
*/
public final class PromotionResults {
private PromotionResults() {}
public static PromotionResult success(String groupFrom, String groupTo) {
return new Impl(PromotionResult.Status.SUCCESS, groupFrom, groupTo);
@ -115,7 +116,4 @@ public final class PromotionResults {
}
}
private PromotionResults() {}
}

View File

@ -34,6 +34,7 @@ import java.util.Comparator;
* Compares permission nodes based upon their supposed "priority".
*/
public class NodeWithContextComparator implements Comparator<Node> {
private NodeWithContextComparator() {}
private static final Comparator<? super Node> INSTANCE = new NodeWithContextComparator();
private static final Comparator<? super Node> REVERSE = INSTANCE.reversed();
@ -46,8 +47,6 @@ public class NodeWithContextComparator implements Comparator<Node> {
return REVERSE;
}
private NodeWithContextComparator() {}
@Override
public int compare(Node o1, Node o2) {
if (o1.equals(o2)) {

View File

@ -36,6 +36,7 @@ import java.util.Map;
import java.util.regex.Pattern;
public final class LegacyNodeFactory {
private LegacyNodeFactory() {}
/**
* The characters which are delimited when serializing a context set
@ -201,6 +202,4 @@ public final class LegacyNodeFactory {
}
}
private LegacyNodeFactory() {}
}

View File

@ -38,6 +38,8 @@ import java.util.Map;
* Utility class to make Node(Builder) instances from strings or existing Nodes
*/
public final class NodeFactory {
private NodeFactory() {}
public static final String DEFAULT_GROUP_NAME = "default";
public static Node.Builder builder(String s) {
@ -344,6 +346,4 @@ public final class NodeFactory {
return sb;
}
private NodeFactory() {}
}

View File

@ -52,6 +52,7 @@ import java.util.Optional;
import java.util.regex.Pattern;
public final class NodeTypes {
private NodeTypes() {}
public static final String PREFIX_KEY = "prefix";
public static final String SUFFIX_KEY = "suffix";
@ -509,6 +510,4 @@ public final class NodeTypes {
}
}
private NodeTypes() {}
}

View File

@ -37,6 +37,7 @@ import java.util.Set;
import java.util.function.Predicate;
public final class NodeTools {
private NodeTools() {}
public static <T extends Node> void removeEqual(Iterator<T> it, NodeEqualityPredicate equalityPredicate) {
List<T> alreadyIn = new ArrayList<>();
@ -78,5 +79,4 @@ public final class NodeTools {
return localizedNode -> delegate.test(localizedNode.getNode());
}
private NodeTools() {}
}

View File

@ -38,6 +38,8 @@ import java.util.stream.Collectors;
import java.util.stream.IntStream;
public final class ShorthandParser {
private ShorthandParser() {}
private static final List<Function<String, Iterable<String>>> PARSERS = ImmutableList.<Function<String, Iterable<String>>>builder()
.add(new ListParser())
.add(new CharacterRangeParser())
@ -169,6 +171,4 @@ public final class ShorthandParser {
}
}
private ShorthandParser() {}
}

View File

@ -29,6 +29,8 @@ package me.lucko.luckperms.common.storage.implementation.custom;
* Hook to allow external code to provide a storage dao
*/
public final class CustomStorageProviders {
private CustomStorageProviders() {}
private static CustomStorageProvider provider = null;
public static void register(CustomStorageProvider provider) {
@ -43,6 +45,4 @@ public final class CustomStorageProviders {
return provider;
}
private CustomStorageProviders() {}
}

View File

@ -29,6 +29,7 @@ import java.util.function.Predicate;
import java.util.regex.Pattern;
public final class DataConstraints {
private DataConstraints() {}
public static final int MAX_PERMISSION_LENGTH = 200;
@ -59,6 +60,4 @@ public final class DataConstraints {
public static final Predicate<String> WORLD_NAME_TEST = s -> !s.isEmpty() && s.length() <= MAX_WORLD_LENGTH;
private DataConstraints() {}
}

View File

@ -39,6 +39,8 @@ import java.util.stream.Stream;
* see: https://github.com/drtshock/Essentials/blob/2.x/Essentials/src/com/earth2me/essentials/utils/DateUtil.java
*/
public final class DateParser {
private DateParser() {}
private static final Pattern TIME_PATTERN = Pattern.compile(Stream.of("y", "mo", "w", "d", "h", "m").map(i -> "(?:([0-9]+)\\s*" + i + "[a-z]*[,\\s]*)?").collect(Collectors.joining()) + "(?:([0-9]+)\\s*(?:s[a-z]*)?)?", Pattern.CASE_INSENSITIVE);
private static final int MAX_YEARS = 100000;
@ -130,6 +132,4 @@ public final class DateParser {
return (c.getTimeInMillis() / 1000) + 1;
}
private DateParser() {}
}

View File

@ -26,7 +26,6 @@
package me.lucko.luckperms.common.util;
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import com.google.common.collect.ForwardingSet;
import org.checkerframework.checker.nullness.qual.NonNull;
@ -45,7 +44,7 @@ public class ExpiringSet<E> extends ForwardingSet<E> {
private final Set<E> setView;
public ExpiringSet(long duration, TimeUnit unit) {
this.cache = Caffeine.newBuilder().expireAfterAccess(duration, unit).build();
this.cache = CaffeineFactory.newBuilder().expireAfterAccess(duration, unit).build();
this.setView = this.cache.asMap().keySet();
}

View File

@ -37,6 +37,7 @@ import java.util.function.Function;
import java.util.stream.Collector;
public final class ImmutableCollectors {
private ImmutableCollectors() {}
private static final Collector<Object, ImmutableList.Builder<Object>, ImmutableList<Object>> LIST = Collector.of(
ImmutableList.Builder::new,
@ -98,6 +99,4 @@ public final class ImmutableCollectors {
);
}
private ImmutableCollectors() {}
}

View File

@ -32,6 +32,7 @@ import java.util.function.Consumer;
import java.util.function.Function;
public final class Iterators {
private Iterators() {}
public static <I> void iterate(Iterable<I> iterable, Consumer<I> action) {
for (I i : iterable) {
@ -86,6 +87,4 @@ public final class Iterators {
return lists;
}
private Iterators() {}
}

View File

@ -30,6 +30,7 @@ import java.nio.file.Files;
import java.nio.file.Path;
public final class MoreFiles {
private MoreFiles() {}
public static Path createFileIfNotExists(Path path) throws IOException {
if (!Files.exists(path)) {
@ -56,5 +57,4 @@ public final class MoreFiles {
return path;
}
private MoreFiles() {}
}

View File

@ -33,6 +33,7 @@ import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
public final class PatternCache {
private PatternCache() {}
private static final Map<String, CachedPattern> CACHE = LoadingMap.of(s -> {
try {
@ -92,6 +93,4 @@ public final class PatternCache {
}
}
private PatternCache() {}
}

View File

@ -33,6 +33,8 @@ import java.util.function.Predicate;
* A collection of predicate utilities used mostly in command classes
*/
public final class Predicates {
private Predicates() {}
private static final Predicate FALSE = new Predicate() {
@Override public boolean test(Object o) { return false; }
@Override public Predicate and(Predicate other) { return this; }
@ -74,5 +76,4 @@ public final class Predicates {
return t::equals;
}
private Predicates() {}
}

View File

@ -30,7 +30,6 @@ import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
public final class PrivateMethodHandles {
private PrivateMethodHandles() {}
private static final Constructor<MethodHandles.Lookup> LOOKUP_CONSTRUCTOR;

View File

@ -32,6 +32,8 @@ import javax.script.ScriptEngineManager;
* Provides a nashorn script engine (lazily)
*/
public final class Scripting {
private Scripting() {}
private static ScriptEngine engine = null;
// Lazily load
@ -42,6 +44,4 @@ public final class Scripting {
return engine;
}
private Scripting() {}
}

View File

@ -35,6 +35,7 @@ import java.util.stream.Stream;
@SuppressWarnings("deprecation")
public final class TextUtils {
private TextUtils() {}
public static String joinNewline(String... strings) {
return joinNewline(Arrays.stream(strings));
@ -68,6 +69,4 @@ public final class TextUtils {
return input;
}
private TextUtils() {}
}

View File

@ -34,6 +34,8 @@ import java.util.function.Predicate;
* Utilities for working with {@link UUID}s.
*/
public final class Uuids {
private Uuids() {}
public static final Predicate<String> PREDICATE = s -> parse(s) != null;
public static @Nullable UUID fromString(String s) {
@ -59,6 +61,4 @@ public final class Uuids {
return uuid;
}
private Uuids() {}
}

View File

@ -37,7 +37,6 @@ import java.io.IOException;
* Utilities for the OkHttp client
*/
public final class HttpClient {
private HttpClient() {}
private static final OkHttpClient CLIENT = new OkHttpClient.Builder()

View File

@ -63,6 +63,8 @@ import java.util.stream.Stream;
* Utility methods for interacting with the LuckPerms web permission editor.
*/
public final class WebEditor {
private WebEditor() {}
private static final String USER_ID_PATTERN = "user/";
private static final String GROUP_ID_PATTERN = "group/";
@ -235,6 +237,4 @@ public final class WebEditor {
return nodes;
}
private WebEditor() {}
}

View File

@ -41,6 +41,7 @@ import java.util.Set;
* checks made by plugins.
*/
public final class PermissibleInjector {
private PermissibleInjector() {}
/**
* All permission checks made on standard Nukkit objects are effectively proxied to a
@ -141,6 +142,4 @@ public final class PermissibleInjector {
}
}
private PermissibleInjector() {}
}

View File

@ -42,6 +42,8 @@ import java.util.Set;
* Utility class for converting between Sponge and LuckPerms context and tristate classes
*/
public final class CompatibilityUtil {
private CompatibilityUtil() {}
private static final Set<Context> EMPTY = ImmutableSet.of();
public static ImmutableContextSet convertContexts(Set<Context> contexts) {
@ -92,6 +94,4 @@ public final class CompatibilityUtil {
}
}
private CompatibilityUtil() {}
}

View File

@ -36,6 +36,7 @@ import java.util.List;
import java.util.Map;
public final class SpongeCommandUtils {
private SpongeCommandUtils() {}
public static Tristate parseTristate(int index, List<String> args) throws ArgumentParser.ArgumentException {
String s = args.get(index).toLowerCase();
@ -90,6 +91,4 @@ public final class SpongeCommandUtils {
return MessageUtils.contextSetToString(localeManager, set);
}
private SpongeCommandUtils() {}
}

View File

@ -42,6 +42,8 @@ import org.spongepowered.api.service.permission.SubjectData;
* Provides proxy instances which implement the SpongeAPI using the LuckPerms model.
*/
public final class ProxyFactory {
private ProxyFactory() {}
private static final boolean IS_API_7 = isApi7();
private static boolean isApi7() {
try {
@ -89,6 +91,4 @@ public final class ProxyFactory {
me.lucko.luckperms.sponge.service.proxy.api6.DescriptionBuilder.registerDescription(service, description);
}
private ProxyFactory() {}
}

View File

@ -31,8 +31,9 @@ import me.lucko.luckperms.sponge.service.model.calculated.CalculatedSubject;
import java.util.stream.Collectors;
public final class SubjectInheritanceGraphs {
private static final SubjectInheritanceGraph NON_CONTEXTUAL = new NonContextual();
private SubjectInheritanceGraphs() {}
private static final SubjectInheritanceGraph NON_CONTEXTUAL = new NonContextual();
public static SubjectInheritanceGraph getGraph() {
return NON_CONTEXTUAL;
@ -73,6 +74,4 @@ public final class SubjectInheritanceGraphs {
.collect(Collectors.toList());
}
}
private SubjectInheritanceGraphs() {}
}

View File

@ -33,6 +33,7 @@ import java.util.Objects;
* Utility class for converting between Velocity and LuckPerms tristate classes
*/
public final class CompatibilityUtil {
private CompatibilityUtil() {}
public static com.velocitypowered.api.permission.Tristate convertTristate(Tristate tristate) {
Objects.requireNonNull(tristate, "tristate");
@ -58,6 +59,4 @@ public final class CompatibilityUtil {
}
}
private CompatibilityUtil() {}
}