]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.utils.datastructures/testcases/org/simantics/utils/datastructures/map/TestCase.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.utils.datastructures / testcases / org / simantics / utils / datastructures / map / TestCase.java
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
3  * in Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.utils.datastructures.map;\r
13 \r
14 import java.util.ArrayList;\r
15 import java.util.Collection;\r
16 import java.util.Iterator;\r
17 \r
18 import org.simantics.utils.datastructures.map.AssociativeMap;\r
19 import org.simantics.utils.datastructures.map.Associativity;\r
20 import org.simantics.utils.datastructures.map.Tuple;\r
21 \r
22 public class TestCase {\r
23 \r
24     public static final String RootLibrary = "http:/";\r
25     public static final String ConsistsOf = "http://www.simantics.org/Layer0-1.0/ConsistsOf";\r
26     public static final String Float = "http://www.simantics.org/Layer0-1.0/Float";\r
27     public static final String InstanceOf = "http://www.simantics.org/Layer0-1.0/InstanceOf";\r
28     public static final String Relation = "http://www.simantics.org/Layer0-1.0/Relation";\r
29     public static final String Library = "http://www.simantics.org/Layer0-1.0/Library";\r
30     public static final String HasValue = "http://www.simantics.org/Layer0-1.0/HasValue";\r
31 \r
32         public static void main(String[] args) {                \r
33                 Object c = "Cluster";\r
34                 Object node = "MyNode";\r
35                 \r
36                 Tuple stms[] = new Tuple[] {\r
37                                 new Tuple(c, RootLibrary, InstanceOf, Library),\r
38                                 new Tuple(c, RootLibrary, ConsistsOf, node),                    \r
39                                 new Tuple(c, node, InstanceOf, Float),\r
40                                 new Tuple(c, node, HasValue, 0.5f)\r
41                 };\r
42                                                 \r
43                 // Test Graph\r
44                 AssociativeMap g = new AssociativeMap( Associativity.fullAssociativity(4) );            \r
45                 g.add( stms );\r
46 \r
47                 Tuple queryAllInstanceOfs = new Tuple(null, null, InstanceOf, null);\r
48                 Collection<Tuple> list = g.get(queryAllInstanceOfs, new ArrayList<Tuple>());;           \r
49                 print(list);\r
50                 \r
51                 AssociativeMap bijectionMap = \r
52                         new AssociativeMap( new Associativity(false, true), new Associativity(true, false), new Associativity(false, false) );\r
53                 \r
54                 bijectionMap.add( new Tuple("x", "y") );\r
55                 Collection<Tuple> res2 = bijectionMap.get(new Tuple("x", "y"), null);;\r
56                 print( res2 );\r
57                 \r
58         }\r
59         \r
60         public static void print(Collection<?> c)\r
61         {\r
62                 int i=0;\r
63                 Iterator<?> iter = c.iterator();\r
64                 while (iter.hasNext()) {\r
65                         i++;\r
66                         System.out.println(i+") "+iter.next());\r
67                 }\r
68         }\r
69 \r
70         \r
71 }\r
72 \r