All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.belladati.sdk.impl.CommentImpl Maven / Gradle / Ivy

Go to download

The BellaDati SDK allows accessing a BellaDati server from 3rd-party applications using Java. This project contains the implementation for Android.

There is a newer version: 0.9.7
Show newest version
package com.belladati.sdk.impl;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import com.belladati.sdk.report.Comment;
import com.belladati.sdk.user.UserInfo;
import com.fasterxml.jackson.databind.JsonNode;

class CommentImpl implements Comment {

	private final String text;
	private final Date date;
	private final UserInfo authorInfo;

	CommentImpl(BellaDatiServiceImpl service, JsonNode json) {
		this.text = json.hasNonNull("text") ? json.get("text").asText() : "";

		this.authorInfo = new UserInfoImpl(service, json.get("authorId").asText(), json.get("author").asText());

		if (json.hasNonNull("when")) {
			SimpleDateFormat format = new SimpleDateFormat(BellaDatiServiceImpl.DATE_TIME_FORMAT);
			Date date;
			try {
				date = format.parse(json.get("when").asText());
			} catch (ParseException e) {
				date = null;
			}
			this.date = date;
		} else {
			this.date = null;
		}
	}

	@Override
	public String getText() {
		return text;
	}

	@Override
	public Date getDateTime() {
		return date != null ? (Date) date.clone() : null;
	}

	@Override
	public UserInfo getAuthorInfo() {
		return authorInfo;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj instanceof CommentImpl) {
			if (authorInfo.equals(((CommentImpl) obj).authorInfo) && text.equals(((CommentImpl) obj).text)) {
				if (date == null) {
					return ((CommentImpl) obj).date == null;
				} else {
					return date.equals(((CommentImpl) obj).date);
				}
			}
		}
		return false;
	}

	@Override
	public int hashCode() {
		return authorInfo.hashCode() ^ text.hashCode();
	}

	@Override
	public String toString() {
		return text;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy