This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 57
/
UserWorkMatrix.java
48 lines (41 loc) · 1.6 KB
/
UserWorkMatrix.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package org.zanata.rest.dto.matrix;
import java.util.List;
import java.util.Map;
import javax.xml.bind.annotation.XmlRootElement;
import lombok.Delegate;
import org.codehaus.jackson.annotate.JsonIgnore;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.map.annotate.JsonSerialize;
import org.zanata.dao.TextFlowTargetHistoryDAO;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
/**
* This will help us to build a nested map structure.
*
* @see org.zanata.rest.dto.matrix.DetailMatrix
*
* @author Patrick Huang <a
* href="mailto:pahuang@redhat.com">pahuang@redhat.com</a>
*/
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
@XmlRootElement
public class UserWorkMatrix implements Map<String, List<DetailMatrix>> {
@Delegate
private Map<String, List<DetailMatrix>> dateToProjects = Maps.newHashMap();
@JsonIgnore
public void putOrCreateIfAbsent(String date,
TextFlowTargetHistoryDAO.UserTranslationMatrix matrixRecord) {
DetailMatrix detailMatrix = new DetailMatrix(
matrixRecord.getProjectIteration().getProject().getSlug(),
matrixRecord.getProjectIteration().getSlug(),
matrixRecord.getLocale().getLocaleId(),
matrixRecord.getSavedState(), matrixRecord.getWordCount());
if (containsKey(date)) {
List<DetailMatrix> matrixList = get(date);
matrixList.add(detailMatrix);
} else {
put(date, Lists.newArrayList(detailMatrix));
}
}
}