Skip to content
This repository has been archived by the owner on Apr 4, 2022. It is now read-only.

Commit

Permalink
Reformat all code
Browse files Browse the repository at this point in the history
  • Loading branch information
spikespaz committed Mar 24, 2017
1 parent ebdfbc0 commit a41a027
Show file tree
Hide file tree
Showing 123 changed files with 4,243 additions and 4,327 deletions.
49 changes: 25 additions & 24 deletions src/main/java/fr/eyzox/bsc/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,29 @@

public class Config {

private final Map<String, ConfigOptionGroup> groups = new LinkedHashMap<String, ConfigOptionGroup>();

public Config() {}

public void addOptionGroup(final ConfigOptionGroup optionGroup) {
this.groups.put(optionGroup.getName(), optionGroup);
}

public void removeOptionGroup(final ConfigOptionGroup optionGroup) {
this.removeOptionGroup(optionGroup.getName());
}

public void removeOptionGroup(final String optionGroupeName) {
this.groups.remove(optionGroupeName);
}

public ConfigOptionGroup getOptionGroup(final String name) {
return groups.get(name);
}

public Collection<ConfigOptionGroup> getOptionGroups() {
return groups.values();
}

private final Map<String, ConfigOptionGroup> groups = new LinkedHashMap<String, ConfigOptionGroup>();

public Config() {
}

public void addOptionGroup(final ConfigOptionGroup optionGroup) {
this.groups.put(optionGroup.getName(), optionGroup);
}

public void removeOptionGroup(final ConfigOptionGroup optionGroup) {
this.removeOptionGroup(optionGroup.getName());
}

public void removeOptionGroup(final String optionGroupeName) {
this.groups.remove(optionGroupeName);
}

public ConfigOptionGroup getOptionGroup(final String name) {
return groups.get(name);
}

public Collection<ConfigOptionGroup> getOptionGroups() {
return groups.values();
}

}
66 changes: 33 additions & 33 deletions src/main/java/fr/eyzox/bsc/config/ConfigOptionGroup.java
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
package fr.eyzox.bsc.config;

import fr.eyzox.bsc.config.option.IConfigOption;

import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.Map;

import fr.eyzox.bsc.config.option.IConfigOption;

public class ConfigOptionGroup {

private final String name;
private final Map<String, IConfigOption> options = new LinkedHashMap<String, IConfigOption>();
public ConfigOptionGroup(final String name) {
this.name = name;
}
public String getName() {
return name;
}
public void addOption(final IConfigOption option) {
this.options.put(option.getName(), option);
}
public void removeOption(final String optionName) {
this.options.remove(optionName);
}
public void removeOption(final IConfigOption option) {
this.removeOption(option.getName());
}

public IConfigOption getOption(final String name) {
return options.get(name);
}
public Collection<IConfigOption> getOptions() {
return options.values();
}
private final String name;
private final Map<String, IConfigOption> options = new LinkedHashMap<String, IConfigOption>();

public ConfigOptionGroup(final String name) {
this.name = name;
}

public String getName() {
return name;
}

public void addOption(final IConfigOption option) {
this.options.put(option.getName(), option);
}

public void removeOption(final String optionName) {
this.options.remove(optionName);
}

public void removeOption(final IConfigOption option) {
this.removeOption(option.getName());
}

public IConfigOption getOption(final String name) {
return options.get(name);
}

public Collection<IConfigOption> getOptions() {
return options.values();
}

}
2 changes: 1 addition & 1 deletion src/main/java/fr/eyzox/bsc/config/IConfigListener.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package fr.eyzox.bsc.config;

public interface IConfigListener {
public void onChange(final Config config);
public void onChange(final Config config);
}
17 changes: 11 additions & 6 deletions src/main/java/fr/eyzox/bsc/config/IConfigProvider.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package fr.eyzox.bsc.config;

public interface IConfigProvider {
public Config getConfig();
public void addConfigListener(final IConfigListener listener);
public void removeConfigListener(final IConfigListener listener);
public void fireConfigChanged();
public void loadConfig();
public void unloadConfig();
public Config getConfig();

public void addConfigListener(final IConfigListener listener);

public void removeConfigListener(final IConfigListener listener);

public void fireConfigChanged();

public void loadConfig();

public void unloadConfig();
}
149 changes: 72 additions & 77 deletions src/main/java/fr/eyzox/bsc/config/loader/AbstractFileConfigLoader.java
Original file line number Diff line number Diff line change
@@ -1,86 +1,81 @@
package fr.eyzox.bsc.config.loader;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.file.AccessDeniedException;
import java.nio.file.NoSuchFileException;

import fr.eyzox.bsc.config.Config;
import fr.eyzox.bsc.exception.InvalidValueException;

import java.io.*;
import java.nio.file.AccessDeniedException;
import java.nio.file.NoSuchFileException;

