Author: bbrossaud Date: 2010-05-11 12:11:30 +0200 (Tue, 11 May 2010) New Revision: 18 Url: http://chorem.org/repositories/revision/bow/18 Log: added the BookmarkActions comments Modified: trunk/src/main/java/org/chorem/bow/BookmarkActions.java Modified: trunk/src/main/java/org/chorem/bow/BookmarkActions.java =================================================================== --- trunk/src/main/java/org/chorem/bow/BookmarkActions.java 2010-05-11 09:14:13 UTC (rev 17) +++ trunk/src/main/java/org/chorem/bow/BookmarkActions.java 2010-05-11 10:11:30 UTC (rev 18) @@ -20,16 +20,25 @@ */ public class BookmarkActions { - protected List<Bookmark> bookmarks = new ArrayList<Bookmark>(); - protected Map<String, Integer> tagsCloud = new HashMap<String, Integer>(); - protected List<String> tagsSearch = new ArrayList<String>(); + protected List<Bookmark> bookmarks = new ArrayList<Bookmark>(); // bookmarks which contain the search tags + protected Map<String, Integer> tagCloud = new HashMap<String, Integer>(); // associate a tag with its frequency + // among all bookmarks + protected List<String> tagsSearch = new ArrayList<String>(); // contains the tags taped in the search field protected int tmax = -1; protected int tmin = -1; + + /* @param url String which contains the bookmark url + * @param nameAndTags String which contains the name and the tags of the + bookmark separated by '|' ==> name|tag1 tag2... + * @param user bookmark user + * @return null if all fields are not correctly filled + * @return Bookmark the website bookmark + */ public Bookmark createBookmark(String url, String nameAndTags, User user) { - int nameIndex = nameAndTags.indexOf('|'); - if (nameIndex < 0) { + int nameIndex = nameAndTags.indexOf('|'); // get the index name of the website + if (nameIndex < 0) { // nameAndTags ==> name|tag1 tag2 tag3... return null; } Bookmark bookmark = (Bookmark) new BookmarkImpl(); @@ -37,45 +46,48 @@ String link = url.trim(); bookmark.setLink(link); - String name = nameAndTags.substring(0, nameIndex); + String name = nameAndTags.substring(0, nameIndex); // get the website name name = name.trim(); - bookmark.setDescription(name); + bookmark.setDescription(name); // set the description (website name) - String tags = nameAndTags.substring(nameIndex + 1); + String tags = nameAndTags.substring(nameIndex + 1); // get tags, +1 because of '|' tags = tags.trim(); - String[] tagsTab = tags.split("\\s+"); + String[] tagsTab = tags.split("\\s+"); // put the tags in an array + if (tagsTab.length == 0) + return null; for (int i = 0; i < tagsTab.length; ++i) { - bookmark.addTags(tagsTab[i]); + bookmark.addTags(tagsTab[i]); // Added tag for each rank (one tag by rank) } - bookmark.setEmail(user.getEmail()); - bookmark.setDate(new Date()); + bookmark.setEmail(user.getEmail()); // set the email (user name) + bookmark.setDate(new Date()); // set the date return bookmark; } - public List<Bookmark> getBookmarks() { - return bookmarks; - } - public void createTagsCloud() { - tagsCloud.clear(); + tagCloud.clear(); if (tagsSearch.isEmpty()) { - fillTagsCloud(); + fillTagsCloud(); // if nothing is taped in the search field, the tags cloud must contains all tags } else { fillTagsCloudBySearch(); } + this.defineTValues(); // define t values for the font } + + /* @param bookmark user bookmark + * @return void + */ protected void addBookmarkTagsToTagCloud(Bookmark bookmark) { - Set<String> tags = bookmark.getTags(); + Set<String> tags = bookmark.getTags(); // bookmark tags for (String tag : tags) { - if (!tagsSearch.contains(tag)) { - if (tagsCloud.containsKey(tag)) { - Integer count = tagsCloud.get(tag); + if (!tagsSearch.contains(tag)) { // the tags cloud mustn't contained the tags taped in the search field + if (tagCloud.containsKey(tag)) { // check if it contains the tag + Integer count = tagCloud.get(tag); ++count; - tagsCloud.put(tag, count); + tagCloud.put(tag, count); } else { - tagsCloud.put(tag, 1); + tagCloud.put(tag, 1); } } } @@ -88,34 +100,33 @@ } public void fillTagsCloudBySearch() { - tagsCloud.clear(); + tagCloud.clear(); for (String tag : tagsSearch) { List<Bookmark> bookmarksList = new ArrayList<Bookmark>(bookmarks); for (Bookmark bookmark : bookmarksList) { if (bookmark.getTags().contains(tag) == false) { - bookmarks.remove(bookmark); + bookmarks.remove(bookmark); // Delete bookmark which doesn't contain the tags from the search field } else { addBookmarkTagsToTagCloud(bookmark); } } } - this.defineTValues(); } protected void defineTValues() { - Collection values = tagsCloud.values(); + Collection values = tagCloud.values(); Iterator it = values.iterator(); - tmax = -1; - tmin = -1; + tmax = -1; // correspond to the most tag frequency in the tag cloud + tmin = -1; // correspond to the less tag frequency in the tag cloud int value; while (it.hasNext()) { value = (Integer) it.next(); - if (tmax < value) { - tmax = value; + if (tmax < value) { // search the most tag frequancy + tmax = value; } if (tmin == -1) { tmin = value; - } else if (tmin > value) { + } else if (tmin > value) { // search less tag frequency tmin = value; } } @@ -136,37 +147,41 @@ } } + public void reset() { + bookmarks.clear(); + tagCloud.clear(); + tagsSearch.clear(); + tmax = -1; + tmin = -1; + } + + public void setBookmarks(List<Bookmark> bookmarksList) { + List<Bookmark> newList = new ArrayList(bookmarksList); + bookmarks = newList; + } + public String getSearchLine() { - return StringUtil.join(tagsSearch, " ", true); + return StringUtil.join(tagsSearch, " ", true); // return the search line created with the tags } public int getFont(int ti) { int font = 1; if (tmax > tmin) { - font = (15 * (ti - tmin)) / (tmax - tmin); + font = (15 * (ti - tmin)) / (tmax - tmin); // get the font size for a tag frequency } return font; } - public void reset() { - bookmarks.clear(); - tagsCloud.clear(); - tagsSearch.clear(); - tmax = -1; - tmin = -1; - } - public Map<String, Integer> getTagsCloud() { - return tagsCloud; + return tagCloud; } public List<String> getTagsSearch() { return tagsSearch; } - public void setBookmarks(List<Bookmark> bookmarksList) { - List<Bookmark> newList = new ArrayList(bookmarksList); - bookmarks = newList; + public List<Bookmark> getBookmarks() { + return bookmarks; } public int getTmin() {
participants (1)
-
bbrossaudï¼ users.chorem.org