Skip to content

Instantly share code, notes, and snippets.

@cemdrman
Created November 30, 2022 17:38
Show Gist options
  • Save cemdrman/58569e2672563ca52c444871436992f1 to your computer and use it in GitHub Desktop.
Save cemdrman/58569e2672563ca52c444871436992f1 to your computer and use it in GitHub Desktop.
import model.Blog;
import model.User;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class Main {
static List<User> userList = new ArrayList<>();
public static void main(String[] args) {
User userCem = new User();
userCem.setName("Cem");
userCem.setEmail("cemdrmanqgmail.com");
userCem.setBio("fenerbahçeli yazılımcı");
userCem.setPassword("12456");
userCem.setProfilePhoto("sonradan ekleyeceğiz");
User userZeynep = new User("Zeynep", "zeynepqmail.com", "123123", "foto yok", "bio da yok");
userList.add(userCem);
userList.add(userZeynep);
String[] tags = new String[5];
tags[0] = "git";
tags[1] = "git commands";
tags[2] = "git branch";
tags[3] = "java";
tags[4] = "java8";
Blog zeynepBlog = new Blog("Daily Git Commands",
"https://miro.medium.com/max/1400/0*p4eGQrb2mfROeQHh",
"Today, i will try to tell what i use git commands just in my daily life \uD83D\uDE05\n" +
"\n" +
"git add . or git add fileName ➡️ add a file to your commit\n" +
"git commit -m “commit message” ➡️ commit to your local repo\n" +
"git push origin branch-name ➡️ pushs all commits in your local branch to remote(origin means remote repo but you can change it)\n" +
"git checkout branch-name ➡️ switch to existing branch\n" +
"git checkout -b branch-name ➡️ creates and switch new branch",
LocalDateTime.now(),
tags);
zeynepBlog.setPublisched(true);
Blog zeynepBlog2 = new Blog();
zeynepBlog2.setViews(zeynepBlog2.getViews() + 1);
zeynepBlog2.setPublisched(false);
zeynepBlog2.setTitle("ikinci blog yazım");
zeynepBlog2.setPublishDate(LocalDateTime.now());
List<Blog> zeynepBlogs = new ArrayList<>();
zeynepBlogs.add(zeynepBlog);
zeynepBlogs.add(zeynepBlog2);
userZeynep.setBlogs(zeynepBlogs);
Blog cemBlog = new Blog();
cemBlog.setTitle("Shell Script in Real Life");
cemBlog.setPublisched(true);
userCem.setBlogs(Arrays.asList(cemBlog));
for (User user : userList) {
for (Blog blog : user.getBlogs()) {
if (blog.getPublisched()){
System.out.println("User:" + user.getName() + "Blog: " + blog.getTitle());
}
}
}
System.out.println("--Your stories--");
findPublichedBlogByUserName("Cem");
}
private static void findPublichedBlogByUserName(String name){
for (int i = 0; i < userList.size(); i++) {
if (userList.get(i).getName().equals(name)){
System.out.println(userList.get(i).getName());
for (int j = 0; j < userList.get(i).getBlogs().size(); j++) {
if (userList.get(i).getBlogs().get(j).getPublisched()){
System.out.println(userList.get(i).getBlogs().get(j).getTitle());
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment