List of usage examples for java.util Map containsValue
boolean containsValue(Object value);
From source file:org.drools.semantics.builder.model.inference.DelegateInferenceStrategy.java
private Map<OWLClassExpression, OWLClassExpression> buildAliasesForEquivalentClasses(OWLOntology ontoDescr) { Map<OWLClassExpression, OWLClassExpression> aliases = new HashMap<OWLClassExpression, OWLClassExpression>(); Set<OWLEquivalentClassesAxiom> pool = new HashSet<OWLEquivalentClassesAxiom>(); Set<OWLEquivalentClassesAxiom> temp = new HashSet<OWLEquivalentClassesAxiom>(); for (OWLClass klass : ontoDescr.getClassesInSignature(true)) { for (OWLEquivalentClassesAxiom klassEq : ontoDescr.getEquivalentClassesAxioms(klass)) { for (OWLEquivalentClassesAxiom eq2 : klassEq.asPairwiseAxioms()) { pool.add(eq2);//from w ww. j ava 2 s.c o m } } } boolean stable = false; while (!stable) { stable = true; temp.addAll(pool); for (OWLEquivalentClassesAxiom eq2 : pool) { List<OWLClassExpression> pair = eq2.getClassExpressionsAsList(); OWLClassExpression first = pair.get(0); OWLClassExpression secnd = pair.get(1); OWLClassExpression removed = null; if (aliases.containsValue(first)) { // add to existing eqSet, put reversed // A->X, add X->C ==> A->X, C->X removed = aliases.put(secnd, first); if (removed != null) { logger.warn("DUPLICATE KEY WHILE RESOLVING EQUALITIES" + removed + " for value " + eq2); } stable = false; temp.remove(eq2); } else if (aliases.containsValue(secnd)) { // add to existing eqSet, put as is // A->X, add C->X ==> A->X, C->X removed = aliases.put(first, secnd); if (removed != null) { logger.warn("DUPLICATE KEY WHILE RESOLVING EQUALITIES" + removed + " for value " + eq2); } stable = false; temp.remove(eq2); } else if (aliases.containsKey(first)) { // apply transitivity, reversed // A->X, add A->C ==> A->X, C->X removed = aliases.put(secnd, aliases.get(first)); if (removed != null) { logger.warn("DUPLICATE KEY WHILE RESOLVING EQUALITIES" + removed + " for value " + eq2); } stable = false; temp.remove(eq2); } else if (aliases.containsKey(secnd)) { // apply transitivity, as is // A->X, add C->A ==> A->X, C->X removed = aliases.put(first, aliases.get(secnd)); if (removed != null) { logger.warn("DUPLICATE KEY WHILE RESOLVING EQUALITIES" + removed + " for value " + eq2); } stable = false; temp.remove(eq2); } else if (!first.isAnonymous()) { removed = aliases.put(secnd, first); if (removed != null) { logger.warn("DUPLICATE KEY WHILE RESOLVING EQUALITIES" + removed + " for value " + eq2); } stable = false; temp.remove(eq2); } else if (!secnd.isAnonymous()) { removed = aliases.put(first, secnd); if (removed != null) { logger.warn("DUPLICATE KEY WHILE RESOLVING EQUALITIES" + removed + " for value " + eq2); } stable = false; temp.remove(eq2); } else { // both anonymous } } pool.clear(); pool.addAll(temp); } if (!pool.isEmpty()) { logger.error("COULD NOT RESOLVE ANON=ANON EQUALITIES " + pool); for (OWLEquivalentClassesAxiom eq2 : pool) { List<OWLClassExpression> l = eq2.getClassExpressionsAsList(); if (!(l.get(0).isAnonymous() && l.get(1).isAnonymous())) { logger.error(" EQUALITY WAS NOT RESOLVED " + l); } } } if (logger.isInfoEnabled()) { logger.info( "----------------------------------------------------------------------- " + aliases.size()); for (Map.Entry<OWLClassExpression, OWLClassExpression> entry : aliases.entrySet()) { logger.trace(entry.getKey() + " == " + entry.getValue()); } logger.info("-----------------------------------------------------------------------"); } for (Map.Entry<OWLClassExpression, OWLClassExpression> entry : aliases.entrySet()) { OWLClassExpression key = entry.getKey(); OWLClassExpression val = entry.getValue(); if (!reverseAliases.containsKey(val)) { reverseAliases.put(val, new HashSet<OWLClassExpression>()); } reverseAliases.get(val).add(key); } return aliases; }
From source file:pltag.parser.ParsingTask.java
private ArrayList<ChartEntry> match(ElementaryStringTree tree, TreeState elemtreetreeState, Chart chart, ChartEntry chartEntry, String[] origPosTags, int timestamp) { TreeState preftreetreeState = chartEntry.getTreeState(); ArrayList<ShadowStringTree> shadowtrees = preftreetreeState.getShadowTrees(); ArrayList<ChartEntry> chartentries = new ArrayList<ChartEntry>(); for (ShadowStringTree shadowtree : shadowtrees) { for (Integer rootnode : shadowtree.getShadowSourceTreesRootList()) { if (shadowtree.getTreeOrigIndex().getCategory(rootnode).equals(tree.getCategory(tree.getRoot()))) // if (shadowtree.getTreeOrigIndex().getCategory(Integer.toString(rootnode)).equals(tree.getCategory(tree.getRoot()))) {/*from w ww . j a v a 2 s. c o m*/ Map<Integer, Integer> coveredNodes = getCoveredNodes(tree, tree.getRoot(), shadowtree, rootnode, preftreetreeState.getFringe().getSubstNode(), opts.verbose); // HashMap<Integer, Integer> coveredNodes = getCoveredNodes(tree, tree.getRoot(), shadowtree, Integer.toString(rootnode), preftreetreeState.getFringe().getSubstNode()); //All nodes that are not in coveredNodes must be after anchor. // if a tree contains a trace, it can verify more than one index. //Integer[] indexlist if (coveredNodes == null) { continue; } ArrayList<Byte> pattern = checkTreeEquivalence(shadowtree, rootnode, tree, coveredNodes); //all subst nodes before anchor must be substituted in. for (int i = 1; i < tree.getAnchor(); i++) // for (int i = 1; i < Integer.parseInt(tree.getAnchor()); i++) { if (tree.getNodeType(i) == TagNodeType.subst && !coveredNodes.containsValue(i)) // if (tree.getNodeType(String.valueOf(i)) == TagNodeType.subst && !coveredNodes.containsValue(i)) { pattern = null; break; } } if (pattern == null) { continue; } //if (index == -1) continue; // check whether incrementality ok (subst nodes before lexical anchor have already been filled) if (preftreetreeState.getFringe().getSubstNode() == null) { if (StringTreeAnalysis.matches(pattern, preftreetreeState.getFringe().getLastAdjNode().getDownIndex())) { //TODO preftreetreeState need to be expanded up to root node of shadow tree. ArrayList<TreeState> expandedTreeStates = new ArrayList<TreeState>(); if (shadowtree.getTreeOrigIndex().isAuxtree() && !shadowtree.getTreeOrigIndex().hasFootLeft()) { expandedTreeStates = preftreetreeState.expand(chartEntry, opts.nBest, opts.useSemantics, model); } if (expandedTreeStates == null) { return chartentries; } if (expandedTreeStates.isEmpty()) { expandedTreeStates.add(preftreetreeState); } for (TreeState pref : expandedTreeStates) { for (ChartEntry ce : ParserOperation.verify.combine(model, opts, words, origPosTags, pref, elemtreetreeState, pattern, tree, shadowtree, coveredNodes, shadowtree.getOffsetNodeIds(), timestamp)) { chartentries.add(ce); } } return chartentries; } // if } // if } // if } // for } // for return chartentries; }
From source file:org.springframework.beans.factory.DefaultListableBeanFactoryTests.java
@Test public void testRegisterExistingSingletonWithReference() { DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(); Properties p = new Properties(); p.setProperty("test.(class)", TestBean.class.getName()); p.setProperty("test.name", "Tony"); p.setProperty("test.age", "48"); p.setProperty("test.spouse(ref)", "singletonObject"); (new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p); Object singletonObject = new TestBean(); lbf.registerSingleton("singletonObject", singletonObject); assertTrue(lbf.isSingleton("singletonObject")); assertEquals(TestBean.class, lbf.getType("singletonObject")); TestBean test = (TestBean) lbf.getBean("test"); assertEquals(singletonObject, lbf.getBean("singletonObject")); assertEquals(singletonObject, test.getSpouse()); Map<?, ?> beansOfType = lbf.getBeansOfType(TestBean.class, false, true); assertEquals(2, beansOfType.size()); assertTrue(beansOfType.containsValue(test)); assertTrue(beansOfType.containsValue(singletonObject)); beansOfType = lbf.getBeansOfType(null, false, true); assertEquals(2, beansOfType.size()); Iterator<String> beanNames = lbf.getBeanNamesIterator(); assertEquals("test", beanNames.next()); assertEquals("singletonObject", beanNames.next()); assertFalse(beanNames.hasNext());// w w w .j ava2 s .co m assertTrue(lbf.containsSingleton("test")); assertTrue(lbf.containsSingleton("singletonObject")); assertTrue(lbf.containsBeanDefinition("test")); assertFalse(lbf.containsBeanDefinition("singletonObject")); }
From source file:org.springframework.beans.factory.DefaultListableBeanFactoryTests.java
@Test public void testRegisterExistingSingletonWithNameOverriding() { DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(); Properties p = new Properties(); p.setProperty("test.(class)", TestBean.class.getName()); p.setProperty("test.name", "Tony"); p.setProperty("test.age", "48"); p.setProperty("test.spouse(ref)", "singletonObject"); (new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p); lbf.registerBeanDefinition("singletonObject", new RootBeanDefinition(PropertiesFactoryBean.class)); Object singletonObject = new TestBean(); lbf.registerSingleton("singletonObject", singletonObject); lbf.preInstantiateSingletons();// www.j a v a 2s .com assertTrue(lbf.isSingleton("singletonObject")); assertEquals(TestBean.class, lbf.getType("singletonObject")); TestBean test = (TestBean) lbf.getBean("test"); assertEquals(singletonObject, lbf.getBean("singletonObject")); assertEquals(singletonObject, test.getSpouse()); Map<?, ?> beansOfType = lbf.getBeansOfType(TestBean.class, false, true); assertEquals(2, beansOfType.size()); assertTrue(beansOfType.containsValue(test)); assertTrue(beansOfType.containsValue(singletonObject)); beansOfType = lbf.getBeansOfType(null, false, true); Iterator<String> beanNames = lbf.getBeanNamesIterator(); assertEquals("test", beanNames.next()); assertEquals("singletonObject", beanNames.next()); assertFalse(beanNames.hasNext()); assertEquals(2, beansOfType.size()); assertTrue(lbf.containsSingleton("test")); assertTrue(lbf.containsSingleton("singletonObject")); assertTrue(lbf.containsBeanDefinition("test")); assertTrue(lbf.containsBeanDefinition("singletonObject")); }
From source file:com.amalto.workbench.utils.Util.java
public static XSDSchema createXsdSchema(String xsd, TreeObject treeObj) throws Exception { List<XSDImport> imports = new ArrayList<XSDImport>(); List<Exception> exceptons = new ArrayList<Exception>(); Map<String, Integer> schemaMonitor = new HashMap<String, Integer>(); // no import or include using old getXsdschema() // if (Util.getNodeList(doc.getDocumentElement(),"//xsd:import").getLength() ==0 // || Util.getNodeList(doc.getDocumentElement(), // "//xsd:include").getLength() ==0) // {// ww w. j a v a 2 s . c o m // return Util.getXSDSchema(xsd); // } // replace the old roles with the new role scheme String xsdCpy = new String(xsd); for (Map.Entry<String, String> pair : ICoreConstants.rolesConvert.oldRoleToNewRoleMap.entrySet()) { xsdCpy = xsdCpy.replaceAll(pair.getKey().toString(), pair.getValue().toString()); } XSDSchema xsdSchema = Util.getXSDSchema(null, xsdCpy, imports, treeObj, false, exceptons, schemaMonitor); if (exceptons.size() > 0) { throw exceptons.get(0); } else if (schemaMonitor.containsValue(new Integer(-1))) { throw new Exception(Messages.Util_44); } addImport(xsdSchema, imports); return xsdSchema; }
From source file:com.google.gwt.emultest.java.util.TreeMapTest.java
/** * Test method for 'java.util.Map.containsValue(Object)'. * * @see java.util.Map#containsValue(Object) *//*from w ww . j a va2 s .c o m*/ @SuppressWarnings("SuspiciousMethodCalls") public void testContainsValue() { K[] keys = getKeys(); V[] values = getValues(); Map<K, V> map = createMap(); assertFalse(map.containsValue(values[0])); map.put(keys[0], values[0]); assertEquals(1, map.values().size()); assertTrue(map.containsValue(values[0])); assertFalse(map.containsValue(keys[0])); assertFalse(map.containsValue(values[1])); assertFalse(map.containsValue(null)); map.put(keys[0], null); assertTrue(map.containsValue(null)); map.put(keys[0], values[0]); map.put(keys[1], values[1]); assertTrue(map.containsValue(values[1])); assertFalse(map.containsValue(values[3])); }
From source file:com.google.gwt.emultest.java.util.TreeMapTest.java
/** * Test method for 'java.util.Map.containsValue(Object)'. * * @see java.util.Map#containsValue(Object) *//*from w w w.j a v a 2 s . co m*/ public void testContainsValue_throwsClassCastException() { K[] keys = getKeys(); V[] values = getValues(); Map<K, V> map = createMap(); map.put(keys[0], values[0]); map.containsValue(getConflictingValue()); // You might think this should throw an exception here but, no. Makes // sense since the class cast is attributed to comparability of the // keys... generics really have nothing to do with it . // try { // map.containsValue(getConflictingValue()); // fail("expected exception"); // } catch (ClassCastException e) { // // expected outcome // } }
From source file:com.google.gwt.emultest.java.util.TreeMapTest.java
/** * Test method for 'java.util.Map.containsValue(Object)'. * * @see java.util.Map#containsValue(Object) *//*w w w. ja va 2 s .c o m*/ public void testContainsValue_throwsNullPointerException() { Map<K, V> map = createMap(); if (!isNullValueSupported) { try { map.containsValue(null); fail("expected exception"); } catch (NullPointerException e) { // expected outcome } } }
From source file:com.google.gwt.emultest.java.util.TreeMapTest.java
public void testHeadMapLjava_lang_Object() { K[] keys = getSortedKeys();/*from w ww . j a v a 2s. co m*/ V[] values = getSortedValues(); NavigableMap<K, V> map = createNavigableMap(); for (int i = 0; i < keys.length; i++) { map.put(keys[i], values[i]); } Map<K, V> head = map.headMap(keys[3]); assertEquals(3, head.size()); assertTrue(head.containsKey(keys[0])); assertTrue(head.containsValue(values[1])); assertTrue(head.containsKey(keys[2])); if (useNullKey() && useNullValue()) { map.put(null, null); SortedMap<K, V> submap = map.headMap(null); assertEquals(0, submap.size()); Set<K> keySet = submap.keySet(); assertEquals(0, keySet.size()); Set<Map.Entry<K, V>> entrySet = submap.entrySet(); assertEquals(0, entrySet.size()); Collection<V> valueCollection = submap.values(); assertEquals(0, valueCollection.size()); map.remove(null); } SortedMap<K, V> submap = map.headMap(getLessThanMinimumKey()); assertEquals(submap.size(), 0); assertTrue(submap.isEmpty()); try { submap.firstKey(); fail("NoSuchElementException should be thrown"); } catch (NoSuchElementException expected) { } try { submap.lastKey(); fail("NoSuchElementException should be thrown"); } catch (NoSuchElementException expected) { } try { submap.headMap(null); assertTrue("expected exception", useNullKey()); } catch (NullPointerException e) { assertFalse("unexpected NPE", useNullKey()); } }
From source file:com.google.gwt.emultest.java.util.TreeMapTest.java
public void testEntrySet_entry_setValue() { K[] keys = getKeys();/*from w w w. ja va 2s . c o m*/ V[] values = getValues(); Map<K, V> map = createMap(); Set<Entry<K, V>> entrySet = map.entrySet(); map.put(keys[0], values[0]); entrySet.iterator().next().setValue(values[1]); assertTrue(map.containsValue(values[1])); _assertEquals(entrySet, map.entrySet()); }