Passed
Push — master ( 676f65...74c283 )
by Huu-Phat
02:02 queued 13s
created

com.dawn.jat.illuminati.core.convert.Converter   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 16
c 1
b 0
f 0
dl 0
loc 23
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A convertMapKeysToArray(Map) 0 6 1
A convertPostDtoToEntity(PostDto,PostEntity) 0 10 1
1
package com.dawn.jat.illuminati.core.convert;
2
3
import com.dawn.jat.illuminati.post.dto.PostDto;
4
import com.dawn.jat.illuminati.post.entity.PostEntity;
5
6
import java.util.ArrayList;
7
import java.util.List;
8
import java.util.Map;
9
10
import org.springframework.stereotype.Service;
11
12
@Service
13
public class Converter {
14
    private  <T> List<String> convertMapKeysToArray(Map<String, T> map) {
15
        List<String> list = new ArrayList<>();
16
        map.forEach((key, value) -> {
17
            list.add(key);
18
        });
19
        return list;
20
    }
21
22
    /**
23
     * Convert a PostDto to PostEntity.
24
     */
25
    public PostEntity convertPostDtoToEntity(PostDto post, PostEntity postEntity) {
26
        postEntity.setSlug(post.getSlug());
27
        postEntity.setAuthor(post.getAuthor());
28
        postEntity.setBrief(post.getBrief());
29
        postEntity.setTitle(post.getTitle());
30
        postEntity.setTime(post.getTime());
31
        postEntity.setContent(post.getContent());
32
        Map<String, Boolean> tagMap = post.getTag();
33
        postEntity.setTag(convertMapKeysToArray(tagMap));
34
        return postEntity;
35
    }
36
}
37