Skip to content

Commit

Permalink
Edited code to fulfill checkstyle requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
HoolaBoola committed Dec 2, 2020
1 parent 4abced1 commit acbea0f
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 48 deletions.
2 changes: 1 addition & 1 deletion config/checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<property name="max" value="1"/>
</module>
<module name="Indentation">
<property name="caseIndent" value="0"/>
<property name="caseIndent" value="4"/>
</module>
<module name="LeftCurly">
</module>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@

import recommendation_library.domain.BookRecommendation;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.*;
import java.util.function.Function;

import recommendation_library.domain.TimeMemory;
import recommendation_library.domain.Type;
Expand Down Expand Up @@ -49,27 +48,22 @@ public void editBookRecommendation(String title, String fieldToBeEdited, String
}
}
}

private void editBookMatchingField(BookRecommendation b, String fieldToBeEdited, String newValue) {
switch (fieldToBeEdited.toLowerCase()){
case "author":
b.setAuthor(newValue);
break;
case "title":
b.setTitle(newValue);
break;
case "description":
b.setDescription(newValue);
break;
case "isbn":
b.setIsbn(newValue);
break;
case "pagecount":
b.setPageCount(Integer.parseInt(newValue));
break;
}
fieldToBeEdited = fieldToBeEdited.toLowerCase();

Map<String, Function<String, Boolean>> map = new HashMap<>();

map.put("author", b::setAuthor);
map.put("title", b::setTitle);
map.put("description", b::setDescription);
map.put("isbn", b::setIsbn);
map.put("pagecount", s -> b.setPageCount(Integer.parseInt(s)));

map.get(fieldToBeEdited).apply(newValue);
}


@Override
public void deleteBookByTitle(String title) {
BookRecommendation toBeRemoved = null;
Expand Down Expand Up @@ -103,25 +97,15 @@ public void editVideoRecommendation(String title, String fieldToBeEdited, String
}
}
}

private void editVideoMatchingField(VideoRecommendation v, String fieldToBeEdited, String newValue) {
System.err.println(v.getTitle());
System.err.println(v.getUrl());
fieldToBeEdited = fieldToBeEdited.toLowerCase();
Map<String, Function<String, Boolean>> map = new HashMap<>();
map.put("title", v::setTitle);
map.put("url", v::setUrl);
map.put("description", v::setDescription);
System.err.println(fieldToBeEdited);
System.err.println(newValue);
System.err.println();
System.err.println();
switch (fieldToBeEdited.toLowerCase()){
case "title":
v.setTitle(newValue);
break;
case "url":
v.setUrl(newValue);
break;
case "description":
v.setDescription(newValue);
break;
}
map.get(fieldToBeEdited).apply(newValue);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,27 @@ public int getPageCount() {
return pageCount;
}

public void setPageCount(int pageCount) {
public boolean setPageCount(int pageCount) {
this.pageCount = pageCount;
return true;
}

public String getAuthor() {
return author;
}

public void setAuthor(String author) {
public boolean setAuthor(String author) {
this.author = author;
return true;
}

public String getIsbn() {
return isbn;
}

public void setIsbn(String isbn) {
public boolean setIsbn(String isbn) {
this.isbn = isbn;
return true;
}

}
15 changes: 10 additions & 5 deletions src/main/java/recommendation_library/domain/Recommendation.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,40 +29,45 @@ public int getId() {
return id;
}

public void setId(int id) {
public boolean setId(int id) {
this.id = id;
return true;
}

public String getTitle() {
return title;
}

public void setTitle(String title) {
public boolean setTitle(String title) {
this.title = title;
return true;
}

public Type getType() {
return type;
}

public void setType(Type type) {
public boolean setType(Type type) {
this.type = type;
return true;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
public boolean setDescription(String description) {
this.description = description;
return true;
}

public String getAddDate() {
return addDate;
}

public void setAddDate(String addDate) {
public boolean setAddDate(String addDate) {
this.addDate = addDate;
return true;
}

public boolean equals(Recommendation other) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ public String getUrl() {
return url;
}

public void setUrl(String newUrl) {
public boolean setUrl(String newUrl) {
url = newUrl;
return true;
}


Expand Down

0 comments on commit acbea0f

Please sign in to comment.