Skip to content

Commit

Permalink
Assorted tidying.
Browse files Browse the repository at this point in the history
  • Loading branch information
csmith committed Feb 20, 2016
1 parent 15f3b92 commit 18cb00a
Show file tree
Hide file tree
Showing 21 changed files with 53 additions and 66 deletions.
2 changes: 1 addition & 1 deletion src/com/dmdirc/Channel.java
Expand Up @@ -263,7 +263,7 @@ public void resetWindow() {
// Needs to be published synchronously so that nicklists are cleared before the parser
// is disconnected (which happens synchronously after this method returns).
getEventBus().publish(
new NickListClientsChangedEvent(this, Collections.<GroupChatUser>emptyList()));
new NickListClientsChangedEvent(this, Collections.emptyList()));
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions src/com/dmdirc/FrameContainer.java
Expand Up @@ -83,7 +83,7 @@ public class FrameContainer implements WindowModel {
/** The connection associated with this model. */
private Optional<Connection> connection = Optional.empty();
/** The ID for this window. */
@Nullable private String id = null;
@Nullable private String id;

/**
* Instantiate new frame container.
Expand Down Expand Up @@ -119,7 +119,7 @@ protected void initBackBuffer() {

@Override
public String getId() {
if (this.id == null) {
if (id == null) {
throw new IllegalStateException("ID has not been set");
}
return id;
Expand Down
2 changes: 1 addition & 1 deletion src/com/dmdirc/commandline/CommandLineParser.java
Expand Up @@ -388,7 +388,7 @@ private void doHelp() {
}

System.out.print(" -" + arg[0] + needsArg);
System.out.println(" --" + desc + needsArg + " " + arg[2]);
System.out.println(" --" + desc + needsArg + ' ' + arg[2]);
System.out.println();
}

Expand Down
2 changes: 1 addition & 1 deletion src/com/dmdirc/commandparser/CommandArguments.java
Expand Up @@ -194,7 +194,7 @@ public String getWordsAsString(final int start) {
public String getWordsAsString(final int start, final int end) {
checkPositionIndex(start, end);

final Pattern pattern = Pattern.compile("(\\S+\\s+){" + start + "}"
final Pattern pattern = Pattern.compile("(\\S+\\s+){" + start + '}'
+ "((\\S+\\s+){" + Math.max(0, end - start) + "}\\S+(\\s+$)?).*?");
final Matcher matcher = pattern.matcher(line);

Expand Down
2 changes: 1 addition & 1 deletion src/com/dmdirc/commandparser/commands/PreviousCommand.java
Expand Up @@ -61,7 +61,7 @@ public boolean equals(final Object obj) {
return false;
}
final PreviousCommand other = (PreviousCommand) obj;
return Objects.equals(this.line, other.line) && this.time == other.time;
return Objects.equals(line, other.line) && time == other.time;
}

}
4 changes: 2 additions & 2 deletions src/com/dmdirc/commandparser/commands/flags/CommandFlag.java
Expand Up @@ -98,7 +98,7 @@ public CommandFlag(final String name, final boolean enabled,
* @param enabled The flags which will be enabled
*/
public void addEnabled(final CommandFlag... enabled) {
this.enables.addAll(Arrays.asList(enabled));
enables.addAll(Arrays.asList(enabled));
}

/**
Expand All @@ -107,7 +107,7 @@ public void addEnabled(final CommandFlag... enabled) {
* @param disabled The flags which will be disabled
*/
public void addDisabled(final CommandFlag... disabled) {
this.disables.addAll(Arrays.asList(disabled));
disables.addAll(Arrays.asList(disabled));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/com/dmdirc/commandparser/commands/server/Umode.java
Expand Up @@ -70,7 +70,7 @@ public void execute(@Nonnull final WindowModel origin,

connection.getParser().get().sendRawMessage("MODE "
+ connection.getParser().get().getLocalClient().getNickname()
+ " " + args.getArgumentsAsString());
+ ' ' + args.getArgumentsAsString());
}

}
Expand Up @@ -23,7 +23,6 @@
package com.dmdirc.commandparser.parsers;

