]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.layer0.utils/src/org/simantics/layer0/utils/instantiation/MultiInstance.java
Templates for creating SCL values
[simantics/platform.git] / bundles / org.simantics.layer0.utils / src / org / simantics / layer0 / utils / instantiation / MultiInstance.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.layer0.utils.instantiation;
13
14 import java.util.Collection;
15
16 import org.simantics.db.Resource;
17
18 /**
19  * Helper class for creating multi-instances.
20  * Note : This does NOT check conflicting requirements. 
21  * 
22  * @author Marko Luukkainen <Marko.Luukkainen@vtt.fi>
23  *
24  */
25 public class MultiInstance extends Instance {
26         
27         public MultiInstance(Collection<Instance> instances, Resource instanceOf) {
28                 for (Instance i : instances) {
29                         if (i.equals != null)
30                                 throw new UnsupportedOperationException("Don't know how to handle equal instances.");
31                         for (RelatedInstance ri : i.relatedInstances) {
32                                 boolean contains = false;
33                                 for (RelatedInstance cri : relatedInstances) {
34                                         if (cri.relation == ri.relation &&
35                                                 cri.relation != instanceOf) {
36                                                 contains = true;
37                                                 break;
38                                         }
39                                 }
40                                 if(!contains) {
41                                         relatedInstances.add(ri);
42                                 }
43                         }
44                 }
45         }
46
47 }