001// Generated by delombok at Thu Aug 13 13:56:44 UTC 2026 002/* 003 * Copyright (c) 2010-2026 Mark Allen, Norbert Bartels. 004 * 005 * Permission is hereby granted, free of charge, to any person obtaining a copy 006 * of this software and associated documentation files (the "Software"), to deal 007 * in the Software without restriction, including without limitation the rights 008 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 009 * copies of the Software, and to permit persons to whom the Software is 010 * furnished to do so, subject to the following conditions: 011 * 012 * The above copyright notice and this permission notice shall be included in 013 * all copies or substantial portions of the Software. 014 * 015 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 016 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 017 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 018 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 019 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 020 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 021 * THE SOFTWARE. 022 */ 023package com.restfb.types; 024 025import static java.util.Collections.unmodifiableList; 026import java.util.ArrayList; 027import java.util.List; 028import com.restfb.Facebook; 029import com.restfb.JsonMapper.JsonMappingCompleted; 030import com.restfb.json.Json; 031import com.restfb.json.JsonObject; 032 033/** 034 * Represents the <a href="https://developers.facebook.com/docs/graph-api/reference/object/comments">Comments Graph API 035 * type</a>. 036 * 037 * <p> 038 * Please request '{id}/comments?summary=true' explicitly if you would like the summary field which contains the count 039 * (now called 'total_count') 040 * </p> 041 * 042 * @author <a href="http://restfb.com">Mark Allen</a> 043 */ 044public class Comments extends AbstractFacebookType { 045 /** 046 * The count of comments on this node. 047 * 048 * <p> 049 * It is important to note that this value is changed depending on the {@code filter} modifier being used (where 050 * comment replies are available): 051 * </p> 052 * <ul> 053 * <li>if filter is {@code stream} then total_count will be a count of all comments (including replies) on the node. 054 * </li> 055 * <li>if filter is {@code toplevel} then total_count will be a count of all top-level comments on the node.</li> 056 * </ul> 057 * <p> 058 * {@code total_count} can be greater than or equal to the actual number of comments returned due to privacy or 059 * deletion 060 * </p> 061 * <p> 062 * Please request '{id}/comments?summary=true' explicitly if you would like the summary field which contains the count 063 * (now called 'total_count') 064 * </p> 065 */ 066 @Facebook("total_count") 067 private Long totalCount = 0L; 068 /** 069 * Order in which comments were returned. 070 * 071 * <p> 072 * <code>ranked</code> indicates the most interesting comments are sorted first.<br> 073 * <code>chronological</code> indicates comments are sorted by the oldest comments first. 074 * </p> 075 */ 076 private String order; 077 private Boolean canComment; 078 @Facebook("comment_order") 079 private String openGraphCommentOrder; 080 @Facebook("can_comment") 081 private Boolean openGraphCanComment; 082 @Facebook 083 private Long count = 0L; 084 @Facebook 085 private String summary = null; 086 @Facebook 087 private List<Comment> data = new ArrayList<>(); 088 private static final long serialVersionUID = 1L; 089 090 /** 091 * The comments. 092 * 093 * @return The comments. 094 */ 095 public List<Comment> getData() { 096 return unmodifiableList(data); 097 } 098 099 /** 100 * Adds a comment 101 * 102 * @param comment 103 * the comment that should be added 104 * @return true if the comment was added, false otherwise 105 */ 106 public boolean addData(Comment comment) { 107 return data.add(comment); 108 } 109 110 /** 111 * remove a comment 112 * 113 * @param comment 114 * the comment that should be removed 115 * @return true if the comment was removed, false otherwise 116 */ 117 public boolean removeData(Comment comment) { 118 return data.remove(comment); 119 } 120 121 @JsonMappingCompleted 122 private void fillFields() { 123 JsonObject summaryObject = null; 124 if (summary != null) { 125 summaryObject = Json.parse(summary).asObject(); 126 } 127 fillTotalCount(summaryObject); 128 fillOrder(summaryObject); 129 fillCanComment(summaryObject); 130 } 131 132 /** 133 * set total count if summary is present 134 */ 135 private void fillTotalCount(JsonObject summary) { 136 if (totalCount == 0 && summary != null && summary.get("total_count") != null) { 137 totalCount = summary.getLong("total_count", totalCount); 138 } 139 if (totalCount == 0 && count != 0) { 140 totalCount = count; 141 } 142 } 143 144 /** 145 * set the order the comments are sorted 146 */ 147 private void fillOrder(JsonObject summary) { 148 if (summary != null) { 149 order = summary.getString("order", order); 150 } 151 if (order == null && openGraphCommentOrder != null) { 152 order = openGraphCommentOrder; 153 } 154 } 155 156 /** 157 * set the can_comment 158 */ 159 private void fillCanComment(JsonObject summary) { 160 if (summary != null && summary.get("can_comment") != null) { 161 canComment = summary.get("can_comment").asBoolean(); 162 } 163 if (canComment == null && openGraphCanComment != null) { 164 canComment = openGraphCanComment; 165 } 166 } 167 168 /** 169 * The count of comments on this node. 170 * 171 * <p> 172 * It is important to note that this value is changed depending on the {@code filter} modifier being used (where 173 * comment replies are available): 174 * </p> 175 * <ul> 176 * <li>if filter is {@code stream} then total_count will be a count of all comments (including replies) on the node. 177 * </li> 178 * <li>if filter is {@code toplevel} then total_count will be a count of all top-level comments on the node.</li> 179 * </ul> 180 * <p> 181 * {@code total_count} can be greater than or equal to the actual number of comments returned due to privacy or 182 * deletion 183 * </p> 184 * <p> 185 * Please request '{id}/comments?summary=true' explicitly if you would like the summary field which contains the count 186 * (now called 'total_count') 187 * </p> 188 * 189 * @return The number of comments. 190 */ 191 @java.lang.SuppressWarnings("all") 192 @lombok.Generated 193 public Long getTotalCount() { 194 return this.totalCount; 195 } 196 197 /** 198 * The count of comments on this node. 199 * 200 * <p> 201 * It is important to note that this value is changed depending on the {@code filter} modifier being used (where 202 * comment replies are available): 203 * </p> 204 * <ul> 205 * <li>if filter is {@code stream} then total_count will be a count of all comments (including replies) on the node. 206 * </li> 207 * <li>if filter is {@code toplevel} then total_count will be a count of all top-level comments on the node.</li> 208 * </ul> 209 * <p> 210 * {@code total_count} can be greater than or equal to the actual number of comments returned due to privacy or 211 * deletion 212 * </p> 213 * <p> 214 * Please request '{id}/comments?summary=true' explicitly if you would like the summary field which contains the count 215 * (now called 'total_count') 216 * </p> 217 */ 218 @java.lang.SuppressWarnings("all") 219 @lombok.Generated 220 public void setTotalCount(final Long totalCount) { 221 this.totalCount = totalCount; 222 } 223 224 /** 225 * Order in which comments were returned. 226 * 227 * <p> 228 * <code>ranked</code> indicates the most interesting comments are sorted first.<br> 229 * <code>chronological</code> indicates comments are sorted by the oldest comments first. 230 * </p> 231 * 232 * @return the order of the comments 233 */ 234 @java.lang.SuppressWarnings("all") 235 @lombok.Generated 236 public String getOrder() { 237 return this.order; 238 } 239 240 /** 241 * Order in which comments were returned. 242 * 243 * <p> 244 * <code>ranked</code> indicates the most interesting comments are sorted first.<br> 245 * <code>chronological</code> indicates comments are sorted by the oldest comments first. 246 * </p> 247 */ 248 @java.lang.SuppressWarnings("all") 249 @lombok.Generated 250 public void setOrder(final String order) { 251 this.order = order; 252 } 253 254 @java.lang.SuppressWarnings("all") 255 @lombok.Generated 256 public Boolean getCanComment() { 257 return this.canComment; 258 } 259 260 @java.lang.SuppressWarnings("all") 261 @lombok.Generated 262 public void setCanComment(final Boolean canComment) { 263 this.canComment = canComment; 264 } 265}