public class Post {
private String text;
private Date date;
private List <Comment> comments;
public Post( String text) {
this .text = text;
this .date = new Date();
this .comments = new ArrayList <Comment>();
}
// getters and setters...
}
* This source code was highlighted with Source Code Highlighter .
public class Post {
private String text;
private Date date;
private List <Comment> comments;
public Post( String text) {
this .text = text;
this .date = new Date();
this .comments = new ArrayList <Comment>();
}
// getters and setters...
}
* This source code was highlighted with Source Code Highlighter .
public class Post {
private String text;
private Date date;
private List <Comment> comments;
public Post( String text) {
this .text = text;
this .date = new Date();
this .comments = new ArrayList <Comment>();
}
// getters and setters...
}
* This source code was highlighted with Source Code Highlighter .
public class Comment {
private String text;
private Date date;
public Comment( String text) {
this .text = text;
this .date = new Date();
}
// getters and setters...
}
* This source code was highlighted with Source Code Highlighter .
public class Comment {
private String text;
private Date date;
public Comment( String text) {
this .text = text;
this .date = new Date();
}
// getters and setters...
}
* This source code was highlighted with Source Code Highlighter .
public class Comment {
private String text;
private Date date;
public Comment( String text) {
this .text = text;
this .date = new Date();
}
// getters and setters...
}
* This source code was highlighted with Source Code Highlighter .
public Comment comment( String text) {
Comment comment = new Comment(text);
this .comments.add(comment);
return comment;
}
* This source code was highlighted with Source Code Highlighter .
public Comment comment( String text) {
Comment comment = new Comment(text);
this .comments.add(comment);
return comment;
}
* This source code was highlighted with Source Code Highlighter .
public Comment comment( String text) {
Comment comment = new Comment(text);
this .comments.add(comment);
return comment;
}
* This source code was highlighted with Source Code Highlighter .
Item item = new Item();
item. set ...
itemDao.insert(item);
...
Item item = itemDao. select (itemId);
item. set ..
itemDao.update(item);
* This source code was highlighted with Source Code Highlighter .
Item item = new Item();
item. set ...
itemDao.insert(item);
...
Item item = itemDao. select (itemId);
item. set ..
itemDao.update(item);
* This source code was highlighted with Source Code Highlighter .
Item item = new Item();
item. set ...
itemDao.insert(item);
...
Item item = itemDao. select (itemId);
item. set ..
itemDao.update(item);
* This source code was highlighted with Source Code Highlighter .
Item = new Item();
item. set ...
itemRepository.add(item);
...
Item item = itemRepository. get (itemId);
item. set ...
* This source code was highlighted with Source Code Highlighter .
Item = new Item();
item. set ...
itemRepository.add(item);
...
Item item = itemRepository. get (itemId);
item. set ...
* This source code was highlighted with Source Code Highlighter .
Item = new Item();
item. set ...
itemRepository.add(item);
...
Item item = itemRepository. get (itemId);
item. set ...
* This source code was highlighted with Source Code Highlighter .
public interface PostRepository {
void add(Post post);
void remove(PostId postId);
Post get (PostId postId);
List <Post> getAll();
}
* This source code was highlighted with Source Code Highlighter .
public interface PostRepository {
void add(Post post);
void remove(PostId postId);
Post get (PostId postId);
List <Post> getAll();
}
* This source code was highlighted with Source Code Highlighter .
public interface PostRepository {
void add(Post post);
void remove(PostId postId);
Post get (PostId postId);
List <Post> getAll();
}
* This source code was highlighted with Source Code Highlighter .
public class PostId {}
public class Post {
private PostId postId;
private String text;
private Date date;
private List <Comment> comments;
...
}
* This source code was highlighted with Source Code Highlighter .
public class PostId {}
public class Post {
private PostId postId;
private String text;
private Date date;
private List <Comment> comments;
...
}
* This source code was highlighted with Source Code Highlighter .
public class PostId {}
public class Post {
private PostId postId;
private String text;
private Date date;
private List <Comment> comments;
...
}
* This source code was highlighted with Source Code Highlighter .
public class InMemoryPostRepository implements PostRepository {
private Map<PostId, Post> identityMap = new HashMap<PostId, Post>();
@Override
public Post get (PostId postId) {
return this .identityMap. get (postId);
}
@Override
public List <Post> getAll() {
return new ArrayList <Post>( this .identityMap.values());
}
@Override
public void add(Post post) {
PostId postId = new PostId();
post.setPostId(postId);
this .identityMap.put(postId, post);
}
@Override
public void remove(PostId postId) {
this .identityMap.remove(postId);
}
}
* This source code was highlighted with Source Code Highlighter .
public class InMemoryPostRepository implements PostRepository {
private Map<PostId, Post> identityMap = new HashMap<PostId, Post>();
@Override
public Post get (PostId postId) {
return this .identityMap. get (postId);
}
@Override
public List <Post> getAll() {
return new ArrayList <Post>( this .identityMap.values());
}
@Override
public void add(Post post) {
PostId postId = new PostId();
post.setPostId(postId);
this .identityMap.put(postId, post);
}
@Override
public void remove(PostId postId) {
this .identityMap.remove(postId);
}
}
* This source code was highlighted with Source Code Highlighter .
public class InMemoryPostRepository implements PostRepository {
private Map<PostId, Post> identityMap = new HashMap<PostId, Post>();
@Override
public Post get (PostId postId) {
return this .identityMap. get (postId);
}
@Override
public List <Post> getAll() {
return new ArrayList <Post>( this .identityMap.values());
}
@Override
public void add(Post post) {
PostId postId = new PostId();
post.setPostId(postId);
this .identityMap.put(postId, post);
}
@Override
public void remove(PostId postId) {
this .identityMap.remove(postId);
}
}
* This source code was highlighted with Source Code Highlighter .
public class BlogService {
private PostRepository posts;
public void setPostRepository(PostRepository posts) {
this .posts = posts;
}
public Post post( String text) {
Post post = new Post(text);
this .posts.add(post);
return post;
}
public Comment comment(PostId postId, String text) {
Post post = this .posts. get (postId);
return post.comment(text);
}
public Post get (PostId postId) {
return this .posts. get (postId);
}
public List <Post> getAll() {
return this .posts.getAll();
}
public void delete(PostId postId) {
this .posts.remove(postId);
}
}
* This source code was highlighted with Source Code Highlighter .
public class BlogService {
private PostRepository posts;
public void setPostRepository(PostRepository posts) {
this .posts = posts;
}
public Post post( String text) {
Post post = new Post(text);
this .posts.add(post);
return post;
}
public Comment comment(PostId postId, String text) {
Post post = this .posts. get (postId);
return post.comment(text);
}
public Post get (PostId postId) {
return this .posts. get (postId);
}
public List <Post> getAll() {
return this .posts.getAll();
}
public void delete(PostId postId) {
this .posts.remove(postId);
}
}
* This source code was highlighted with Source Code Highlighter .
public class BlogService {
private PostRepository posts;
public void setPostRepository(PostRepository posts) {
this .posts = posts;
}
public Post post( String text) {
Post post = new Post(text);
this .posts.add(post);
return post;
}
public Comment comment(PostId postId, String text) {
Post post = this .posts. get (postId);
return post.comment(text);
}
public Post get (PostId postId) {
return this .posts. get (postId);
}
public List <Post> getAll() {
return this .posts.getAll();
}
public void delete(PostId postId) {
this .posts.remove(postId);
}
}
* This source code was highlighted with Source Code Highlighter .
Source: https://habr.com/ru/post/87812/
All Articles