]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/contentassist/NamedObject.java
Fixed multiple issues causing dangling references to discarded queries
[simantics/platform.git] / bundles / org.simantics.browsing.ui.swt / src / org / simantics / browsing / ui / swt / contentassist / NamedObject.java
1 /*******************************************************************************
2  * Copyright (c) 2010, 2012 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.browsing.ui.swt.contentassist;
13
14 /**
15  * @author Tuukka Lehtonen
16  */
17 public class NamedObject<T> implements INamedObject {
18
19     private final T object;
20     private final String name;
21     private final String label;
22     private final String description;
23
24     public NamedObject(T object, String name) {
25         this(object, name, name);
26     }
27
28     public NamedObject(T object, String name, String label) {
29         this(object, name, label, null);
30     }
31
32     public NamedObject(T object, String name, String label, String description) {
33         this.object = object;
34         this.name = name;
35         this.label = label;
36         this.description = description;
37     }
38
39     @Override
40     public String getName() {
41         return name;
42     }
43
44     public String getLabel() {
45         return label;
46     }
47
48     public String getDescription() {
49         return description;
50     }
51
52     public T getObject() {
53         return object;
54     }
55
56     @Override
57     public int hashCode() {
58         final int prime = 31;
59         int result = 1;
60         result = prime * result + ((object == null) ? 0 : object.hashCode());
61         return result;
62     }
63
64     @Override
65     public boolean equals(Object obj) {
66         if (this == obj)
67             return true;
68         if (obj == null)
69             return false;
70         if (getClass() != obj.getClass())
71             return false;
72         NamedObject<?> other = (NamedObject<?>) obj;
73         if (object == null) {
74             if (other.object != null)
75                 return false;
76         } else if (!object.equals(other.object))
77             return false;
78         return true;
79     }
80
81     @Override
82     public String toString() {
83         return getClass().getSimpleName() + "[name=" + name + "]";
84     }
85
86 }