import com.dmdirc.DMDircMBassador;
import com.dmdirc.Query;
import com.dmdirc.commandparser.CommandArguments;
import com.dmdirc.commandparser.CommandInfo;
import com.dmdirc.commandparser.CommandType;
Expand Down
6 changes: 3 additions & 3 deletions src/com/dmdirc/config/ConfigFileBackedConfigProvider.java
Expand Up @@ -107,7 +107,7 @@ public ConfigFileBackedConfigProvider(final InputStream stream,
final boolean forceDefault) throws IOException, InvalidIdentityFileException {
this.identityManager = null;
this.file = new ConfigFile(stream);
this.file.setAutomake(true);
file.setAutomake(true);
initFile(forceDefault);
myTarget = getTarget(forceDefault);
}
Expand All @@ -123,7 +123,7 @@ public ConfigFileBackedConfigProvider(@Nullable final IdentityManager identityMa
final ConfigFile configFile, final ConfigTarget target) {
this.identityManager = identityManager;
this.file = configFile;
this.file.setAutomake(true);
file.setAutomake(true);
this.myTarget = target;
}

Expand Down Expand Up @@ -181,7 +181,7 @@ private ConfigTarget getTarget(final boolean forceDefault)
private void initFile(final boolean forceDefault)
throws InvalidIdentityFileException, IOException {
try {
this.file.read();
file.read();
} catch (InvalidConfigFileException ex) {
throw new InvalidIdentityFileException(ex);
}
Expand Down
6 changes: 3 additions & 3 deletions src/com/dmdirc/config/prefs/PreferencesSetting.java
Expand Up @@ -33,6 +33,7 @@
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
* Represents a single setting.
Expand Down Expand Up @@ -315,8 +316,7 @@ public boolean save() {
* Dismisses changes to this setting.
*/
public void dismiss() {
if (original != null && original.equals(value)
|| original == null && value == null) {
if (Objects.equals(original, value)) {
return;
}

Expand All @@ -333,7 +333,7 @@ public void dismiss() {
* @return true iif the setting will be changed if saved
*/
public boolean needsSaving() {
return (value == null || !value.equals(original))
return (!Objects.equals(value, original))
&& (value != null || original != null)
&& (validator == null || !validator.validate(value).isFailure());
}
Expand Down
1 change: 0 additions & 1 deletion src/com/dmdirc/interfaces/Connection.java
Expand Up @@ -32,7 +32,6 @@

import java.net.URI;
import java.util.Collection;
import java.util.Date;
import java.util.Optional;

import javax.annotation.Nonnull;
Expand Down
11 changes: 3 additions & 8 deletions src/com/dmdirc/ui/core/about/CoreAboutDialogModel.java
Expand Up @@ -22,13 +22,11 @@

package com.dmdirc.ui.core.about;

import com.dmdirc.ClientModule.GlobalConfig;
import com.dmdirc.DMDircMBassador;
import com.dmdirc.commandline.CommandLineOptionsModule;
import com.dmdirc.commandline.CommandLineOptionsModule.Directory;
import com.dmdirc.commandline.CommandLineOptionsModule.DirectoryType;
import com.dmdirc.commandline.CommandLineParser;
import com.dmdirc.events.ClientInfoRequestEvent;
import com.dmdirc.interfaces.config.AggregateConfigProvider;
import com.dmdirc.interfaces.ui.AboutDialogModel;
import com.dmdirc.plugins.PluginManager;
import com.dmdirc.util.ClientInfo;
Expand Down Expand Up @@ -56,24 +54,21 @@
public class CoreAboutDialogModel implements AboutDialogModel {

private static final Logger LOGGER = LoggerFactory.getLogger(CoreAboutDialogModel.class);
private final AggregateConfigProvider globalConfig;
private final Path baseDirectory;
private final ClientInfo clientInfo;
private final DMDircMBassador eventBus;
private final PluginManager pluginManager;
private final CommandLineParser commandLineParser;
private String about;
private List<Developer> mainDevelopers;
private List<Developer> otherDevelopers;
private List<InfoItem> info;
private List<LicensedComponent> licences;
private CommandLineParser commandLineParser;

@Inject
public CoreAboutDialogModel(@GlobalConfig final AggregateConfigProvider globalConfig,
@Directory(CommandLineOptionsModule.DirectoryType.BASE) final Path baseDirectory,
public CoreAboutDialogModel(@Directory(DirectoryType.BASE) final Path baseDirectory,
final ClientInfo clientInfo, final DMDircMBassador eventBus,
final PluginManager pluginManager, final CommandLineParser commandLineParser) {
this.globalConfig = globalConfig;
this.baseDirectory = baseDirectory;
this.clientInfo = clientInfo;
this.eventBus = eventBus;
Expand Down
4 changes: 2 additions & 2 deletions src/com/dmdirc/ui/core/aliases/CoreAliasDialogModel.java
Expand Up @@ -148,14 +148,14 @@ public void removeAlias(final String name) {
final Alias alias = aliases.get(name);
aliases.remove(name);
if (getSelectedAlias().isPresent() && getSelectedAlias().get().equals(alias)) {
setSelectedAlias(Optional.<Alias>empty());
setSelectedAlias(Optional.empty());
}
listeners.getCallable(AliasDialogModelListener.class).aliasRemoved(alias);
}

@Override
public void save() {
setSelectedAlias(Optional.<Alias>empty());
setSelectedAlias(Optional.empty());
aliasManager.getAliases().forEach(aliasManager::removeAlias);
aliases.values().forEach(aliasManager::addAlias);
}
Expand Down
14 changes: 7 additions & 7 deletions src/com/dmdirc/ui/messages/Formatter.java
Expand Up @@ -66,26 +66,26 @@ public static String formatMessage(final AggregateConfigProvider config,

final String res = config.hasOptionString("formatter", messageType)
? config.getOption("formatter", messageType).replace("%-1$", "%"
+ arguments.length + "$") : null;
+ arguments.length + '$') : null;

if (res == null) {
return "<No format string for message type " + messageType + ">";
return "<No format string for message type " + messageType + '>';
} else {
try {
final Object[] newArgs = castArguments(res, arguments);
return String.format(res.replaceAll("(%[0-9]+\\$)u", "$1s"), newArgs);
} catch (IllegalFormatConversionException ex) {
return "<Invalid format string for message type " + messageType
+ "; Error: Illegal format conversion: " + ex.getMessage() + ">";
+ "; Error: Illegal format conversion: " + ex.getMessage() + '>';
} catch (UnknownFormatConversionException ex) {
return "<Invalid format string for message type " + messageType
+ "; Error: Unknown format conversion: " + ex.getMessage() + ">";
+ "; Error: Unknown format conversion: " + ex.getMessage() + '>';
} catch (MissingFormatArgumentException ex) {
return "<Invalid format string for message type " + messageType
+ "; Error: Missing format argument: " + ex.getMessage() + ">";
+ "; Error: Missing format argument: " + ex.getMessage() + '>';
} catch (NumberFormatException ex) {
return "<Invalid format string for message type " + messageType
+ "; Error: Invalid number conversion: " + ex.getMessage() + ">";
+ "; Error: Invalid number conversion: " + ex.getMessage() + '>';
}
}
}
Expand Down Expand Up @@ -181,7 +181,7 @@ private static void analyseFormat(final String format, final Object[] args) {
final Character[] types = new Character[args.length];

for (int i = 0; i < args.length; i++) {
final int index = format.indexOf("%" + (i + 1) + "$");
final int index = format.indexOf("%" + (i + 1) + '$');

if (index > -1) {
types[i] = format.charAt(index + 3);
Expand Down
4 changes: 2 additions & 2 deletions src/com/dmdirc/ui/messages/IRCTextAttribute.java
Expand Up @@ -45,7 +45,7 @@ public final class IRCTextAttribute extends Attribute {
*/
protected IRCTextAttribute(final String name) {
super(name);
if (this.getClass() == IRCTextAttribute.class) {
if (getClass() == IRCTextAttribute.class) {
INSTANCE_MAP.put(name, this);
}
}
Expand All @@ -60,7 +60,7 @@ protected IRCTextAttribute(final String name) {
*/
@Override
protected Object readResolve() throws InvalidObjectException {
if (this.getClass() != IRCTextAttribute.class) {
if (getClass() != IRCTextAttribute.class) {
throw new InvalidObjectException("subclass didn't correctly implement readResolve");
}

Expand Down
12 changes: 6 additions & 6 deletions src/com/dmdirc/updater/Version.java
Expand Up @@ -74,16 +74,16 @@ public Version(final String version) {

@Override
public int compareTo(@Nonnull final Version o) {
if (o.intVersion > Integer.MIN_VALUE && this.intVersion > Integer.MIN_VALUE) {
return this.intVersion - o.intVersion;
} else if (o.strVersion == null && this.strVersion == null) {
if (o.intVersion > Integer.MIN_VALUE && intVersion > Integer.MIN_VALUE) {
return intVersion - o.intVersion;
} else if (o.strVersion == null && strVersion == null) {
return 0;
} else if (o.strVersion == null && this.strVersion != null) {
} else if (o.strVersion == null && strVersion != null) {
return 1;
} else if (o.strVersion != null && this.strVersion == null) {
} else if (o.strVersion != null && strVersion == null) {
return -1;
} else {
final String[] myParts = this.strVersion.split("-");
final String[] myParts = strVersion.split("-");
final String[] thParts = o.strVersion.split("-");

final String[] myFirstParts = myParts[0].split("\\.|(?=a|b|rc|m)");
Expand Down
11 changes: 4 additions & 7 deletions src/com/dmdirc/updater/manager/DMDircUpdateManager.java
Expand Up @@ -70,13 +70,10 @@ public DMDircUpdateManager(
new LinkedBlockingQueue<>(), new NamedThreadFactory()),
consolidator, updatePolicy);

checkStrategies.forEach(DMDircUpdateManager.this::addCheckStrategy);

retrievalStrategies.forEach(DMDircUpdateManager.this::addRetrievalStrategy);

installationStrategies.forEach(DMDircUpdateManager.this::addInstallationStrategy);

components.forEach(DMDircUpdateManager.this::addComponent);
checkStrategies.forEach(this::addCheckStrategy);
retrievalStrategies.forEach(this::addRetrievalStrategy);
installationStrategies.forEach(this::addInstallationStrategy);
components.forEach(this::addComponent);
}

/**
Expand Down
16 changes: 8 additions & 8 deletions src/com/dmdirc/updater/manager/UpdateManagerImpl.java
Expand Up @@ -97,46 +97,46 @@ protected UpdateComponentPolicy getPolicy() {
@Override
public void addCheckStrategy(final UpdateCheckStrategy strategy) {
LOG.trace("Adding new check strategy: {}", strategy);
this.checkers.add(strategy);
checkers.add(strategy);
}

@Override
public void addRetrievalStrategy(final UpdateRetrievalStrategy strategy) {
LOG.trace("Adding new retrieval strategy: {}", strategy);
strategy.addUpdateRetrievalListener(retrievalListener);
this.retrievers.add(strategy);
retrievers.add(strategy);
}

@Override
public void addInstallationStrategy(final UpdateInstallationStrategy strategy) {
LOG.trace("Adding new installation strategy: {}", strategy);
strategy.addUpdateInstallationListener(installationListener);
this.installers.add(strategy);
installers.add(strategy);
}

@Override
public void addComponent(final UpdateComponent component) {
LOG.trace("Adding new component: {}", component);
synchronized (componentsLock) {
this.components.put(component.getName(), component);
components.put(component.getName(), component);
}
}

@Override
public void removeComponent(final UpdateComponent component) {
LOG.trace("Removing component: {}", component);
synchronized (componentsLock) {
this.components.remove(component.getName());
components.remove(component.getName());
}

this.checkResults.remove(component);
this.retrievalResults.remove(component);
checkResults.remove(component);
retrievalResults.remove(component);
}

@Override
public Collection<UpdateComponent> getComponents() {
synchronized (componentsLock) {
return Collections.unmodifiableCollection(this.components.values());
return Collections.unmodifiableCollection(components.values());
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/com/dmdirc/util/resourcemanager/ResourceManager.java
Expand Up @@ -90,7 +90,7 @@ public static ResourceManager getResourceManager(final String url)
} else if (url.startsWith("jar://") || url.startsWith("zip://")) {
return new ZipResourceManager(url.substring(6));
} else {
throw new IllegalArgumentException("Unknown resource manager type (" + url + ")");
throw new IllegalArgumentException("Unknown resource manager type (" + url + ')');
}
}

Expand Down Expand Up @@ -134,7 +134,7 @@ public final boolean extractResource(final String resourceName,

if (usePath && resourceName.indexOf('/') > -1) {
newDir = new File(directory,
resourceName.substring(0, resourceName.lastIndexOf('/')) + "/");
resourceName.substring(0, resourceName.lastIndexOf('/')) + '/');
} else {
newDir = new File(directory);
}
Expand Down
4 changes: 2 additions & 2 deletions src/com/dmdirc/util/resourcemanager/ZipResourceManager.java
Expand Up @@ -146,8 +146,8 @@ public InputStream getResourceInputStream(final String resource) {
@Override
public URL getResourceURL(final String resource) throws MalformedURLException {
if (resourceExists(resource)) {
return new URL("jar:file:/" + zipFile.getName() + "!"
+ (resource.charAt(0) == '/' ? resource : "/" + resource));
return new URL("jar:file:/" + zipFile.getName() + '!'
+ (resource.charAt(0) == '/' ? resource : '/' + resource));
} else {
return null;
}
Expand Down

0 comments on commit 18cb00a

Please sign in to comment.