001/* 002 * (C) Copyright 2006-2012 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Thomas Roger <[email protected]> 018 */ 019 020package org.nuxeo.ecm.rating.api; 021 022import java.io.Serializable; 023import java.util.HashMap; 024import java.util.Map; 025 026/** 027 * An object storing the like / dislike status of an activity object. 028 * <p> 029 * It may also contain the like status for a {@code username}: 030 * <ul> 031 * <li>LIKED</li> 032 * <li>DISLIKED</li> 033 * <li>UNKNOWN</li> 034 * </ul> 035 * 036 * @author <a href="mailto:[email protected]">Thomas Roger</a> 037 * @since 5.6 038 */ 039public class LikeStatus { 040 041 /** 042 * Constant used when the {@code username} liked the {@code activityObject} . 043 */ 044 public static final int LIKED = 1; 045 046 /** 047 * Constant used when the {@code username} disliked the {@code activityObject}. 048 */ 049 public static final int DISLIKED = -1; 050 051 /** 052 * Constant used when the {@code username} didn't like nor dislike the {@code activityObject}. 053 */ 054 public static final int UNKNOWN = 0; 055 056 public final String activityObject; 057 058 public final long likesCount; 059 060 public final long dislikesCount; 061 062 public final String username; 063 064 public final int userLikeStatus; 065 066 /** 067 * Creates a {@code LikeStatus} with the like status for the specified {@code username}. 068 * 069 * @param activityObject the activity object for which this {@code LikeStatus} apply 070 * @param likesCount the likes count for the activity object 071 * @param dislikesCount the dislikes count for the activity object 072 * @param username the username on which the {@code userLikeStatus} apply 073 * @param userLikeStatus the like status for the {@code username} 074 */ 075 public LikeStatus(String activityObject, long likesCount, long dislikesCount, String username, int userLikeStatus) { 076 this.activityObject = activityObject; 077 this.likesCount = likesCount; 078 this.dislikesCount = dislikesCount; 079 this.username = username; 080 this.userLikeStatus = userLikeStatus; 081 } 082 083 /** 084 * Creates a {@code LikeStatus} without the like status for a {@code username}. 085 * 086 * @param activityObject the activity object for which this {@code LikeStatus} apply 087 * @param likesCount the likes count for the activity object 088 * @param dislikesCount the dislikes count for the activity object 089 */ 090 public LikeStatus(String activityObject, long likesCount, long dislikesCount) { 091 this(activityObject, likesCount, dislikesCount, null, UNKNOWN); 092 } 093 094 /** 095 * Returns a {@code Map} of attributes for this {@code LikeStatus}. 096 */ 097 @SuppressWarnings("boxing") 098 public Map<String, Serializable> toMap() { 099 Map<String, Serializable> map = new HashMap<String, Serializable>(); 100 map.put("activityObject", activityObject); 101 map.put("likesCount", likesCount); 102 map.put("dislikesCount", dislikesCount); 103 map.put("username", username); 104 map.put("userLikeStatus", userLikeStatus); 105 return map; 106 } 107 108}