Skip to content

Commit

Permalink
Merge e15460e into 0af9251
Browse files Browse the repository at this point in the history
  • Loading branch information
moziliar committed Nov 9, 2019
2 parents 0af9251 + e15460e commit fceeee4
Show file tree
Hide file tree
Showing 20 changed files with 735 additions and 10 deletions.
24 changes: 24 additions & 0 deletions src/main/java/seedu/weme/model/statistics/DislikeData.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,28 @@ public Map<String, SimpleIntegerProperty> getCopy() {
}
return copy;
}


@Override
public boolean equals(Object other) {
if (other == this) {
return true;
}

if (!(other instanceof DislikeData)) {
return false;
}

DislikeData otherDislikeData = (DislikeData) other;
if (!dislikeMap.keySet().equals(otherDislikeData.getCopy().keySet())) {
return false;
} else {
for (Map.Entry<String, SimpleIntegerProperty> entry : otherDislikeData.dislikeMap.entrySet()) {
if (dislikeMap.get(entry.getKey()).get() != entry.getValue().get()) {
return false;
}
}
}
return true;
}
}
30 changes: 30 additions & 0 deletions src/main/java/seedu/weme/model/statistics/LikeData.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ public LikeData(ObservableMap<String, SimpleIntegerProperty> likeMap) {
setLikeMap(likeMap);
}

/**
* Constructs a LikeData filled with the provided likeMap
*/
public LikeData(LikeData likeData) {
setLikeMap(likeData.getCopy());
}

/**
* Sets the current set of {@code LikeData} with a replacement.
*/
Expand Down Expand Up @@ -94,4 +101,27 @@ public Map<String, SimpleIntegerProperty> getCopy() {
return copy;
}

@Override
public boolean equals(Object other) {
if (other == this) {
return true;
}

if (!(other instanceof LikeData)) {
return false;
}

LikeData otherLikeData = (LikeData) other;
if (!likeMap.keySet().equals(otherLikeData.getCopy().keySet())) {
return false;
} else {
for (Map.Entry<String, SimpleIntegerProperty> entry : otherLikeData.likeMap.entrySet()) {
if (likeMap.get(entry.getKey()).get() != entry.getValue().get()) {
return false;
}
}
}
return true;
}
}

