Blog blog1 = new Blog(); blog1.setTitle("Game of Thrones"); blog1.setAuthor("HBO"); blog1.setDescription("The best TV show in the US"); blog1.setUrl("www.hbonow.com/gameofthrones"); Blog blog2 = new Blog(); blog2.setTitle("Game of Thrones"); blog2.setAuthor("HBO"); blog2.setDescription("The best TV show in the US"); blog2.setUrl("www.hbonow.com/gameofthrones"); Blog blog3 = new Blog(); blog3.setTitle("Ray Donovan"); blog3.setAuthor("Showtime"); blog3.setDescription("The second best TV show in the US"); blog3.setUrl("www.showtime.com/raydonovan"); ArrayList<Blog> listOfBlogs = new ArrayList<>(); listOfBlogs.add(blog1); listOfBlogs.add(blog2); listOfBlogs.add(blog3); Set<Blog> setOfBlogs = new LinkedHashSet<>(listOfBlogs); listOfBlogs.clear(); listOfBlogs.addAll(setOfBlogs); for(int i=0;i<listOfBlogs.size();i++) System.out.println(listOfBlogs.get(i).getTitle());
class BlogWrapper { private Blog blog; //set via constructor etc. public int hashCode() { int hashCode = blog.getTitle().hashCode(); //check for null etc. //add the other hash codes as well return hashCode; } public boolean equals(Object other) { //check if both are BlogWrappers //remember to check for null too! Blog otherBlog = ((BlogWrapper)other).getBlog(); if( !blog.getTitle().equals(otherBlog.getTitle()) { return false; } ... //check other fields as well return true } }
/** * */ @Test public void test_AT_CacheResult_UsingAt_CacheKeyParam() { String testBody = "" + System.currentTimeMillis(); String testTitle = "title abc"; Blog blog = new Blog(testTitle, testBody); BlogManager blogManager = getBlogManager(); blogManager.createEntry(blog); Blog entryCached = blogManager.getEntryCached("asdf", testTitle, "adsfa"); assertEquals(entryCached.getBody(), testBody); /* clear from map, but not from cache */ blogManager.clearEntry(testTitle); entryCached = blogManager.getEntryCached(testTitle); assertNotNull("Item should still be in the cache thus not null", entryCached); assertEquals( "Item should still be in the cache and the title should be the same as before", entryCached.getBody(), testBody); }
var Blog = function () {}; Blog.prototype.signature = "Original sig"; var blog = new Blog(); blog.signature === "Original sig" //^looked up in Blog.prototype === Object.getPrototypeOf(blog) === blog.__proto__ blog.signature = "New sig" //^set as an instance property blog.signature === "New sig" Blog.prototype.signature !== "New sig" //actual instance properties override prototype properties, but they don't over-write them var blog2 = new Blog() blog2.signature === "Original sig"
/** * */ @Test public void test_AT_CacheResult() { String testBody = "" + System.currentTimeMillis(); String testTitle = "title a"; Blog blog = new Blog(testTitle, testBody); BlogManager blogManager = getBlogManager(); blogManager.createEntry(blog); Blog entryCached = blogManager.getEntryCached(testTitle); assertEquals(entryCached.getBody(), testBody); /* clear from map, but not from cache */ blogManager.clearEntry(testTitle); entryCached = blogManager.getEntryCached(testTitle); assertNotNull("Item should still be in the cache thus not null", entryCached); assertEquals( "Item should still be in the cache and the title should be the same as before", entryCached.getBody(), testBody); }
/** * */ @Test public void test_AT_CacheResult() { String testBody = "" + System.currentTimeMillis(); String testTitle = "title a"; Blog blog = new Blog(testTitle, testBody); BlogManager blogManager = getBlogManager(); blogManager.createEntry(blog); Blog entryCached = blogManager.getEntryCached(testTitle); assertEquals(entryCached.getBody(), testBody); /* clear from map, but not from cache */ blogManager.clearEntry(testTitle); entryCached = blogManager.getEntryCached(testTitle); assertNotNull("Item should still be in the cache thus not null", entryCached); assertEquals( "Item should still be in the cache and the title should be the same as before", entryCached.getBody(), testBody); }
public static void main(String[] args) { Blog b1 = new Blog("A", "sam", "a", "desc"); Blog b2 = new Blog("B", "ram", "b", "desc"); Blog b3 = new Blog("C", "cam", "c", "desc"); Blog b4 = new Blog("A", "sam", "a", "desc"); Blog b5 = new Blog("D", "dam", "d", "desc"); List<Blog> list = new ArrayList(); list.add(b1); list.add(b2); list.add(b3); list.add(b4); list.add(b5); //Removing Duplicates; Set<Blog> s= new HashSet<Blog>(); s.addAll(list); list = new ArrayList<Blog>(); list.addAll(s); //Now the List has only the identical Elements
/** * (non-Javadoc) * * @see manager.BlogManager#createEntry(domain.Blog) */ public void createEntry(Blog blog) { map.put(blog.getTitle(), blog); }
/** * */ @Test public void test_AT_CacheResult_UsingAt_CacheKeyParam() { String testBody = "" + System.currentTimeMillis(); String testTitle = "title abc"; Blog blog = new Blog(testTitle, testBody); BlogManager blogManager = getBlogManager(); blogManager.createEntry(blog); Blog entryCached = blogManager.getEntryCached("asdf", testTitle, "adsfa"); assertEquals(entryCached.getBody(), testBody); /* clear from map, but not from cache */ blogManager.clearEntry(testTitle); entryCached = blogManager.getEntryCached(testTitle); assertNotNull("Item should still be in the cache thus not null", entryCached); assertEquals( "Item should still be in the cache and the title should be the same as before", entryCached.getBody(), testBody); }
@Named("blogManager") @SessionScoped public class BlogManager { private List<Blog> blogs; private Blog blog; public BlogManager() { blogs = new ArrayList<Blog>(); blog = new Blog(); } // getter setters for blog and blogs public void addBlog() { blogs.add(blog); } public void removeBlog(Blog blog) { blogs.add(blog); } }
/** * (non-Javadoc) * * @see manager.BlogManager#createEntry(domain.Blog) */ public void createEntry(Blog blog) { map.put(blog.getTitle(), blog); }
@Test public void test_AT_CacheRemoveEntry() { String testBody = "" + System.currentTimeMillis(); String testTitle = "title b"; Blog blog = new Blog(testTitle, testBody); BlogManager blogManager = getBlogManager(); blogManager.createEntry(blog); Blog entryCached = blogManager.getEntryCached(testTitle); assertEquals(entryCached.getBody(), testBody); /* clear from cache using annotation @CacheRemove */ blogManager.clearEntryFromCache(testTitle); /* clear from map, but not from cache */ blogManager.clearEntry(testTitle); entryCached = blogManager.getEntryCached(testTitle); assertNull("Item should removed from the cache and the map", entryCached); }
var blog = new Blog();
public void createEntry(Blog blog) { map.put(blog.getTitle(), blog); }
@Test public void test_AT_CacheRemoveEntry() { String testBody = "" + System.currentTimeMillis(); String testTitle = "title b"; Blog blog = new Blog(testTitle, testBody); BlogManager blogManager = getBlogManager(); blogManager.createEntry(blog); Blog entryCached = blogManager.getEntryCached(testTitle); assertEquals(entryCached.getBody(), testBody); /* clear from cache using annotation @CacheRemove */ blogManager.clearEntryFromCache(testTitle); /* clear from map, but not from cache */ blogManager.clearEntry(testTitle); entryCached = blogManager.getEntryCached(testTitle); assertNull("Item should removed from the cache and the map", entryCached); }
import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.RequestMapping; @Controller public class BlogsController { @RequestMapping("/blogs") public String index(ModelMap model) { model.addAttribute("blog", new Blog("foobar")); return "blogs/index"; } }
Log.e("USER","1"+blog.getTitle());
@Test public void test_AT_CacheRemoveAll() { String testBody = "" + System.currentTimeMillis(); String testTitle = "title b"; Blog blog = new Blog(testTitle, testBody); BlogManager blogManager = getBlogManager(); blogManager.createEntry(blog); Blog entryCached = blogManager.getEntryCached(testTitle); assertEquals(entryCached.getBody(), testBody); /* clear from map, but not from cache */ blogManager.clearEntry(testTitle); /* clear from cache using annotation @CacheRemoveAll */ blogManager.clearCache(); entryCached = blogManager.getEntryCached(testTitle); assertNull("Item should removed from the cache and the map", entryCached); }
@Test public void test_AT_CacheRemoveAll() { String testBody = "" + System.currentTimeMillis(); String testTitle = "title b"; Blog blog = new Blog(testTitle, testBody); BlogManager blogManager = getBlogManager(); blogManager.createEntry(blog); Blog entryCached = blogManager.getEntryCached(testTitle); assertEquals(entryCached.getBody(), testBody); /* clear from map, but not from cache */ blogManager.clearEntry(testTitle); /* clear from cache using annotation @CacheRemoveAll */ blogManager.clearCache(); entryCached = blogManager.getEntryCached(testTitle); assertNull("Item should removed from the cache and the map", entryCached); }