-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTopicService.java
More file actions
64 lines (46 loc) · 1.47 KB
/
TopicService.java
File metadata and controls
64 lines (46 loc) · 1.47 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package com.app.topic;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.springframework.stereotype.Service;
import com.app.dto.Topic;
@Service
public class TopicService {
List<Topic> topiclist = new ArrayList<Topic>(Arrays.asList(
new Topic("one", "java", "twomonths"),
new Topic("two", "C++", "twomonths"),
new Topic("Three", "C", "twomonths"),
new Topic("Four", "Python", "twomonths")
));
/*topiclist =Arrays.asList(
new Topic(1, "java", "twomonths"),
new Topic(2, "C++", "twomonths"),
new Topic(3, "C", "twomonths"),
new Topic(4, "Python", "twomonths")
);*/
public List<Topic> getAllTopics() {
return topiclist ;
}
public void addTopic(Topic topic) {
topiclist.add(topic);
System.out.println(topiclist);
}
public Topic getTopic(String id) {
return topiclist.stream().filter(t -> t.getId().equals(id)).findFirst().get();
}
public void upateTopic(Topic topic, String id) {
System.out.println("entered in servie");
for(int i=0; i<topiclist.size();i++) {
Topic top = topiclist.get(i);
if(top.getId().equals(id))
topiclist.set(i, topic);
}
System.out.println("completed service");
}
public void deleteTopic(String id) {
topiclist.removeIf(t -> t.getId().equals(id));
}
/*public Topic getTopic(String id) {
return topiclist.stream().filter( t -> t.getId().equals(id)).findFirst().get();
}*/
}