]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.project/src/org/simantics/project/management/GraphBundleRef.java
Support ontology install option trueWhenDeployed also during development
[simantics/platform.git] / bundles / org.simantics.project / src / org / simantics / project / management / GraphBundleRef.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.project.management;
13
14 import java.util.regex.Matcher;
15
16 /**
17  * Graph bundle reference in graph.
18  *
19  * @author Toni Kalajainen <toni.kalajainen@vtt.fi>
20  */
21 public class GraphBundleRef {
22
23         public static GraphBundleRef of(String versionedId) {
24                 Matcher m = GraphBundle.VERSIONED_ID_PATTERN.matcher(versionedId);
25                 String id = m.group(1);
26                 int major = Integer.valueOf( m.group(2) );
27                 return new GraphBundleRef(id, major);
28         }
29         
30         public static GraphBundleRef of(GraphBundle bundle) {
31                 return new GraphBundleRef(bundle.getId(), bundle.getMajor());
32         }
33         
34         public final String id;
35         public final int major;
36         
37         public GraphBundleRef(String id, int major) {
38                 if (id==null) throw new IllegalArgumentException();
39                 this.id = id;
40                 this.major = major;
41         }
42         
43         @Override
44         public int hashCode() {
45                 return id.hashCode() + major;
46         }
47         
48         @Override
49         public boolean equals(Object obj) {
50                 if (obj instanceof GraphBundleRef == false) return false;
51                 GraphBundleRef other = (GraphBundleRef) obj;
52                 return other.id.equals(id) && other.major == major;
53         }
54         
55         @Override
56         public String toString() {
57                 return id+"/"+major;
58         }
59         
60 }
61