]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.common/src/org/simantics/db/common/NamedResource.java
More DB ListenerAdapter abstract to force isDisposed implementation
[simantics/platform.git] / bundles / org.simantics.db.common / src / org / simantics / db / common / NamedResource.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 public class NamedResource implements Comparable<NamedResource> {
20     String   name;
21     Resource resource;
22
23     public NamedResource(String name, Resource resource) {
24         assert(name != null);
25         assert(resource != null);
26         this.name = name;
27         this.resource = resource;
28     }
29
30     public String getName() {
31         return name;
32     }
33
34     public Resource getResource() {
35         return resource;
36     }
37
38     @Override
39     public int compareTo(NamedResource o) {
40         return name.compareToIgnoreCase(o.name);
41     }
42
43     @Override
44     public String toString() {
45         return name;
46     }
47
48     @Override
49     public int hashCode() {
50         return resource.hashCode();
51     }
52
53     @Override
54     public boolean equals(Object obj) {
55         if (this == obj)
56             return true;
57         if (obj == null)
58             return false;
59         if (getClass() != obj.getClass())
60             return false;
61         NamedResource other = (NamedResource) obj;
62         return resource.equals(other.resource) && name.equals(other.name);
63     }
64
65 }