@@ -27,75 +27,70 @@ public class RecordController extends BaseController<Record> {
2727 private final AccountController accountController ;
2828
2929 public RecordController (IRepo <Record > recordRepo , CategoryController categoryController ,
30- AccountController accountController ) {
30+ AccountController accountController ) {
3131 super (recordRepo );
3232 this .categoryController = categoryController ;
3333 this .accountController = accountController ;
3434 }
3535
36- @ Override
37- @ SuppressWarnings ("SimplifiableIfStatement" )
38- public Record create (@ Nullable Record record ) {
36+ @ Override @ SuppressWarnings ("SimplifiableIfStatement" ) public Record create (@ Nullable Record record ) {
3937 if (record == null ) return null ;
4038
4139 record = validateRecord (record );
4240
4341 Record createdRecord = repo .create (record );
44- if (createdRecord == null ) return null ;
45- else {
42+ if (createdRecord == null ) {
43+ return null ;
44+ } else {
4645 accountController .recordAdded (createdRecord );
4746 return createdRecord ;
4847 }
4948 }
5049
51- @ Override
52- @ SuppressWarnings ("SimplifiableIfStatement" )
53- public Record update (@ Nullable Record record ) {
50+ @ Override @ SuppressWarnings ("SimplifiableIfStatement" ) public Record update (@ Nullable Record record ) {
5451 if (record == null ) return null ;
5552
5653 record = validateRecord (record );
5754
5855 Record oldRecord = read (record .getId ());
5956
6057 Record updatedRecord = repo .update (record );
61- if (updatedRecord == null ) return null ;
62- else {
58+ if (updatedRecord == null ) {
59+ return null ;
60+ } else {
6361 accountController .recordUpdated (oldRecord , updatedRecord );
6462 return updatedRecord ;
6563 }
6664 }
6765
68- @ Override
69- @ SuppressWarnings ("SimplifiableIfStatement" )
70- public boolean delete (@ Nullable Record record ) {
71- if (repo .delete (record )) return accountController .recordDeleted (record );
72- else return false ;
66+ @ Override @ SuppressWarnings ("SimplifiableIfStatement" ) public boolean delete (@ Nullable Record record ) {
67+ if (repo .delete (record )) {
68+ return accountController .recordDeleted (record );
69+ } else {
70+ return false ;
71+ }
7372 }
7473
75- @ Nullable
76- @ Override
77- public Record read (long id ) {
78- List <Record > list = readWithCondition ("id=?" , new String []{Long .toString (id )});
74+ @ Nullable @ Override public Record read (long id ) {
75+ List <Record > list = readWithCondition ("id=?" , new String [] { Long .toString (id ) });
7976
80- if (list .size () == 1 ) return list .get (0 );
81- else return null ;
77+ if (list .size () == 1 ) {
78+ return list .get (0 );
79+ } else {
80+ return null ;
81+ }
8282 }
8383
84- @ NonNull
85- @ Override
86- public List <Record > readAll () {
84+ @ NonNull @ Override public List <Record > readAll () {
8785 return readWithCondition (null , null );
8886 }
8987
90- @ NonNull
91- @ Override
92- public List <Record > readWithCondition (String condition , String [] args ) {
88+ @ NonNull @ Override public List <Record > readWithCondition (String condition , String [] args ) {
9389 List <Record > recordList = super .readWithCondition (condition , args );
9490
9591 // Sort record list by time field from smallest to biggest
9692 Collections .sort (recordList , new Comparator <Record >() {
97- @ Override
98- public int compare (Record lhs , Record rhs ) {
93+ @ Override public int compare (Record lhs , Record rhs ) {
9994 return lhs .getTime () < rhs .getTime () ? -1 : (lhs .getTime () == rhs .getTime () ? 0 : 1 );
10095 }
10196 });
@@ -104,25 +99,31 @@ public int compare(Record lhs, Record rhs) {
10499 List <Record > completedRecordList = new ArrayList <>();
105100 for (Record record : recordList ) {
106101 Category category = null ;
107- if (record .getCategory () != null )
108- category = categoryController .read (record .getCategory ().getId ());
102+ if (record .getCategory () != null ) category = categoryController .read (record .getCategory ().getId ());
109103
110104 Account account = null ;
111- if (record .getAccount () != null )
112- account = accountController .read (record .getAccount ().getId ());
105+ if (record .getAccount () != null ) account = accountController .read (record .getAccount ().getId ());
113106
114- completedRecordList .add (new Record ( record . getId (), record . getTime (), record . getType (),
115- record .getTitle (), category , record .getPrice (), account , record .getCurrency () ,
116- record .getDecimals ()));
107+ completedRecordList .add (
108+ new Record ( record .getId (), record . getTime () , record .getType (), record .getTitle (), category ,
109+ record . getPrice (), account , record . getCurrency (), record .getDecimals ()));
117110 }
118111
119112 return completedRecordList ;
120113 }
121114
122115 public List <Record > getRecordsForPeriod (Period period ) {
123116 String condition = DbHelper .TIME_COLUMN + " BETWEEN ? AND ?" ;
124- String [] args = new String []{Long .toString (period .getFirst ().getTime ()),
125- Long .toString (period .getLast ().getTime ())};
117+ String [] args = new String [] {
118+ Long .toString (period .getFirst ().getTime ()), Long .toString (period .getLast ().getTime ())
119+ };
120+
121+ return readWithCondition (condition , args );
122+ }
123+
124+ public List <Record > getRecordsForAccount (Account account ) {
125+ String condition = DbHelper .ACCOUNT_ID_COLUMN + "=?" ;
126+ String [] args = new String [] { Long .toString (account .getId ()) };
126127
127128 return readWithCondition (condition , args );
128129 }
@@ -132,8 +133,7 @@ private Record validateRecord(@NonNull Record record) {
132133
133134 Category category = categoryController .readOrCreate (record .getCategory ().getName ());
134135
135- return new Record (record .getId (), record .getTime (), record .getType (), record .getTitle (),
136- category , record .getPrice (), record .getAccount (), record .getCurrency (),
137- record .getDecimals ());
136+ return new Record (record .getId (), record .getTime (), record .getType (), record .getTitle (), category ,
137+ record .getPrice (), record .getAccount (), record .getCurrency (), record .getDecimals ());
138138 }
139139}
0 commit comments