25 changes: 20 additions & 5 deletions src/main/java/seedu/weme/model/statistics/LikeManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ public class LikeManager {
private LikeData likeData;
private DislikeData dislikeData;

public LikeManager(LikeData likeData, DislikeData dislikeData) {
public LikeManager(LikeManager likeManager) {
super();
requireAllNonNull(likeData);
requireAllNonNull(likeManager);

logger.fine("Initializing with like data: " + likeData);
logger.fine("Initializing with like data: " + likeManager);

this.likeData = new LikeData(likeData.getObservableLikeData());
this.dislikeData = new DislikeData(dislikeData.getObservableDislikeData());
this.likeData = new LikeData(likeManager.likeData.getObservableLikeData());
this.dislikeData = new DislikeData(likeManager.dislikeData.getObservableDislikeData());
}

public LikeManager() {
Expand Down Expand Up @@ -157,4 +157,19 @@ public Map<String, SimpleIntegerProperty> getCopyDislikeData() {
return dislikeData.getCopy();
}

@Override
public boolean equals(Object other) {
if (other == this) {
return true;
}

if (!(other instanceof LikeManager)) {
return false;
}

LikeManager otherLikeManager = (LikeManager) other;
return likeData.equals(otherLikeManager.likeData)
&& dislikeData.equals(otherLikeManager.dislikeData);

}
}
2 changes: 2 additions & 0 deletions src/main/java/seedu/weme/model/statistics/Stats.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public interface Stats {

Stats getStats();

LikeManager getLikeManager();

//============= Like Data ====================================

/**
Expand Down
19 changes: 18 additions & 1 deletion src/main/java/seedu/weme/model/statistics/StatsManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ public StatsManager(Stats stats) {
resetData(stats);
}

public LikeManager getLikeManager() {
return likeManager;
}

//============= Like Data ====================================

public void addDefaultLikeData(Meme meme) {
Expand Down Expand Up @@ -116,7 +120,7 @@ public int getCountOfTag(List<Meme> memeList, Tag tag) {
@Override
public List<TagWithCount> getTagsWithCountList(List<Meme> memeList) {
return tagManager.getTagsWithCountList(memeList);
};
}

@Override
public List<TagWithLike> getTagsWithLikeCountList(List<Meme> memeList) {
Expand Down Expand Up @@ -151,4 +155,17 @@ public Stats getStats() {
return newStats;
}

@Override
public boolean equals(Object other) {
if (other == this) {
return true;
}

if (!(other instanceof StatsManager)) {
return false;
}

StatsManager otherStats = (StatsManager) other;
return likeManager.equals(otherStats.likeManager);
}
}
14 changes: 14 additions & 0 deletions src/main/java/seedu/weme/storage/JsonSerializableStats.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
*/
@JsonRootName(value = "statsData")
class JsonSerializableStats {
public static final String MESSAGE_INVALID_LIKE = "Like data contains out of bound like.";
public static final String MESSAGE_INVALID_DISLIKE = "Like data contains out of bound dislike.";
public static final String MESSAGE_DUPLICATE_LIKE = "Like data contains duplicate like.";
public static final String MESSAGE_DUPLICATE_DISLIKE = "Like data contains duplicate dislike.";

private final Map<String, Integer> likeMap = new HashMap<>();
private final Map<String, Integer> dislikeMap = new HashMap<>();
Expand Down Expand Up @@ -57,9 +61,19 @@ public Stats toModelType() throws IllegalValueException {
Map<String, SimpleIntegerProperty> likeData = new HashMap<>();
Map<String, SimpleIntegerProperty> dislikeData = new HashMap<>();
for (Map.Entry<String, Integer> entry : likeMap.entrySet()) {
if (entry.getValue() < 0) {
throw new IllegalValueException(MESSAGE_INVALID_LIKE);
} else if (likeData.containsKey(entry.getKey())) {
throw new IllegalValueException(MESSAGE_DUPLICATE_LIKE);
}
likeData.put(entry.getKey(), new SimpleIntegerProperty(entry.getValue()));
}
for (Map.Entry<String, Integer> entry : dislikeMap.entrySet()) {
if (entry.getValue() < 0) {
throw new IllegalValueException(MESSAGE_INVALID_DISLIKE);
} else if (dislikeData.containsKey(entry.getKey())) {
throw new IllegalValueException(MESSAGE_DUPLICATE_DISLIKE);
}
dislikeData.put(entry.getKey(), new SimpleIntegerProperty(entry.getValue()));
}
stats.setLikeData(likeData);
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/seedu/weme/storage/JsonSerializableWeme.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ public JsonSerializableWeme(ReadOnlyWeme source) {
records = new JsonSerializableRecords(source.getRecords());
}

public JsonSerializableStats getStats() {
return stats;
}

/**
* Converts this Weme into the model's {@code Weme} object.
*
Expand Down
77 changes: 77 additions & 0 deletions src/test/data/JsonSerializableStatsTest/invalidDislikeWeme.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
{
"_comment": "Weme save file which contains the same Meme values as in TypicalMemes#getTypicalMemes() and same Template values as in TypicalTemplates#getTypicalTemplates()",
"memes" : [ {
"filePath": "src/test/data/memes/charmander_meme.jpg",
"tagged" : [ "charmander" ],
"description" : "A meme about Char and charmander.",
"isArchived": false
}, {
"filePath": "src/test/data/memes/doge_meme.jpg",
"tagged" : ["doge"],
"description" : "A meme about doge.",
"isArchived": false
}, {
"filePath": "src/test/data/memes/joker_meme.jpg",
"tagged" : ["joker"],
"description" : "A meme about joker.",
"isArchived": false
}, {
"filePath": "src/test/data/memes/toy_meme.jpg",
"tagged" : ["toy"],
"description" : "A toy story meme.",
"isArchived": false
}, {
"filePath": "src/test/data/memes/pikachu_meme.png",
"tagged" : ["pikachu"],
"description" : "Pikachu",
"isArchived": true
}],
"templates" : [ {
"name" : "Drake Reaction",
"filePath": "src/test/data/templates/drake_template.jpg",
"isArchived": false
}, {
"name" : "Is This",
"filePath": "src/test/data/templates/is_this_template.jpg",
"isArchived": false
}, {
"name" : "Quiz Kid",
"filePath": "src/test/data/templates/quiz_kid_template.jpg",
"isArchived": false
}, {
"name" : "Surprised Pikachu",
"filePath": "src/test/data/templates/pikachu_template.jpg",
"isArchived": true
} ],
"stats" : {
"likeMap" : {
"src/test/data/memes/charmander_meme.jpg" : 1,
"src/test/data/memes/doge_meme.jpg" : 2,
"src/test/data/memes/joker_meme.jpg" : 0,
"src/test/data/memes/toy_meme.jpg" : 0
},
"dislikeMap" : {
"src/test/data/memes/charmander_meme.jpg" : 0,
"src/test/data/memes/doge_meme.jpg" : 0,
"src/test/data/memes/joker_meme.jpg" : -1,
"src/test/data/memes/toy_meme.jpg" : 2
}
},
"records" : {
"pathRecords" : [
"/home/me/Pictures/weme.jpg"
],
"descriptionRecords" : [
"OMG my favorite meme!!!"
],
"tagRecords" : [
"[CS2103]"
],
"nameRecords" : [
"disaster girl"
],
"textRecords" : [
"lol"
]
}
}
77 changes: 77 additions & 0 deletions src/test/data/JsonSerializableStatsTest/invalidLikeWeme.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
{
"_comment": "Weme save file which contains the same Meme values as in TypicalMemes#getTypicalMemes() and same Template values as in TypicalTemplates#getTypicalTemplates()",
"memes" : [ {
"filePath": "src/test/data/memes/charmander_meme.jpg",
"tagged" : [ "charmander" ],
"description" : "A meme about Char and charmander.",
"isArchived": false
}, {
"filePath": "src/test/data/memes/doge_meme.jpg",
"tagged" : ["doge"],
"description" : "A meme about doge.",
"isArchived": false
}, {
"filePath": "src/test/data/memes/joker_meme.jpg",
"tagged" : ["joker"],
"description" : "A meme about joker.",
"isArchived": false
}, {
"filePath": "src/test/data/memes/toy_meme.jpg",
"tagged" : ["toy"],
"description" : "A toy story meme.",
"isArchived": false
}, {
"filePath": "src/test/data/memes/pikachu_meme.png",
"tagged" : ["pikachu"],
"description" : "Pikachu",
"isArchived": true
}],
"templates" : [ {
"name" : "Drake Reaction",
"filePath": "src/test/data/templates/drake_template.jpg",
"isArchived": false
}, {
"name" : "Is This",
"filePath": "src/test/data/templates/is_this_template.jpg",
"isArchived": false
}, {
"name" : "Quiz Kid",
"filePath": "src/test/data/templates/quiz_kid_template.jpg",
"isArchived": false
}, {
"name" : "Surprised Pikachu",
"filePath": "src/test/data/templates/pikachu_template.jpg",
"isArchived": true
} ],
"stats" : {
"likeMap" : {
"src/test/data/memes/charmander_meme.jpg" : -1,
"src/test/data/memes/doge_meme.jpg" : 2,
"src/test/data/memes/joker_meme.jpg" : 0,
"src/test/data/memes/toy_meme.jpg" : 0
},
"dislikeMap" : {
"src/test/data/memes/charmander_meme.jpg" : 0,
"src/test/data/memes/doge_meme.jpg" : 0,
"src/test/data/memes/joker_meme.jpg" : 1,
"src/test/data/memes/toy_meme.jpg" : 2
}
},
"records" : {
"pathRecords" : [
"/home/me/Pictures/weme.jpg"
],
"descriptionRecords" : [
"OMG my favorite meme!!!"
],
"tagRecords" : [
"[CS2103]"
],
"nameRecords" : [
"disaster girl"
],
"textRecords" : [
"lol"
]
}
}

0 comments on commit fceeee4

Please sign in to comment.