Skip to content

Commit 7b03927

Browse files
committed
Merge pull request #96 from ProgrammingLife3/refactor/inspection
Refactor/inspection
2 parents c538af0 + e4eaa35 commit 7b03927

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+405
-522
lines changed

checkstyle.xml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Checkstyle configuration that checks the Google coding conventions (https://goog
1313
<property name="severity" value="warning"/>
1414
<property name="charset" value="UTF-8"/>
1515
<module name="TreeWalker">
16+
<property name="tabWidth" value="4"/>
1617
<module name="OuterTypeFilename"/>
1718
<module name="LineLength">
1819
<property name="ignorePattern" value="^package.*|^import.*|a href|href|http://|https://|ftp://"/>
@@ -99,10 +100,10 @@ Checkstyle configuration that checks the Google coding conventions (https://goog
99100
<message key="ws.illegalFollow" value="GenericWhitespace ''{0}'' should followed by whitespace."/>
100101
</module>
101102
<module name="Indentation">
102-
<property name="basicOffset" value="8"/>
103-
<property name="caseIndent" value="8"/>
103+
<property name="basicOffset" value="4"/>
104+
<property name="caseIndent" value="4"/>
104105
<property name="throwsIndent" value="1"/>
105-
<property name="arrayInitIndent" value="16"/>
106+
<property name="arrayInitIndent" value="8"/>
106107
<property name="lineWrappingIndentation" value="1"/>
107108
</module>
108109
<module name="AbbreviationAsWordInName">

src/main/java/tudelft/ti2806/pl3/Application.java

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
import tudelft.ti2806.pl3.controls.ScrollListener;
77
import tudelft.ti2806.pl3.controls.WindowController;
88
import tudelft.ti2806.pl3.data.graph.GraphDataRepository;
9-
import tudelft.ti2806.pl3.metafilter.MetaFilterController;
109
import tudelft.ti2806.pl3.exception.FileSelectorException;
1110
import tudelft.ti2806.pl3.findgenes.FindGenesController;
1211
import tudelft.ti2806.pl3.loading.LoadingMouse;
1312
import tudelft.ti2806.pl3.menubar.LastOpenedController;
1413
import tudelft.ti2806.pl3.menubar.MenuBarController;
14+
import tudelft.ti2806.pl3.metafilter.MetaFilterController;
1515
import tudelft.ti2806.pl3.sidebar.SideBarController;
1616
import tudelft.ti2806.pl3.sidebar.phylotree.PhyloController;
1717
import tudelft.ti2806.pl3.ui.util.DialogUtil;
@@ -44,7 +44,7 @@ public class Application extends JFrame implements ControllerContainer {
4444
/**
4545
* The value of the layers used in the view.
4646
*/
47-
private static final Integer MIDDEL_LAYER = 50;
47+
private static final Integer MIDDLE_LAYER = 50;
4848
private static final Integer HIGHEST_LAYER = 100;
4949

5050
private final GraphDataRepository graphDataRepository;
@@ -74,7 +74,7 @@ public Application() {
7474
LastOpenedStack<File> files = ParserLastOpened.readLastOpened();
7575
FileSelector.setLastOpened(files);
7676
} catch (IOException e) {
77-
// the file is missing so there are no lastopened
77+
// the file is missing so there are no last opened.
7878
FileSelector.setLastOpened(new LastOpenedStack<>(ParserLastOpened.limit));
7979
}
8080

@@ -138,16 +138,16 @@ private void setUpUi() {
138138
*/
139139
public void makeGraphFromFolder() {
140140
try {
141-
File folder = FileSelector.selectFolder("Select data folder", this);
142-
143-
File[] files = FileSelector.getFilesFromFolder(folder, ".node.graph", ".edge.graph", ".nwk", ".txt");
141+
File folder = FileSelector.selectFolder(Constants.DIALOG_SELECT_DATA_FOLDER, this);
142+
File[] files = FileSelector.getFilesFromFolder(folder, Constants.EXTENSION_NODE,
143+
Constants.EXTENSION_EDGE, Constants.EXTENSION_PHYLOTREE, Constants.EXTENSION_TEXT);
144144
makeGraph(files[0], files[1], files[2], files[3]);
145145
} catch (ArrayIndexOutOfBoundsException exception) {
146-
if (DialogUtil.confirm("Error!", "Some necessary files were not found. Want to select a new folder?")) {
146+
if (DialogUtil.confirm(Constants.DIALOG_TITLE_ERROR, "Some necessary files were not found. Want to select a new folder?")) {
147147
makeGraphFromFolder();
148148
}
149149
} catch (FileSelectorException exception) {
150-
if (DialogUtil.confirm("Error!", "You have not selected a folder, want to try again?")) {
150+
if (DialogUtil.confirm(Constants.DIALOG_TITLE_ERROR, "You have not selected a folder, want to try again?")) {
151151
makeGraphFromFolder();
152152
}
153153
}
@@ -158,19 +158,19 @@ public void makeGraphFromFolder() {
158158
*/
159159
public void makeGraphFromFiles() {
160160
try {
161-
File nodeFile = FileSelector.selectFile("Select node file", this, ".node.graph");
162-
163-
File edgeFile = FileSelector.getOtherExtension(nodeFile, ".node.graph", ".edge.graph");
161+
File nodeFile = FileSelector.selectFile(Constants.DIALOG_SELECT_NODE_FILE, this, Constants.EXTENSION_NODE);
162+
File edgeFile = FileSelector.getOtherExtension(nodeFile,
163+
Constants.EXTENSION_EDGE, Constants.EXTENSION_NODE);
164164
makeGraph(nodeFile, edgeFile, null, null);
165165
} catch (FileSelectorException exception) {
166-
if (DialogUtil.confirm("Error!", "Your file was not found. Want to try again?")) {
166+
if (DialogUtil.confirm(Constants.DIALOG_TITLE_ERROR, Constants.DIALOG_FILE_NOT_FOUND)) {
167167
makeGraphFromFiles();
168168
}
169169
}
170170
}
171171

172172
/**
173-
* Parses the graph files and makes a graphview.
173+
* Parses the graph files and makes a GraphView.
174174
*/
175175
public void makeGraph(File nodeFile, File edgeFile, File treeFile, File metaFile) {
176176
try {
@@ -180,7 +180,7 @@ public void makeGraph(File nodeFile, File edgeFile, File treeFile, File metaFile
180180
makePhyloTree(treeFile);
181181
}
182182
} catch (FileNotFoundException exception) {
183-
if (DialogUtil.confirm("Error!", "Your file was not found. Want to try again?")) {
183+
if (DialogUtil.confirm(Constants.DIALOG_TITLE_ERROR, Constants.DIALOG_FILE_NOT_FOUND)) {
184184
makeGraph(nodeFile, edgeFile, treeFile, metaFile);
185185
}
186186
}
@@ -200,19 +200,20 @@ public void makePhyloTree(File input) {
200200
try {
201201
File treeFile;
202202
if (input == null) {
203-
treeFile = FileSelector.selectFile("Select phylogenetic tree file", this, ".nwk");
203+
treeFile = FileSelector.selectFile(Constants.DIALOG_SELECT_PHYLOTREE_FILE, this,
204+
Constants.EXTENSION_PHYLOTREE);
204205
} else {
205206
treeFile = input;
206207
}
207208

208209
getSideBarController().getPhyloController().parseTree(treeFile);
209210

210211
} catch (FileSelectorException exception) {
211-
if (DialogUtil.confirm("Error!", "Your file was not found. Want to try again?")) {
212+
if (DialogUtil.confirm(Constants.DIALOG_TITLE_ERROR, Constants.DIALOG_FILE_NOT_FOUND)) {
212213
makePhyloTree();
213214
}
214215
} catch (ParseException exception) {
215-
if (DialogUtil.confirm("Error!", "Your file was not formatted correctly. Want to try again?")) {
216+
if (DialogUtil.confirm(Constants.DIALOG_TITLE_ERROR, Constants.DIALOG_FILE_FORMATTED_INCORRECTLY)) {
216217
makePhyloTree();
217218
}
218219
}
@@ -238,11 +239,11 @@ public void loadMetaData() {
238239
@SuppressFBWarnings({"DM_EXIT"})
239240
public void stop() {
240241
// save data or do something else here
241-
if (DialogUtil.confirm("Exit", "Are you sure you want to exit the application? ")) {
242+
if (DialogUtil.confirm(Constants.DIALOG_TITLE_EXIT, Constants.DIALOG_EXIT)) {
242243
try {
243244
ParserLastOpened.saveLastOpened(FileSelector.getLastopened());
244245
} catch (IOException | InterruptedException e) {
245-
System.out.println("Unable to save the files");
246+
DialogUtil.displayError(Constants.DIALOG_TITLE_ERROR, Constants.DIALOG_FAIL_SAVE_FILES);
246247
e.printStackTrace();
247248
}
248249
this.dispose();
@@ -281,7 +282,7 @@ private void setGraphView() {
281282
Component view = getGraphController().getPanel();
282283
view.setBounds(0, 0, size.getWidth(),
283284
size.getHeight() - size.getZoomBarHeight());
284-
main.add(view, MIDDEL_LAYER);
285+
main.add(view, MIDDLE_LAYER);
285286
view.setVisible(true);
286287
view.addKeyListener(keys);
287288
view.addMouseWheelListener(new ScrollListener(this));
@@ -294,7 +295,7 @@ private void setZoomBarView() {
294295
Component view = getZoomBarController().getPanel();
295296
view.setBounds(0, size.getHeight() - size.getZoomBarHeight(),
296297
size.getWidth(), size.getZoomBarHeight());
297-
main.add(view, MIDDEL_LAYER);
298+
main.add(view, MIDDLE_LAYER);
298299
view.setVisible(true);
299300
}
300301

src/main/java/tudelft/ti2806/pl3/Constants.java

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
*/
77
public class Constants {
88
// Special chars
9-
public static final char POWER = '\u00B2';
9+
public static final char POWER = '\u00B2'; // Power of 2 character (^2).
1010
public static final char PLUS = '+';
1111
public static final char MINUS = '-';
12-
public static final char ARROW_RIGHT = '\u2192';
13-
public static final char ARROW_LEFT = '\u2190';
12+
public static final char ARROW_RIGHT = '\u2192'; // Arrow to the right character.
13+
public static final char ARROW_LEFT = '\u2190'; // Arrow to the left character.
1414
public static final String SPACE = "Space";
1515

1616
// Name of the application.
@@ -73,13 +73,33 @@ public class Constants {
7373
public static final String MENU_HELP_CONTROLS = "Controls";
7474
public static final String MENU_HELP_ABOUT = "About " + APP_NAME;
7575

76-
public static final String DIALOG_ERROR = "Error!";
76+
public static final String DIALOG_TITLE_ERROR = "Error!";
77+
public static final String DIALOG_TITLE_EXIT = "Exit";
78+
public static final String DIALOG_FILE_NOT_FOUND = "Your file was not found. Want to try again?";
79+
public static final String DIALOG_FILE_FORMATTED_INCORRECTLY = "Your file was not formatted correctly. "
80+
+ "Want to try again?";
81+
public static final String DIALOG_EXIT = "Are you sure you want to exit the application? ";
82+
public static final String DIALOG_SELECT_PHYLOTREE_FILE = "Select phylogenetic tree file";
83+
public static final String DIALOG_SELECT_NODE_FILE = "Select node file";
84+
public static final String DIALOG_SELECT_DATA_FOLDER = "Select data folder";
85+
public static final String DIALOG_FAIL_SAVE_FILES = "Unable to save the last opened files";
86+
7787
public static final String DETAILVIEW_GENOMES = "Genomes:";
7888
public static final String DETAILVIEW_LABELS = "Labels:";
7989

90+
public static final String EXTENSION_GRAPH = ".graph";
91+
public static final String EXTENSION_NODE = ".node" + EXTENSION_GRAPH;
92+
public static final String EXTENSION_EDGE = ".edge" + EXTENSION_GRAPH;
93+
public static final String EXTENSION_PHYLOTREE = ".nwk";
94+
public static final String EXTENSION_TEXT = ".txt";
95+
8096
// Phylogenetic view constants.
8197
public static final String PHYLO_WINDOW_TITLE = "Select Genomes";
8298
public static final String PHYLO_BUTTON_LABEL_UPDATE = "Update";
8399
public static final String PHYLO_LABEL_PHYLOGENETIC_TREE = "Phylogenetic tree";
84100
public static final String PHYLO_LABEL_COMMON_ANCESTOR = "Common ancestor";
101+
102+
// MetaFilter view constants
103+
public static final String META_VIEW_TITLE = "Select options to filter on";
104+
85105
}

src/main/java/tudelft/ti2806/pl3/ScreenSize.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public void calculate() {
9090
* size of the dimension
9191
* @return percentage*size rounded to nearest integer
9292
*/
93-
public int calculate(double percentage, int integer) {
93+
private int calculate(double percentage, int integer) {
9494
return (int) (percentage * integer);
9595
}
9696
}

src/main/java/tudelft/ti2806/pl3/controls/KeyController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*/
1212
public class KeyController implements KeyListener {
1313

14-
private Application app;
14+
private final Application app;
1515

1616
/**
1717
* Constructor removes the old keylisteners and makes our own.

src/main/java/tudelft/ti2806/pl3/controls/MouseManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public void mouseMoved(MouseEvent e) {
6666
* @param y
6767
* y location of the mouse cursor.
6868
*/
69-
public void mouseMoved(int x, int y) {
69+
private void mouseMoved(int x, int y) {
7070
node = getNodeAtPosition(x, y);
7171
if (node == null) {
7272
removeDetailView();

src/main/java/tudelft/ti2806/pl3/data/gene/GeneData.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,24 @@
2121
* Class containing all gene data.
2222
*/
2323
public class GeneData {
24-
public static final String PREFIX_GENE_START = "_start_";
25-
public static final String PREFIX_GENE_END = "_end_";
24+
private static final String PREFIX_GENE_START = "_start_";
25+
private static final String PREFIX_GENE_END = "_end_";
2626

2727
/**
2828
* List of all genes.
2929
*/
30-
private ArrayList<Gene> genes;
31-
private Map<String, Label> labelMap;
30+
private final ArrayList<Gene> genes;
31+
private final Map<String, Label> labelMap;
3232

3333
/**
3434
* Mapping from start index to the actual gene.
3535
*/
36-
private Map<Integer, Gene> geneStart;
36+
private final Map<Integer, Gene> geneStart;
3737

3838
/**
3939
* Mapping from end index to the actual gene.
4040
*/
41-
private Map<Integer, Gene> geneEnd;
41+
private final Map<Integer, Gene> geneEnd;
4242

4343
private static final char COMMENT_IDENTIFIER = '#';
4444
private static final String TAB = "\t";
@@ -75,10 +75,6 @@ public ArrayList<Gene> getGenes() {
7575
return genes;
7676
}
7777

78-
public Map<String, Label> getLabelMap() {
79-
return labelMap;
80-
}
81-
8278
public Label getLabel(String key) {
8379
return labelMap.get(key);
8480
}

src/main/java/tudelft/ti2806/pl3/data/graph/GraphData.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* GraphData parses the data as nodes,edges and genomes.
1111
*/
1212
public class GraphData extends AbstractGraphData {
13-
private AbstractGraphData origin;
13+
private final AbstractGraphData origin;
1414

1515
/**
1616
* Constructs an instance of {@code GraphData}.

src/main/java/tudelft/ti2806/pl3/data/graph/GraphDataRepository.java

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424

2525
public class GraphDataRepository extends AbstractGraphData implements LoadingObservable {
2626

27-
private ArrayList<LoadingObserver> observers = new ArrayList<>();
28-
private List<GraphParsedObserver> graphParsedObserver = new ArrayList<>();
27+
private final ArrayList<LoadingObserver> observers = new ArrayList<>();
28+
private final List<GraphParsedObserver> graphParsedObserver = new ArrayList<>();
2929

3030
/**
3131
* Construct a empty {@code GraphDataRepository}.
@@ -308,27 +308,6 @@ public DataNode getNodeByNodeId(int id) {
308308
return null;
309309
}
310310

311-
/**
312-
* Search for the edge in the graph with the given from and to id.
313-
*
314-
* @param fromId
315-
* the id of the from node on the edge
316-
* @param toId
317-
* the id of the to node on the edge
318-
* @return the found edge<br>
319-
* {@code null} if there is no node with this id in the graph
320-
*/
321-
// TODO This is never used, can it be deleted?
322-
public Edge getEdge(int fromId, int toId) {
323-
for (Edge edge : edges) {
324-
if (edge.getFrom().getId() == fromId
325-
&& edge.getTo().getId() == toId) {
326-
return edge;
327-
}
328-
}
329-
return null;
330-
}
331-
332311
@Override
333312
public AbstractGraphData getOrigin() {
334313
return this;
@@ -341,9 +320,7 @@ public void addLoadingObserver(LoadingObserver loadingObserver) {
341320

342321
@Override
343322
public void addLoadingObserversList(ArrayList<LoadingObserver> loadingObservers) {
344-
for (LoadingObserver loadingObserver : loadingObservers) {
345-
addLoadingObserver(loadingObserver);
346-
}
323+
loadingObservers.forEach(this::addLoadingObserver);
347324
}
348325

349326
@Override

src/main/java/tudelft/ti2806/pl3/data/label/Label.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
*/
77
public abstract class Label {
88

9-
private String text;
9+
private final String text;
1010

1111
/**
1212
* Constructs an instance of the label.
1313
* @param s
1414
* the String label to set
1515
*/
16-
public Label(String s) {
16+
Label(String s) {
1717
if (s != null) {
1818
text = s;
1919
} else {
@@ -31,14 +31,12 @@ public boolean equals(Object o) {
3131
}
3232

3333
Label label = (Label) o;
34-
35-
return !(text != null ? !text.equals(label.text) : label.text != null);
36-
34+
return text.equals(label.text);
3735
}
3836

3937
@Override
4038
public int hashCode() {
41-
return text != null ? text.hashCode() : 0;
39+
return text.hashCode();
4240
}
4341

4442
public String getText() {

0 commit comments

Comments
 (0)