]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.common/src/org/simantics/db/common/NamedTypedResource.java
Fixed multiple issues causing dangling references to discarded queries
[simantics/platform.git] / bundles / org.simantics.db.common / src / org / simantics / db / common / NamedTypedResource.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 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.db.common;
13
14 import org.simantics.db.Resource;
15
16 /**
17  * 
18  */
19 final public class NamedTypedResource implements Comparable<NamedTypedResource> {
20         
21     final String   name;
22     final Resource resource;
23     final Resource type;
24
25     public NamedTypedResource(String name, Resource resource, Resource type) {
26         assert(name != null);
27         assert(resource != null);
28         assert(type != null);
29         this.name = name;
30         this.resource = resource;
31         this.type = type;
32     }
33
34     public String getName() {
35         return name;
36     }
37
38     public Resource getResource() {
39         return resource;
40     }
41
42     public Resource getType() {
43         return type;
44     }
45
46     @Override
47     public int compareTo(NamedTypedResource o) {
48         return name.compareToIgnoreCase(o.name);
49     }
50
51     @Override
52     public String toString() {
53         return name;
54     }
55
56     @Override
57     public int hashCode() {
58         return resource.hashCode();
59     }
60
61     @Override
62     public boolean equals(Object obj) {
63         if (this == obj)
64             return true;
65         if (obj == null)
66             return false;
67         if (getClass() != obj.getClass())
68             return false;
69         NamedTypedResource other = (NamedTypedResource) obj;
70         return resource.equals(other.resource) && type.equals(other.type) && name.equals(other.name);
71     }
72
73 }