X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.utils.datastructures%2Ftestcases%2Forg%2Fsimantics%2Futils%2Fdatastructures%2Fmap%2FTestCase.java;h=e7dd2edeee3b7e8b535114173d169983e514b129;hb=7a71c1866a7404cd39c921c85c160094eeda410c;hp=1e350c04d72c627417827cc262a00d934dd3f60f;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.utils.datastructures/testcases/org/simantics/utils/datastructures/map/TestCase.java b/bundles/org.simantics.utils.datastructures/testcases/org/simantics/utils/datastructures/map/TestCase.java index 1e350c04d..e7dd2edee 100644 --- a/bundles/org.simantics.utils.datastructures/testcases/org/simantics/utils/datastructures/map/TestCase.java +++ b/bundles/org.simantics.utils.datastructures/testcases/org/simantics/utils/datastructures/map/TestCase.java @@ -1,72 +1,72 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.utils.datastructures.map; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; - -import org.simantics.utils.datastructures.map.AssociativeMap; -import org.simantics.utils.datastructures.map.Associativity; -import org.simantics.utils.datastructures.map.Tuple; - -public class TestCase { - - public static final String RootLibrary = "http:/"; - public static final String ConsistsOf = "http://www.simantics.org/Layer0-1.0/ConsistsOf"; - public static final String Float = "http://www.simantics.org/Layer0-1.0/Float"; - public static final String InstanceOf = "http://www.simantics.org/Layer0-1.0/InstanceOf"; - public static final String Relation = "http://www.simantics.org/Layer0-1.0/Relation"; - public static final String Library = "http://www.simantics.org/Layer0-1.0/Library"; - public static final String HasValue = "http://www.simantics.org/Layer0-1.0/HasValue"; - - public static void main(String[] args) { - Object c = "Cluster"; - Object node = "MyNode"; - - Tuple stms[] = new Tuple[] { - new Tuple(c, RootLibrary, InstanceOf, Library), - new Tuple(c, RootLibrary, ConsistsOf, node), - new Tuple(c, node, InstanceOf, Float), - new Tuple(c, node, HasValue, 0.5f) - }; - - // Test Graph - AssociativeMap g = new AssociativeMap( Associativity.fullAssociativity(4) ); - g.add( stms ); - - Tuple queryAllInstanceOfs = new Tuple(null, null, InstanceOf, null); - Collection list = g.get(queryAllInstanceOfs, new ArrayList());; - print(list); - - AssociativeMap bijectionMap = - new AssociativeMap( new Associativity(false, true), new Associativity(true, false), new Associativity(false, false) ); - - bijectionMap.add( new Tuple("x", "y") ); - Collection res2 = bijectionMap.get(new Tuple("x", "y"), null);; - print( res2 ); - - } - - public static void print(Collection c) - { - int i=0; - Iterator iter = c.iterator(); - while (iter.hasNext()) { - i++; - System.out.println(i+") "+iter.next()); - } - } - - -} - +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.utils.datastructures.map; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; + +import org.simantics.utils.datastructures.map.AssociativeMap; +import org.simantics.utils.datastructures.map.Associativity; +import org.simantics.utils.datastructures.map.Tuple; + +public class TestCase { + + public static final String RootLibrary = "http:/"; + public static final String ConsistsOf = "http://www.simantics.org/Layer0-1.0/ConsistsOf"; + public static final String Float = "http://www.simantics.org/Layer0-1.0/Float"; + public static final String InstanceOf = "http://www.simantics.org/Layer0-1.0/InstanceOf"; + public static final String Relation = "http://www.simantics.org/Layer0-1.0/Relation"; + public static final String Library = "http://www.simantics.org/Layer0-1.0/Library"; + public static final String HasValue = "http://www.simantics.org/Layer0-1.0/HasValue"; + + public static void main(String[] args) { + Object c = "Cluster"; + Object node = "MyNode"; + + Tuple stms[] = new Tuple[] { + new Tuple(c, RootLibrary, InstanceOf, Library), + new Tuple(c, RootLibrary, ConsistsOf, node), + new Tuple(c, node, InstanceOf, Float), + new Tuple(c, node, HasValue, 0.5f) + }; + + // Test Graph + AssociativeMap g = new AssociativeMap( Associativity.fullAssociativity(4) ); + g.add( stms ); + + Tuple queryAllInstanceOfs = new Tuple(null, null, InstanceOf, null); + Collection list = g.get(queryAllInstanceOfs, new ArrayList());; + print(list); + + AssociativeMap bijectionMap = + new AssociativeMap( new Associativity(false, true), new Associativity(true, false), new Associativity(false, false) ); + + bijectionMap.add( new Tuple("x", "y") ); + Collection res2 = bijectionMap.get(new Tuple("x", "y"), null);; + print( res2 ); + + } + + public static void print(Collection c) + { + int i=0; + Iterator iter = c.iterator(); + while (iter.hasNext()) { + i++; + System.out.println(i+") "+iter.next()); + } + } + + +} +