Skip to content

Commit

Permalink
[#159] Remove non-static initializers
Browse files Browse the repository at this point in the history
Remove non-static initializers except one (keep one as an example)
  • Loading branch information
damithc authored Oct 19, 2016
1 parent a645792 commit 9f70ed1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
7 changes: 7 additions & 0 deletions src/main/java/seedu/address/model/AddressBook.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ public class AddressBook implements ReadOnlyAddressBook {
private final UniquePersonList persons;
private final UniqueTagList tags;

/*
* The 'unusual' code block below is an non-static initialization block, sometimes used to avoid duplication
* between constructors. See https://docs.oracle.com/javase/tutorial/java/javaOO/initial.html
*
* Note that non-static init blocks are not recommended to use. There are other ways to avoid duplication
* among constructors.
*/
{
persons = new UniquePersonList();
tags = new UniqueTagList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,19 @@ public class XmlSerializableAddressBook implements ReadOnlyAddressBook {
@XmlElement
private List<XmlAdaptedTag> tags;

{
persons = new ArrayList<>();
tags = new ArrayList<>();
}

/**
* Empty constructor required for marshalling
*/
public XmlSerializableAddressBook() {}
public XmlSerializableAddressBook() {
persons = new ArrayList<>();
tags = new ArrayList<>();
}

/**
* Conversion
*/
public XmlSerializableAddressBook(ReadOnlyAddressBook src) {
this();
persons.addAll(src.getPersonList().stream().map(XmlAdaptedPerson::new).collect(Collectors.toList()));
tags.addAll(src.getTagList().stream().map(XmlAdaptedTag::new).collect(Collectors.toList()));
}
Expand Down

0 comments on commit 9f70ed1

Please sign in to comment.