]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.utils.datastructures/testcases/org/simantics/utils/datastructures/map/TestCase.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.utils.datastructures / testcases / org / simantics / utils / datastructures / map / TestCase.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.utils.datastructures.map;
13
14 import java.util.ArrayList;
15 import java.util.Collection;
16 import java.util.Iterator;
17
18 import org.simantics.utils.datastructures.map.AssociativeMap;
19 import org.simantics.utils.datastructures.map.Associativity;
20 import org.simantics.utils.datastructures.map.Tuple;
21
22 public class TestCase {
23
24     public static final String RootLibrary = "http:/";
25     public static final String ConsistsOf = "http://www.simantics.org/Layer0-1.0/ConsistsOf";
26     public static final String Float = "http://www.simantics.org/Layer0-1.0/Float";
27     public static final String InstanceOf = "http://www.simantics.org/Layer0-1.0/InstanceOf";
28     public static final String Relation = "http://www.simantics.org/Layer0-1.0/Relation";
29     public static final String Library = "http://www.simantics.org/Layer0-1.0/Library";
30     public static final String HasValue = "http://www.simantics.org/Layer0-1.0/HasValue";
31
32         public static void main(String[] args) {                
33                 Object c = "Cluster";
34                 Object node = "MyNode";
35                 
36                 Tuple stms[] = new Tuple[] {
37                                 new Tuple(c, RootLibrary, InstanceOf, Library),
38                                 new Tuple(c, RootLibrary, ConsistsOf, node),                    
39                                 new Tuple(c, node, InstanceOf, Float),
40                                 new Tuple(c, node, HasValue, 0.5f)
41                 };
42                                                 
43                 // Test Graph
44                 AssociativeMap g = new AssociativeMap( Associativity.fullAssociativity(4) );            
45                 g.add( stms );
46
47                 Tuple queryAllInstanceOfs = new Tuple(null, null, InstanceOf, null);
48                 Collection<Tuple> list = g.get(queryAllInstanceOfs, new ArrayList<Tuple>());;           
49                 print(list);
50                 
51                 AssociativeMap bijectionMap = 
52                         new AssociativeMap( new Associativity(false, true), new Associativity(true, false), new Associativity(false, false) );
53                 
54                 bijectionMap.add( new Tuple("x", "y") );
55                 Collection<Tuple> res2 = bijectionMap.get(new Tuple("x", "y"), null);;
56                 print( res2 );
57                 
58         }
59         
60         public static void print(Collection<?> c)
61         {
62                 int i=0;
63                 Iterator<?> iter = c.iterator();
64                 while (iter.hasNext()) {
65                         i++;
66                         System.out.println(i+") "+iter.next());
67                 }
68         }
69
70         
71 }
72