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