]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/environment/specification/EnvironmentSpecification.java
Fixed diagram copy/paste implementations to re-identify diagram elements
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / environment / specification / EnvironmentSpecification.java
1 package org.simantics.scl.compiler.environment.specification;
2
3 import java.util.ArrayList;
4
5 import org.simantics.scl.compiler.module.ImportDeclaration;
6
7 public class EnvironmentSpecification {
8     public final ArrayList<ImportDeclaration> imports = new ArrayList<ImportDeclaration>();
9     
10     public void importModule(String moduleName, String localName) {
11         imports.add(new ImportDeclaration(moduleName, localName));
12     }
13     
14     public static EnvironmentSpecification of(String ... strings) {
15         if(strings.length % 2 != 0)
16             throw new IllegalArgumentException("Expected even number of parameters.");
17         EnvironmentSpecification spec = new EnvironmentSpecification();
18         for(int i=0;i<strings.length;i+=2)
19             spec.importModule(strings[i], strings[i+1]);
20         return spec;
21     }
22
23     @Override
24     public int hashCode() {
25         final int prime = 31;
26         int result = 1;
27         result = prime * result + ((imports == null) ? 0 : imports.hashCode());
28         return result;
29     }
30
31     @Override
32     public boolean equals(Object obj) {
33         if (this == obj)
34             return true;
35         if (obj == null)
36             return false;
37         if (getClass() != obj.getClass())
38             return false;
39         EnvironmentSpecification other = (EnvironmentSpecification) obj;
40         if (imports == null) {
41             if (other.imports != null)
42                 return false;
43         } else if (!imports.equals(other.imports))
44             return false;
45         return true;
46     }
47 }