Skip to content

Commit

Permalink
chore(common): Some name changes
Browse files Browse the repository at this point in the history
  • Loading branch information
phinner committed Mar 27, 2024
1 parent 86d036b commit 0794a38
Show file tree
Hide file tree
Showing 24 changed files with 153 additions and 155 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public ArcCommandManager(
this.registerDefaultExceptionHandlers();

this.captionRegistry().registerProvider((caption, sender) -> {
final var source = DistributorProvider.get().getLocalizationSource();
final var source = DistributorProvider.get().getLocalizationSourceManager();
final var locale = this.senderMapper().reverse(sender).getLocale();
final var format = source.localize(caption.key(), locale);
return format != null ? format.toPattern() : "???" + caption.key() + "???";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@
*/
package com.xpdustry.distributor.common;

import com.xpdustry.distributor.common.command.CommandFacade;
import com.xpdustry.distributor.common.localization.MultiLocalizationSource;
import com.xpdustry.distributor.common.command.CommandFacadeManager;
import com.xpdustry.distributor.common.localization.LocalizationSourceManager;
import com.xpdustry.distributor.common.permission.PermissionManager;
import com.xpdustry.distributor.common.service.ServiceManager;

public interface Distributor {

ServiceManager getServiceManager();

CommandFacade.Factory getCommandFacadeFactory();
CommandFacadeManager getCommandFacadeFactory();

PermissionManager getPermissionManager();

MultiLocalizationSource getLocalizationSource();
LocalizationSourceManager getLocalizationSourceManager();
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
*/
package com.xpdustry.distributor.common;

import com.xpdustry.distributor.common.command.CommandFacade;
import com.xpdustry.distributor.common.localization.MultiLocalizationSource;
import com.xpdustry.distributor.common.command.CommandFacadeManager;
import com.xpdustry.distributor.common.localization.LocalizationSourceManager;
import com.xpdustry.distributor.common.permission.PermissionManager;
import com.xpdustry.distributor.common.plugin.AbstractMindustryPlugin;
import com.xpdustry.distributor.common.service.ServiceManager;
Expand All @@ -29,9 +29,9 @@

public final class DistributorCommonPlugin extends AbstractMindustryPlugin implements Distributor {

private final ServiceManager services = ServiceManager.simple();
private final MultiLocalizationSource source = MultiLocalizationSource.create();
private CommandFacade.@Nullable Factory factory = null;
private final ServiceManager services = ServiceManager.create();
private final LocalizationSourceManager source = LocalizationSourceManager.create();
private @Nullable CommandFacadeManager factory = null;
private @Nullable PermissionManager permissions = null;

@Override
Expand All @@ -40,33 +40,33 @@ public ServiceManager getServiceManager() {
}

@Override
public CommandFacade.Factory getCommandFacadeFactory() {
return Objects.requireNonNull(this.factory, notInitialized("command-facade-factory"));
public CommandFacadeManager getCommandFacadeFactory() {
return ensureInitialized(this.factory, "command-facade-manager");
}

@Override
public PermissionManager getPermissionManager() {
return Objects.requireNonNull(permissions, notInitialized("permission"));
return ensureInitialized(this.permissions, "permission");
}

@Override
public MultiLocalizationSource getLocalizationSource() {
public LocalizationSourceManager getLocalizationSourceManager() {
return this.source;
}

@Override
public void onInit() {
DistributorProvider.set(this);
this.services.register(this, CommandFacade.Factory.class, Priority.LOW, CommandFacade.Factory::simple);
this.services.register(this, CommandFacadeManager.class, Priority.LOW, CommandFacadeManager::create);
}

@Override
public void onLoad() {
this.permissions = services.provide(PermissionManager.class);
this.factory = services.provide(CommandFacade.Factory.class);
this.factory = services.provide(CommandFacadeManager.class);
}

private String notInitialized(final String subsystem) {
return String.format("The \"%s\" subsystem is not initialized yet.", subsystem);
private <T> T ensureInitialized(final @Nullable T instance, final String name) {
return Objects.requireNonNull(instance, String.format("The \"%s\" subsystem is not initialized yet.", name));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
package com.xpdustry.distributor.common.command;

import com.xpdustry.distributor.common.internal.GeneratedDataClass;
import com.xpdustry.distributor.common.internal.DistributorDataClass;
import java.util.Collection;
import org.immutables.value.Value;

Expand All @@ -31,7 +31,7 @@ public sealed interface CommandElement {
Collection<String> getAliases();

@SuppressWarnings("immutables:subtype")
@GeneratedDataClass
@DistributorDataClass
@Value.Immutable
sealed interface Argument extends CommandElement permits ImmutableArgument {

Expand All @@ -53,7 +53,7 @@ enum Kind {
}

@SuppressWarnings("immutables:subtype")
@GeneratedDataClass
@DistributorDataClass
@Value.Immutable
sealed interface Flag extends CommandElement permits ImmutableFlag {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
package com.xpdustry.distributor.common.command;

import arc.util.CommandHandler;
import com.xpdustry.distributor.common.plugin.MindustryPlugin;
import org.jspecify.annotations.Nullable;

Expand All @@ -39,13 +38,4 @@ public interface CommandFacade {
CommandHelp getHelp(final CommandSender sender, final String query);

@Nullable MindustryPlugin getPlugin();

interface Factory {

static Factory simple() {
return SimpleCommandFacadeFactory.INSTANCE;
}

CommandFacade create(final CommandHandler.Command command);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Distributor, a feature-rich framework for Mindustry plugins.
*
* Copyright (C) 2024 Xpdustry
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.xpdustry.distributor.common.command;

import arc.util.CommandHandler;

public interface CommandFacadeManager {

static CommandFacadeManager create() {
return new CommandFacadeManagerImpl();
}

CommandFacade create(final CommandHandler.Command command);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@

import arc.util.CommandHandler;

final class SimpleCommandFacadeFactory implements CommandFacade.Factory {

static final SimpleCommandFacadeFactory INSTANCE = new SimpleCommandFacadeFactory();
final class CommandFacadeManagerImpl implements CommandFacadeManager {

@Override
public CommandFacade create(final CommandHandler.Command command) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
*/
package com.xpdustry.distributor.common.command;

import com.xpdustry.distributor.common.internal.GeneratedDataClass;
import com.xpdustry.distributor.common.internal.DistributorDataClass;
import java.util.List;
import org.immutables.value.Value;

public sealed interface CommandHelp {

@GeneratedDataClass
@DistributorDataClass
@Value.Immutable
sealed interface Entry extends CommandHelp permits ImmutableEntry {

Expand All @@ -45,7 +45,7 @@ static Entry of(
List<CommandElement.Flag> getFlags();
}

@GeneratedDataClass
@DistributorDataClass
@Value.Immutable
sealed interface Suggestion extends CommandHelp permits ImmutableSuggestion {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@
visibility = Value.Style.ImplementationVisibility.PACKAGE,
builderVisibility = Value.Style.BuilderVisibility.PACKAGE,
defaults = @Value.Immutable(copy = false, builder = false))
public @interface GeneratedDataClass {}
public @interface DistributorDataClass {}
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
/**
* A mutable localization source that delegates the localization lookup to other sources in FIFO order.
*/
public interface MultiLocalizationSource extends LocalizationSource {
public interface LocalizationSourceManager extends LocalizationSource {

/**
* Creates a new {@code MultiLocalizationSource} instance.
*/
static MultiLocalizationSource create() {
return new MultiLocalizationSourceImpl();
static LocalizationSourceManager create() {
return new LocalizationSourceManagerImpl();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import java.util.Locale;
import org.jspecify.annotations.Nullable;

final class MultiLocalizationSourceImpl implements MultiLocalizationSource {
final class LocalizationSourceManagerImpl implements LocalizationSourceManager {

private final Deque<LocalizationSource> sources = new ArrayDeque<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@

public interface PermissionTree {

static PermissionTree simple() {
return new SimplePermissionTree();
static PermissionTree create() {
return new PermissionTreeImpl();
}

static PermissionTree empty() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@
import java.util.Map;
import org.jspecify.annotations.Nullable;

final class SimplePermissionTree implements PermissionTree {
final class PermissionTreeImpl implements PermissionTree {

private final @Nullable SimplePermissionTree parent;
private final Map<String, SimplePermissionTree> children = new HashMap<>();
private final @Nullable PermissionTreeImpl parent;
private final Map<String, PermissionTreeImpl> children = new HashMap<>();
private TriState value = TriState.UNDEFINED;

SimplePermissionTree() {
PermissionTreeImpl() {
this.parent = null;
}

private SimplePermissionTree(final @Nullable SimplePermissionTree parent) {
private PermissionTreeImpl(final @Nullable PermissionTreeImpl parent) {
this.parent = parent;
}

Expand Down Expand Up @@ -68,7 +68,7 @@ public void setPermission(final String permission, final TriState state) {
if (state != TriState.UNDEFINED) {
for (final var part : parts) {
final var parent = node;
node = node.children.computeIfAbsent(part, k -> new SimplePermissionTree(parent));
node = node.children.computeIfAbsent(part, k -> new PermissionTreeImpl(parent));
}
node.value = state;
} else {
Expand Down Expand Up @@ -106,7 +106,7 @@ public boolean equals(final @Nullable Object o) {
if (this == o) {
return true;
}
if (!(o instanceof final SimplePermissionTree that)) {
if (!(o instanceof final PermissionTreeImpl that)) {
return false;
}
if (!this.children.equals(that.children)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.jspecify.annotations.Nullable;

/**
* Time units used by the {@link PluginTaskBuilder} and {@link PluginTask} classes to represent time.
* Time units used by the {@link PluginTask.Builder} and {@link PluginTask} classes to represent time.
*/
public enum MindustryTimeUnit {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
public interface PluginScheduler {

/**
* Returns a new {@link PluginTaskBuilder} instance scheduling a task.
* Returns a new {@link PluginTask.Builder} instance scheduling a task.
*
* @param plugin the plugin to schedule the task for.
* @return a new {@link PluginTaskBuilder} instance.
* @return a new {@link PluginTask.Builder} instance.
*/
PluginTaskBuilder schedule(final MindustryPlugin plugin);
PluginTask.Builder schedule(final MindustryPlugin plugin);
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ final class PluginSchedulerImpl implements PluginScheduler, PluginListener {
new PriorityBlockingQueue<>(16, Comparator.comparing(PluginTaskImpl::getNextExecutionTime));
private final ForkJoinPool pool;
private final Executor syncExecutor;
private final TimeSource source;
private final PluginTimeSource source;

public PluginSchedulerImpl(final TimeSource source, final Executor syncExecutor, final int parallelism) {
public PluginSchedulerImpl(final PluginTimeSource source, final Executor syncExecutor, final int parallelism) {
this.pool = new ForkJoinPool(parallelism, new PluginSchedulerWorkerThreadFactory(), null, false);
this.syncExecutor = syncExecutor;
this.source = source;
}

@Override
public PluginTaskBuilder schedule(final MindustryPlugin plugin) {
public PluginTask.Builder schedule(final MindustryPlugin plugin) {
return new PluginTaskImpl.Builder(this, plugin);
}

Expand Down Expand Up @@ -96,7 +96,7 @@ void schedule(final PluginTaskImpl<?> task) {
this.tasks.add(task);
}

TimeSource getTimeSource() {
PluginTimeSource getTimeSource() {
return this.source;
}

Expand Down
Loading

0 comments on commit 0794a38

Please sign in to comment.