Skip to main content
summaryrefslogtreecommitdiffstats
blob: ec887af978281dac01e1540fab82dcde7b6d0315 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/****************************************************************************
 * Copyright (c) 2017, 2018 Remain Software
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Wim Jongman <wim.jongman@remainsoftware.com> - initial API and implementation
 *****************************************************************************/
package org.eclipse.tips.core;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * This is the base Tip class of the UI agnostic Tip framework. You might want
 * to check specializations of this class that may make your life easier.
 *
 */
public abstract class Tip {

	private String providerId;

	private final List<TipAction> fActions = new ArrayList<>();

	/**
	 * Constructor for a Tip. For the best user experience, Tips should be created
	 * really fast.
	 *
	 */
	public Tip(String providerId) {
		this.providerId = providerId;
	}

	/**
	 * @return the id of the provider that created this tip.
	 */
	public String getProviderId() {
		return providerId;
	}

	/**
	 * A getter for a list of {@link TipAction}s for this tip. Clients may override
	 * or provide the actions through the constructor.
	 *
	 * @return the list of actions, never null but could be empty.
	 */
	public List<TipAction> getActions() {
		return fActions;
	}

	/**
	 * Return the publish date of the tip. The UI could decide to server newer tips
	 * first.
	 *
	 * @return the date this tip was published which may not be null.
	 */
	public abstract Date getCreationDate();

	/**
	 * @return the subject which may not be null.
	 */
	public abstract String getSubject();

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((getCreationDate() == null) ? 0 : getCreationDate().hashCode());
		result = prime * result + ((providerId == null) ? 0 : providerId.hashCode());
		result = prime * result + ((getSubject() == null) ? 0 : getSubject().hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		Tip other = (Tip) obj;
		if (getCreationDate() == null) {
			if (other.getCreationDate() != null) {
				return false;
			}
		} else if (!getCreationDate().equals(other.getCreationDate())) {
			return false;
		}
		if (providerId == null) {
			if (other.providerId != null) {
				return false;
			}
		} else if (!providerId.equals(other.providerId)) {
			return false;
		}
		if (getSubject() == null) {
			if (other.getSubject() != null) {
				return false;
			}
		} else if (!getSubject().equals(other.getSubject())) {
			return false;
		}
		return true;
	}
}

Back to the top