Skip to content

Commit

Permalink
Remove ConfigTarget from interfaces.
Browse files Browse the repository at this point in the history
This shouldn't be exposed. Internal classes switch to using
the full class rather than the interface, so they can carry
on accessing the removed methods.
  • Loading branch information
csmith committed Sep 10, 2016
1 parent a50a5ec commit 12b5c1d
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 54 deletions.
Expand Up @@ -271,7 +271,6 @@ public String getName() {
}
}

@Override
public boolean isProfile() {
return (hasOptionString(PROFILE_DOMAIN, "nicknames")
|| hasOptionString(PROFILE_DOMAIN, "nickname"))
Expand Down Expand Up @@ -474,7 +473,6 @@ public synchronized void delete() throws IOException {
identityManager.removeConfigProvider(this);
}

@Override
public ConfigTarget getTarget() {
return myTarget;
}
Expand Down Expand Up @@ -511,7 +509,7 @@ public int hashCode() {
public boolean equals(final Object obj) {
return obj instanceof ConfigFileBackedConfigProvider
&& getName().equals(((ConfigProvider) obj).getName())
&& getTarget() == ((ConfigProvider) obj).getTarget();
&& getTarget() == ((ConfigFileBackedConfigProvider) obj).getTarget();
}

}
14 changes: 7 additions & 7 deletions src/main/java/com/dmdirc/config/ConfigManager.java
Expand Up @@ -58,7 +58,7 @@ class ConfigManager implements ConfigChangeListener, ConfigProviderListener,
/** Magical domain to redirect to the version identity. */
private static final String VERSION_DOMAIN = "version";
/** A list of sources for this config manager. */
private final List<ConfigProvider> sources = new ArrayList<>();
private final List<ConfigFileBackedConfigProvider> sources = new ArrayList<>();
/** The listeners registered for this manager. */
private final Multimap<String, ConfigChangeListener> listeners = ArrayListMultimap.create();
/** The config binder to use for this manager. */
Expand Down Expand Up @@ -255,7 +255,7 @@ protected ConfigProvider getScope(final String domain, final String option) {
*
* @return True if the identity applies, false otherwise
*/
public boolean identityApplies(final ConfigProvider identity) {
public boolean identityApplies(final ConfigFileBackedConfigProvider identity) {
final String comp;

switch (identity.getTarget().getType()) {
Expand Down Expand Up @@ -315,7 +315,7 @@ protected boolean identityTargetMatches(final String actual, final String desire
*
* @param identity The identity to be checked
*/
public void checkIdentity(final ConfigProvider identity) {
public void checkIdentity(final ConfigFileBackedConfigProvider identity) {
if (!sources.contains(identity) && identityApplies(identity)) {
synchronized (sources) {
sources.add(identity);
Expand Down Expand Up @@ -382,8 +382,8 @@ void migrate(final String protocol, final String ircd,
removeIdentity(identity);
});

final List<ConfigProvider> newSources = manager.getIdentitiesForManager(this);
for (ConfigProvider identity : newSources) {
final List<ConfigFileBackedConfigProvider> newSources = manager.getIdentitiesForManager(this);
for (ConfigFileBackedConfigProvider identity : newSources) {
LOG.trace("Testing new identity: {}", identity);
checkIdentity(identity);
}
Expand Down Expand Up @@ -468,12 +468,12 @@ public void configChanged(final String domain, final String key) {
}

@Override
public void configProviderAdded(final ConfigProvider configProvider) {
public void configProviderAdded(final ConfigFileBackedConfigProvider configProvider) {
checkIdentity(configProvider);
}

@Override
public void configProviderRemoved(final ConfigProvider configProvider) {
public void configProviderRemoved(final ConfigFileBackedConfigProvider configProvider) {
removeIdentity(configProvider);
}

Expand Down
Expand Up @@ -32,10 +32,10 @@
* A collection sorted by this comparator will have the most specific (tightly scoped) providers
* first, and global (loosely scoped) last.
*/
public class ConfigProviderTargetComparator implements Comparator<ConfigProvider> {
public class ConfigProviderTargetComparator implements Comparator<ConfigFileBackedConfigProvider> {

@Override
public int compare(final ConfigProvider t, final ConfigProvider t1) {
public int compare(final ConfigFileBackedConfigProvider t, final ConfigFileBackedConfigProvider t1) {
return t1.getTarget().compareTo(t.getTarget());
}

Expand Down
36 changes: 18 additions & 18 deletions src/main/java/com/dmdirc/config/IdentityManager.java
Expand Up @@ -81,9 +81,9 @@ public class IdentityManager implements IdentityFactory, IdentityController {
* Standard identities are inserted with a {@code null} key, custom identities use their
* custom type as the key.
*/
private final Multimap<String, ConfigProvider> identities = ArrayListMultimap.create();
private final Multimap<String, ConfigFileBackedConfigProvider> identities = ArrayListMultimap.create();
/** Map of paths to corresponding config providers, to facilitate reloading. */
private final Map<Path, ConfigProvider> configProvidersByPath = new ConcurrentHashMap<>();
private final Map<Path, ConfigFileBackedConfigProvider> configProvidersByPath = new ConcurrentHashMap<>();
/**
* The {@link ConfigProviderListener}s that have registered with this manager.
*
Expand All @@ -95,11 +95,11 @@ public class IdentityManager implements IdentityFactory, IdentityController {
/** Client info objecty. */
private final ClientInfo clientInfo;
/** The identity file used for the global config. */
private ConfigProvider config;
private ConfigFileBackedConfigProvider config;
/** The identity file used for addon defaults. */
private ConfigProvider addonConfig;
private ConfigFileBackedConfigProvider addonConfig;
/** The identity file bundled with the client containing version info. */
private ConfigProvider versionConfig;
private ConfigFileBackedConfigProvider versionConfig;
/** The config manager used for global settings. */
private AggregateConfigProvider globalconfig;

Expand Down Expand Up @@ -251,7 +251,7 @@ private void loadIdentity(final Path file) {
}

try {
final ConfigProvider provider = new ConfigFileBackedConfigProvider(this, file, false);
final ConfigFileBackedConfigProvider provider = new ConfigFileBackedConfigProvider(this, file, false);
addConfigProvider(provider);
configProvidersByPath.put(file, provider);
} catch (InvalidIdentityFileException ex) {
Expand All @@ -268,7 +268,7 @@ private void loadIdentity(final Path file) {
*
* @since 0.6.4
*/
private Iterable<ConfigProvider> getAllIdentities() {
private Iterable<ConfigFileBackedConfigProvider> getAllIdentities() {
return identities.values();
}

Expand All @@ -282,7 +282,7 @@ private Iterable<ConfigProvider> getAllIdentities() {
*
* @since 0.6.4
*/
private String getGroup(final ConfigProvider identity) {
private String getGroup(final ConfigFileBackedConfigProvider identity) {
return identity.getTarget().getType() == ConfigTarget.TYPE.CUSTOM
? identity.getTarget().getData() : null;
}
Expand Down Expand Up @@ -345,7 +345,7 @@ public void saveAll() {
}

@Override
public void addConfigProvider(final ConfigProvider identity) {
public void addConfigProvider(final ConfigFileBackedConfigProvider identity) {
checkNotNull(identity);

final String target = getGroup(identity);
Expand All @@ -369,15 +369,15 @@ public void addConfigProvider(final ConfigProvider identity) {
}

@Override
public void removeConfigProvider(final ConfigProvider identity) {
public void removeConfigProvider(final ConfigFileBackedConfigProvider identity) {
checkNotNull(identity);

final String group = getGroup(identity);

checkArgument(identities.containsEntry(group, identity));

Path path = null;
for (Map.Entry<Path, ConfigProvider> entry : configProvidersByPath.entrySet()) {
for (Map.Entry<Path, ConfigFileBackedConfigProvider> entry : configProvidersByPath.entrySet()) {
if (entry.getValue() == identity) {
path = entry.getKey();
}
Expand Down Expand Up @@ -436,8 +436,8 @@ public Collection<ConfigProvider> getProvidersByType(final String type) {
*
* @return A list of all matching config sources
*/
List<ConfigProvider> getIdentitiesForManager(final ConfigManager manager) {
final List<ConfigProvider> sources = new ArrayList<>();
List<ConfigFileBackedConfigProvider> getIdentitiesForManager(final ConfigManager manager) {
final List<ConfigFileBackedConfigProvider> sources = new ArrayList<>();

synchronized (identities) {
sources.addAll(identities.get(null).stream()
Expand Down Expand Up @@ -476,7 +476,7 @@ public ConfigProvider createChannelConfig(final String network, final String cha
final String myTarget = (channel + '@' + network).toLowerCase();

synchronized (identities) {
for (ConfigProvider identity : identities.get(null)) {
for (ConfigFileBackedConfigProvider identity : identities.get(null)) {
if (identity.getTarget().getType() == ConfigTarget.TYPE.CHANNEL
&& identity.getTarget().getData().equalsIgnoreCase(myTarget)) {
return identity;
Expand All @@ -501,7 +501,7 @@ public ConfigProvider createNetworkConfig(final String network) {
final String myTarget = network.toLowerCase();

synchronized (identities) {
for (ConfigProvider identity : identities.get(null)) {
for (ConfigFileBackedConfigProvider identity : identities.get(null)) {
if (identity.getTarget().getType() == ConfigTarget.TYPE.NETWORK
&& identity.getTarget().getData().equalsIgnoreCase(myTarget)) {
return identity;
Expand All @@ -526,7 +526,7 @@ public ConfigProvider createServerConfig(final String server) {
final String myTarget = server.toLowerCase();

synchronized (identities) {
for (ConfigProvider identity : identities.get(null)) {
for (ConfigFileBackedConfigProvider identity : identities.get(null)) {
if (identity.getTarget().getType() == ConfigTarget.TYPE.SERVER
&& identity.getTarget().getData().equalsIgnoreCase(myTarget)) {
return identity;
Expand Down Expand Up @@ -643,9 +643,9 @@ protected ConfigFileBackedConfigProvider createIdentity(
* @param configManager The manager to be initialised.
*/
private void setUpConfigManager(final ConfigManager configManager) {
final List<ConfigProvider> sources = getIdentitiesForManager(configManager);
final List<ConfigFileBackedConfigProvider> sources = getIdentitiesForManager(configManager);

for (ConfigProvider identity : sources) {
for (ConfigFileBackedConfigProvider identity : sources) {
LOG.trace("Found {}", identity);
configManager.checkIdentity(identity);
}
Expand Down
16 changes: 0 additions & 16 deletions src/main/java/com/dmdirc/interfaces/config/ConfigProvider.java
Expand Up @@ -22,7 +22,6 @@

package com.dmdirc.interfaces.config;

import com.dmdirc.config.ConfigTarget;
import com.dmdirc.util.io.InvalidConfigFileException;

import java.io.IOException;
Expand Down Expand Up @@ -63,21 +62,6 @@ public interface ConfigProvider extends ReadOnlyConfigProvider {
*/
String getName();

/**
* Retrieves this identity's target.
*
* @return The target of this identity
*/
ConfigTarget getTarget();

/**
* Determines whether this identity can be used as a profile when connecting to a server.
* Profiles are identities that can supply nick, ident, real name, etc.
*
* @return True iff this identity can be used as a profile
*/
boolean isProfile();

/**
* Attempts to reload this identity from disk. If this identity has been modified (i.e.,
* {@code needSave} is true), then this method silently returns straight away. All relevant
Expand Down
Expand Up @@ -22,6 +22,8 @@

package com.dmdirc.interfaces.config;

import com.dmdirc.config.ConfigFileBackedConfigProvider;

/**
* An interface of objects which are interested in config providers being added and removed from the
* {@link IdentityController}.
Expand All @@ -36,14 +38,14 @@ public interface ConfigProviderListener {
*
* @param configProvider The configProvider which has been added
*/
void configProviderAdded(final ConfigProvider configProvider);
void configProviderAdded(final ConfigFileBackedConfigProvider configProvider);

/**
* Called whenever a relevant config provider is removed from the associated
* {@link IdentityController}.
*
* @param configProvider The configProvider which has been removed
*/
void configProviderRemoved(final ConfigProvider configProvider);
void configProviderRemoved(final ConfigFileBackedConfigProvider configProvider);

}
Expand Up @@ -22,6 +22,8 @@

package com.dmdirc.interfaces.config;

import com.dmdirc.config.ConfigFileBackedConfigProvider;

import java.util.Collection;

/**
Expand Down Expand Up @@ -85,7 +87,7 @@ public interface IdentityController {
*
* @param identity The identity to be added
*/
void addConfigProvider(ConfigProvider identity);
void addConfigProvider(final ConfigFileBackedConfigProvider identity);

/**
* Adds a new identity listener which will be informed of all settings identities which are
Expand Down Expand Up @@ -125,6 +127,6 @@ public interface IdentityController {
*
* @param identity The identity to be removed
*/
void removeConfigProvider(ConfigProvider identity);
void removeConfigProvider(final ConfigFileBackedConfigProvider identity);

}
4 changes: 2 additions & 2 deletions src/main/java/com/dmdirc/plugins/PluginInfo.java
Expand Up @@ -91,7 +91,7 @@ public class PluginInfo implements ServiceProvider {
/** Map of exports. */
private final Map<String, ExportInfo> exports = new HashMap<>();
/** List of configuration providers. */
private final Collection<ConfigProvider> configProviders = new ArrayList<>();
private final Collection<ConfigFileBackedConfigProvider> configProviders = new ArrayList<>();
/** Event bus to post plugin loaded events to. */
private final EventBus eventBus;
/** File system for the plugin's jar. */
Expand Down Expand Up @@ -264,7 +264,7 @@ private void loadIdentity(final Path path) {

try (final InputStream stream = Files.newInputStream(path)) {
synchronized (configProviders) {
final ConfigProvider configProvider =
final ConfigFileBackedConfigProvider configProvider =
new ConfigFileBackedConfigProvider(stream, false);
identityController.addConfigProvider(configProvider);
configProviders.add(configProvider);
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/com/dmdirc/config/IdentityManagerTest.java
Expand Up @@ -26,7 +26,6 @@
import com.dmdirc.tests.JimFsRule;
import com.dmdirc.util.ClientInfo;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collection;
Expand Down Expand Up @@ -63,7 +62,8 @@ public void testLoadsVersionIdentity() throws InvalidIdentityFileException {
baseDirectory, identitiesDirectory, clientInfo);
identityManager.initialise();

final ConfigProvider versionSettings = identityManager.getVersionSettings();
final ConfigFileBackedConfigProvider versionSettings =
(ConfigFileBackedConfigProvider) identityManager.getVersionSettings();
assertNotNull(versionSettings);
assertEquals(ConfigTarget.TYPE.GLOBALDEFAULT, versionSettings.getTarget().getType());
assertEquals("DMDirc version information", versionSettings.getName());
Expand Down

0 comments on commit 12b5c1d

Please sign in to comment.