List of usage examples for java.util.concurrent ConcurrentMap containsKey
boolean containsKey(Object key);
From source file:com.github.podd.utils.test.OntologyUtilsTest.java
@Test public void testImportsOrderOneLevelOutOfOrder() throws Exception { final Model model = new LinkedHashModel(); OntologyUtils.ontologyIDsToModel(Arrays.asList(OntologyConstant.testOntologyID), model); model.add(OntologyConstant.testImportOntologyUri1, RDF.TYPE, OWL.ONTOLOGY); model.add(OntologyConstant.testImportOntologyUri1, OWL.VERSIONIRI, OntologyConstant.testImportVersionUri1); model.add(OntologyConstant.testImportVersionUri1, RDF.TYPE, OWL.ONTOLOGY); model.add(OntologyConstant.testVersionUri1, OWL.IMPORTS, OntologyConstant.testImportOntologyUri1); final Set<URI> schemaOntologyUris = new LinkedHashSet<URI>(); final Set<URI> schemaVersionUris = new LinkedHashSet<URI>(); schemaOntologyUris.add(OntologyConstant.testImportOntologyUri1); schemaOntologyUris.add(OntologyConstant.testOntologyUri1); schemaVersionUris.add(OntologyConstant.testImportVersionUri1); schemaVersionUris.add(OntologyConstant.testVersionUri1); final ConcurrentMap<URI, Set<URI>> importsMap = new ConcurrentHashMap<URI, Set<URI>>(); // Expected output solution from importsMap after calling orderImports // importsMap.put(testVersionUri1, // Collections.singleton(OntologyConstant.testImportVersionUri1)); // importsMap.put(testImportVersionUri1, new HashSet<URI>()); final List<URI> orderImports = OntologyUtils.orderImports(model, schemaOntologyUris, schemaVersionUris, importsMap, false);/* w w w. ja v a2s. c o m*/ Assert.assertEquals(2, orderImports.size()); Assert.assertEquals(OntologyConstant.testImportVersionUri1, orderImports.get(0)); Assert.assertEquals(OntologyConstant.testVersionUri1, orderImports.get(1)); Assert.assertEquals(2, importsMap.size()); Assert.assertTrue(importsMap.containsKey(OntologyConstant.testImportVersionUri1)); Assert.assertTrue(importsMap.containsKey(OntologyConstant.testVersionUri1)); final Set<URI> imports1 = importsMap.get(OntologyConstant.testImportVersionUri1); Assert.assertNotNull(imports1); Assert.assertEquals(0, imports1.size()); final Set<URI> importsRoot = importsMap.get(OntologyConstant.testVersionUri1); Assert.assertNotNull(importsRoot); Assert.assertEquals(1, importsRoot.size()); Assert.assertEquals(OntologyConstant.testImportVersionUri1, importsRoot.iterator().next()); }
From source file:com.github.podd.utils.test.OntologyUtilsTest.java
@Test public void testImportsOrderFourLevelsOutOfOrder() throws Exception { final Model model = new LinkedHashModel(); OntologyUtils.ontologyIDsToModel(Arrays.asList(OntologyConstant.testOntologyID), model); model.add(OntologyConstant.testVersionUri1, OWL.IMPORTS, OntologyConstant.testImportOntologyUri1); model.add(OntologyConstant.testImportOntologyUri1, RDF.TYPE, OWL.ONTOLOGY); model.add(OntologyConstant.testImportOntologyUri1, OWL.VERSIONIRI, OntologyConstant.testImportVersionUri1); model.add(OntologyConstant.testImportVersionUri1, RDF.TYPE, OWL.ONTOLOGY); model.add(OntologyConstant.testImportOntologyUri2, RDF.TYPE, OWL.ONTOLOGY); model.add(OntologyConstant.testImportOntologyUri2, OWL.VERSIONIRI, OntologyConstant.testImportVersionUri2); model.add(OntologyConstant.testImportVersionUri2, RDF.TYPE, OWL.ONTOLOGY); model.add(OntologyConstant.testImportVersionUri1, OWL.IMPORTS, OntologyConstant.testImportVersionUri2); model.add(OntologyConstant.testImportOntologyUri3, RDF.TYPE, OWL.ONTOLOGY); model.add(OntologyConstant.testImportOntologyUri3, OWL.VERSIONIRI, OntologyConstant.testImportVersionUri3); model.add(OntologyConstant.testImportVersionUri3, RDF.TYPE, OWL.ONTOLOGY); model.add(OntologyConstant.testImportVersionUri2, OWL.IMPORTS, OntologyConstant.testImportVersionUri3); model.add(OntologyConstant.testImportOntologyUri4, RDF.TYPE, OWL.ONTOLOGY); model.add(OntologyConstant.testImportOntologyUri4, OWL.VERSIONIRI, OntologyConstant.testImportVersionUri4); model.add(OntologyConstant.testImportVersionUri4, RDF.TYPE, OWL.ONTOLOGY); model.add(OntologyConstant.testImportVersionUri3, OWL.IMPORTS, OntologyConstant.testImportVersionUri4); final Set<URI> schemaOntologyUris = new LinkedHashSet<URI>(); final Set<URI> schemaVersionUris = new LinkedHashSet<URI>(); schemaOntologyUris.add(OntologyConstant.testImportOntologyUri2); schemaOntologyUris.add(OntologyConstant.testImportOntologyUri4); schemaOntologyUris.add(OntologyConstant.testOntologyUri1); schemaOntologyUris.add(OntologyConstant.testImportOntologyUri3); schemaOntologyUris.add(OntologyConstant.testImportOntologyUri1); schemaVersionUris.add(OntologyConstant.testImportVersionUri2); schemaVersionUris.add(OntologyConstant.testImportVersionUri4); schemaVersionUris.add(OntologyConstant.testVersionUri1); schemaVersionUris.add(OntologyConstant.testImportVersionUri3); schemaVersionUris.add(OntologyConstant.testImportVersionUri1); final ConcurrentMap<URI, Set<URI>> importsMap = new ConcurrentHashMap<URI, Set<URI>>(); final List<URI> orderImports = OntologyUtils.orderImports(model, schemaOntologyUris, schemaVersionUris, importsMap, false);// ww w . j a va2s . c o m Assert.assertEquals(5, orderImports.size()); Assert.assertEquals(OntologyConstant.testImportVersionUri4, orderImports.get(0)); Assert.assertEquals(OntologyConstant.testImportVersionUri3, orderImports.get(1)); Assert.assertEquals(OntologyConstant.testImportVersionUri2, orderImports.get(2)); Assert.assertEquals(OntologyConstant.testImportVersionUri1, orderImports.get(3)); Assert.assertEquals(OntologyConstant.testVersionUri1, orderImports.get(4)); Assert.assertEquals(5, importsMap.size()); Assert.assertTrue(importsMap.containsKey(OntologyConstant.testImportVersionUri4)); Assert.assertTrue(importsMap.containsKey(OntologyConstant.testImportVersionUri3)); Assert.assertTrue(importsMap.containsKey(OntologyConstant.testImportVersionUri2)); Assert.assertTrue(importsMap.containsKey(OntologyConstant.testImportVersionUri1)); Assert.assertTrue(importsMap.containsKey(OntologyConstant.testVersionUri1)); final Set<URI> imports4 = importsMap.get(OntologyConstant.testImportVersionUri4); Assert.assertNotNull(imports4); Assert.assertEquals(0, imports4.size()); final Set<URI> imports3 = importsMap.get(OntologyConstant.testImportVersionUri3); Assert.assertNotNull(imports3); Assert.assertEquals(1, imports3.size()); Assert.assertTrue(imports3.contains(OntologyConstant.testImportVersionUri4)); final Set<URI> imports2 = importsMap.get(OntologyConstant.testImportVersionUri2); Assert.assertNotNull(imports2); Assert.assertEquals(2, imports2.size()); Assert.assertTrue(imports2.contains(OntologyConstant.testImportVersionUri3)); Assert.assertTrue(imports2.contains(OntologyConstant.testImportVersionUri4)); final Set<URI> imports1 = importsMap.get(OntologyConstant.testImportVersionUri1); Assert.assertNotNull(imports1); Assert.assertEquals(3, imports1.size()); Assert.assertTrue(imports1.contains(OntologyConstant.testImportVersionUri2)); Assert.assertTrue(imports1.contains(OntologyConstant.testImportVersionUri3)); Assert.assertTrue(imports1.contains(OntologyConstant.testImportVersionUri4)); final Set<URI> importsRoot = importsMap.get(OntologyConstant.testVersionUri1); Assert.assertNotNull(importsRoot); Assert.assertEquals(4, importsRoot.size()); Assert.assertTrue(importsRoot.contains(OntologyConstant.testImportVersionUri1)); Assert.assertTrue(importsRoot.contains(OntologyConstant.testImportVersionUri2)); Assert.assertTrue(importsRoot.contains(OntologyConstant.testImportVersionUri3)); Assert.assertTrue(importsRoot.contains(OntologyConstant.testImportVersionUri4)); }
From source file:com.github.podd.utils.test.OntologyUtilsTest.java
@Test public void testImportsOrderFourLevels() throws Exception { final Model model = new LinkedHashModel(); OntologyUtils.ontologyIDsToModel(Arrays.asList(OntologyConstant.testOntologyID), model); model.add(OntologyConstant.testVersionUri1, OWL.IMPORTS, OntologyConstant.testImportOntologyUri1); model.add(OntologyConstant.testImportOntologyUri1, RDF.TYPE, OWL.ONTOLOGY); model.add(OntologyConstant.testImportOntologyUri1, OWL.VERSIONIRI, OntologyConstant.testImportVersionUri1); model.add(OntologyConstant.testImportVersionUri1, RDF.TYPE, OWL.ONTOLOGY); model.add(OntologyConstant.testImportOntologyUri2, RDF.TYPE, OWL.ONTOLOGY); model.add(OntologyConstant.testImportOntologyUri2, OWL.VERSIONIRI, OntologyConstant.testImportVersionUri2); model.add(OntologyConstant.testImportVersionUri2, RDF.TYPE, OWL.ONTOLOGY); model.add(OntologyConstant.testImportVersionUri1, OWL.IMPORTS, OntologyConstant.testImportVersionUri2); model.add(OntologyConstant.testImportOntologyUri3, RDF.TYPE, OWL.ONTOLOGY); model.add(OntologyConstant.testImportOntologyUri3, OWL.VERSIONIRI, OntologyConstant.testImportVersionUri3); model.add(OntologyConstant.testImportVersionUri3, RDF.TYPE, OWL.ONTOLOGY); model.add(OntologyConstant.testImportVersionUri2, OWL.IMPORTS, OntologyConstant.testImportVersionUri3); model.add(OntologyConstant.testImportOntologyUri4, RDF.TYPE, OWL.ONTOLOGY); model.add(OntologyConstant.testImportOntologyUri4, OWL.VERSIONIRI, OntologyConstant.testImportVersionUri4); model.add(OntologyConstant.testImportVersionUri4, RDF.TYPE, OWL.ONTOLOGY); model.add(OntologyConstant.testImportVersionUri3, OWL.IMPORTS, OntologyConstant.testImportVersionUri4); final Set<URI> schemaOntologyUris = new LinkedHashSet<URI>(); final Set<URI> schemaVersionUris = new LinkedHashSet<URI>(); schemaOntologyUris.add(OntologyConstant.testOntologyUri1); schemaOntologyUris.add(OntologyConstant.testImportOntologyUri1); schemaOntologyUris.add(OntologyConstant.testImportOntologyUri2); schemaOntologyUris.add(OntologyConstant.testImportOntologyUri3); schemaOntologyUris.add(OntologyConstant.testImportOntologyUri4); schemaVersionUris.add(OntologyConstant.testVersionUri1); schemaVersionUris.add(OntologyConstant.testImportVersionUri1); schemaVersionUris.add(OntologyConstant.testImportVersionUri2); schemaVersionUris.add(OntologyConstant.testImportVersionUri3); schemaVersionUris.add(OntologyConstant.testImportVersionUri4); final ConcurrentMap<URI, Set<URI>> importsMap = new ConcurrentHashMap<URI, Set<URI>>(); // Expected output solution from importsMap after calling orderImports // importsMap.put(testVersionUri1, // Collections.singleton(OntologyConstant.testImportVersionUri1)); // importsMap.put(testImportVersionUri1, // Collections.singleton(OntologyConstant.testImportVersionUri2)); // importsMap.put(testImportVersionUri2, // Collections.singleton(OntologyConstant.testImportVersionUri3)); // importsMap.put(testImportVersionUri3, new // HashSet<URI>(Arrays.asList(OntologyConstant.testImportVersionUri4))); // importsMap.put(testImportVersionUri4, new HashSet<URI>()); final List<URI> orderImports = OntologyUtils.orderImports(model, schemaOntologyUris, schemaVersionUris, importsMap, false);//from w w w . j a va 2s . co m Assert.assertEquals(5, orderImports.size()); Assert.assertEquals(OntologyConstant.testImportVersionUri4, orderImports.get(0)); Assert.assertEquals(OntologyConstant.testImportVersionUri3, orderImports.get(1)); Assert.assertEquals(OntologyConstant.testImportVersionUri2, orderImports.get(2)); Assert.assertEquals(OntologyConstant.testImportVersionUri1, orderImports.get(3)); Assert.assertEquals(OntologyConstant.testVersionUri1, orderImports.get(4)); Assert.assertEquals(5, importsMap.size()); Assert.assertTrue(importsMap.containsKey(OntologyConstant.testImportVersionUri4)); Assert.assertTrue(importsMap.containsKey(OntologyConstant.testImportVersionUri3)); Assert.assertTrue(importsMap.containsKey(OntologyConstant.testImportVersionUri2)); Assert.assertTrue(importsMap.containsKey(OntologyConstant.testImportVersionUri1)); Assert.assertTrue(importsMap.containsKey(OntologyConstant.testVersionUri1)); final Set<URI> imports4 = importsMap.get(OntologyConstant.testImportVersionUri4); Assert.assertNotNull(imports4); Assert.assertEquals(0, imports4.size()); final Set<URI> imports3 = importsMap.get(OntologyConstant.testImportVersionUri3); Assert.assertNotNull(imports3); Assert.assertEquals(1, imports3.size()); Assert.assertTrue(imports3.contains(OntologyConstant.testImportVersionUri4)); final Set<URI> imports2 = importsMap.get(OntologyConstant.testImportVersionUri2); Assert.assertNotNull(imports2); Assert.assertEquals(2, imports2.size()); Assert.assertTrue(imports2.contains(OntologyConstant.testImportVersionUri3)); Assert.assertTrue(imports2.contains(OntologyConstant.testImportVersionUri4)); final Set<URI> imports1 = importsMap.get(OntologyConstant.testImportVersionUri1); Assert.assertNotNull(imports1); Assert.assertEquals(3, imports1.size()); Assert.assertTrue(imports1.contains(OntologyConstant.testImportVersionUri2)); Assert.assertTrue(imports1.contains(OntologyConstant.testImportVersionUri3)); Assert.assertTrue(imports1.contains(OntologyConstant.testImportVersionUri4)); final Set<URI> importsRoot = importsMap.get(OntologyConstant.testVersionUri1); Assert.assertNotNull(importsRoot); Assert.assertEquals(4, importsRoot.size()); Assert.assertTrue(importsRoot.contains(OntologyConstant.testImportVersionUri1)); Assert.assertTrue(importsRoot.contains(OntologyConstant.testImportVersionUri2)); Assert.assertTrue(importsRoot.contains(OntologyConstant.testImportVersionUri3)); Assert.assertTrue(importsRoot.contains(OntologyConstant.testImportVersionUri4)); }
From source file:org.apache.ranger.common.TestTimedExecutor.java
static void recordResult(ConcurrentMap<String, AtomicInteger> results, String key) { if (results.containsKey(key)) { results.get(key).incrementAndGet(); } else {/* w w w .j a va 2 s.c om*/ AtomicInteger previous = results.putIfAbsent(key, new AtomicInteger(1)); if (previous != null) { // a value was already associated with the key previous.incrementAndGet(); } } }
From source file:org.linagora.linshare.webservice.utils.FlowUploaderUtils.java
public static Response testChunk(long chunkNumber, long totalChunks, long chunkSize, long totalSize, String identifier, String filename, String relativePath, ConcurrentMap<String, ChunkedFile> chunkedFiles, boolean maintenance) { if (maintenance) { return buildReponse(Status.NO_CONTENT); // 204 // https://github.com/flowjs/flow.js // If this request returns a 200, 201 or 202 HTTP code, the chunks is assumed to have been completed. // If request returns a permanent error status, upload is stopped. // If request returns anything else, the chunk will be uploaded in the standard fashion. }/*from w ww . j av a 2 s. co m*/ identifier = cleanIdentifier(identifier); boolean isValid = isValid(chunkNumber, chunkSize, totalSize, identifier, filename); // Throw HTTP 400 error code. Validate.isTrue(isValid); if (chunkedFiles.containsKey(identifier) && chunkedFiles.get(identifier).hasChunk(chunkNumber)) { // HTTP 200 : ok, we already get this chunk. return buildReponse(Status.ACCEPTED); } // HTTP 204 We did not have this chunk return buildReponse(Status.NO_CONTENT); }
From source file:org.opendaylight.controller.protocol_plugin.openflow.internal.TopologyServiceShim.java
/** * Update local cache and return true if it needs to notify upper layer * Topology listeners./*from w w w . j ava 2 s. c o m*/ * * @param container * The network container * @param edge * The edge * @param type * The update type * @param props * The edge properties * @return true if it needs to notify upper layer Topology listeners */ private boolean updateLocalEdgeMap(String container, Edge edge, UpdateType type, Set<Property> props) { ConcurrentMap<NodeConnector, Pair<Edge, Set<Property>>> edgePropsMap = edgeMap.get(container); NodeConnector src = edge.getTailNodeConnector(); Pair<Edge, Set<Property>> edgeProps = new ImmutablePair<Edge, Set<Property>>(edge, props); boolean rv = false; switch (type) { case ADDED: case CHANGED: if (edgePropsMap == null) { edgePropsMap = new ConcurrentHashMap<NodeConnector, Pair<Edge, Set<Property>>>(); rv = true; } else { if (edgePropsMap.containsKey(src) && edgePropsMap.get(src).equals(edgeProps)) { // Entry already exists. No update. rv = false; } else { rv = true; } } if (rv) { edgePropsMap.put(src, edgeProps); edgeMap.put(container, edgePropsMap); } break; case REMOVED: if ((edgePropsMap != null) && edgePropsMap.containsKey(src)) { edgePropsMap.remove(src); if (edgePropsMap.isEmpty()) { edgeMap.remove(container); } else { edgeMap.put(container, edgePropsMap); } rv = true; } break; default: logger.debug("notifyLocalEdgeMap: invalid {} for Edge {} in container {}", new Object[] { type.getName(), edge, container }); } if (rv) { logger.debug("notifyLocalEdgeMap: {} for Edge {} in container {}", new Object[] { type.getName(), edge, container }); } return rv; }
From source file:se.idsecurity.ldifcompare.LdifCompare.java
private void getUniqueEntriesUsingDN(Set<Entry> source, Set<Entry> target, LDIFWriter ldifWriterUnique) { Runnable r = () -> {/*from w w w.j ava2s .c o m*/ StopWatch sw = new StopWatch(); sw.start(); ConcurrentMap<String, Entry> targetMap = target.parallelStream() .collect(Collectors.toConcurrentMap(Entry::getDN, Function.identity())); for (Entry e : source) { //Get unique entries from the rightLdif file based on DN - no entry with the same DN exist in leftLdif String dn = e.getDN(); if (!targetMap.containsKey(dn)) { try { ldifWriterUnique.writeEntry(e);//Entry only exists in rightLdif } catch (IOException ex) { logger.error("Error writing to LDIF file", ex); } } } fileWriteCdl.countDown(); sw.stop(); logger.error("Time taken to process getUniqueEntriesUsingDN(): " + sw.toString()); sw.reset(); }; exec.execute(r); }