/******************************************************************************* * 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()); } } }