public abstract class AbstractFileConfigLoader implements IConfigLoader {

private final File file;
private final IErrorManager errorManager = new FileErrorManager();
public AbstractFileConfigLoader(final File file) {
this.file = file;
}
@Override
public void load(Config config) throws NoSuchFileException, FileNotFoundException, AccessDeniedException, IOException, InvalidValueException{
if(!file.exists()) {
throw new NoSuchFileException(file.getAbsolutePath());
}
if(!file.isFile()) {
throw new FileNotFoundException(file.getAbsolutePath() + "is not a file");
}
if(!file.canRead()) {
throw new AccessDeniedException(file.getAbsolutePath() + "must allow reading");
}
errorManager.getErrors().clear();
}
@Override
public void save(Config config) throws FileNotFoundException, AccessDeniedException, IOException {
if(file.exists()) {
if(!file.isFile()) {
throw new FileNotFoundException(file.getAbsolutePath() + " is not a file");
}
if(!file.canWrite()) {
throw new AccessDeniedException(file.getAbsolutePath()+" must allow writing");
}
}else if(!file.getParentFile().canWrite()){
throw new AccessDeniedException(file.getParentFile().getAbsolutePath()+" must allow writing");
}
}
public File getFile() {
return file;
}
@Override
public IErrorManager getErrorManager() {
return errorManager;
}
protected class FileErrorManager extends ErrorManager {
@Override
public void output(PrintWriter out) throws IOException {
super.output(out);
out.println();
out.println("-------- ORIGINAL FILE --------");
out.println();
BufferedReader in = null;
try {
in = new BufferedReader(new FileReader(file));
String s = null;
while((s=in.readLine())!=null) {
out.println(s);
}
}finally {
if(in != null) {
in.close();
}
}
}
}
private final File file;
private final IErrorManager errorManager = new FileErrorManager();

public AbstractFileConfigLoader(final File file) {
this.file = file;
}

@Override
public void load(Config config) throws NoSuchFileException, FileNotFoundException, AccessDeniedException, IOException, InvalidValueException {
if (!file.exists()) {
throw new NoSuchFileException(file.getAbsolutePath());
}

if (!file.isFile()) {
throw new FileNotFoundException(file.getAbsolutePath() + "is not a file");
}

if (!file.canRead()) {
throw new AccessDeniedException(file.getAbsolutePath() + "must allow reading");
}
errorManager.getErrors().clear();
}

@Override
public void save(Config config) throws FileNotFoundException, AccessDeniedException, IOException {
if (file.exists()) {
if (!file.isFile()) {
throw new FileNotFoundException(file.getAbsolutePath() + " is not a file");
}

if (!file.canWrite()) {
throw new AccessDeniedException(file.getAbsolutePath() + " must allow writing");
}
} else if (!file.getParentFile().canWrite()) {
throw new AccessDeniedException(file.getParentFile().getAbsolutePath() + " must allow writing");
}
}

public File getFile() {
return file;
}

@Override
public IErrorManager getErrorManager() {
return errorManager;
}

protected class FileErrorManager extends ErrorManager {
@Override
public void output(PrintWriter out) throws IOException {
super.output(out);
out.println();
out.println("-------- ORIGINAL FILE --------");
out.println();
BufferedReader in = null;
try {
in = new BufferedReader(new FileReader(file));
String s = null;
while ((s = in.readLine()) != null) {
out.println(s);
}
} finally {
if (in != null) {
in.close();
}
}
}
}

}
57 changes: 29 additions & 28 deletions src/main/java/fr/eyzox/bsc/config/loader/ErrorManager.java
Original file line number Diff line number Diff line change
@@ -1,39 +1,40 @@
package fr.eyzox.bsc.config.loader;

import fr.eyzox.bsc.exception.ConfigException;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;

import fr.eyzox.bsc.exception.ConfigException;
public class ErrorManager implements IErrorManager {

private final List<ConfigException> errors = new LinkedList<ConfigException>();

public ErrorManager() {
}

@Override
public void error(ConfigException exception) {
errors.add(exception);
}

@Override
public boolean hasErrors() {
return !errors.isEmpty();
}

@Override
public void output(final PrintWriter out) throws IOException {
for (final ConfigException e : errors) {
out.println(e.getMessage());
}
}

public class ErrorManager implements IErrorManager{

private final List<ConfigException> errors = new LinkedList<ConfigException>();

public ErrorManager() {}

@Override
public void error(ConfigException exception) {
errors.add(exception);
}

@Override
public boolean hasErrors() {
return !errors.isEmpty();
}

@Override
public void output(final PrintWriter out) throws IOException{
for(final ConfigException e : errors) {
out.println(e.getMessage());
}
}

@Override
public Collection<ConfigException> getErrors() {
return errors;
}
@Override
public Collection<ConfigException> getErrors() {
return errors;
}

}
8 changes: 5 additions & 3 deletions src/main/java/fr/eyzox/bsc/config/loader/IConfigLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import fr.eyzox.bsc.config.Config;

public interface IConfigLoader {
public void load(final Config config) throws Exception;
public void save(final Config config) throws Exception;
public IErrorManager getErrorManager();
public void load(final Config config) throws Exception;

public void save(final Config config) throws Exception;

public IErrorManager getErrorManager();
}
Loading

0 comments on commit a41a027

Please sign in to comment.