Java Code Examples for java.util.concurrent.ConcurrentHashMap#KeySetView

The following examples show how to use java.util.concurrent.ConcurrentHashMap#KeySetView . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProductTypeSyncStatisticsTest.java    From commercetools-sync-java with Apache License 2.0 6 votes vote down vote up
@Test
void removeReferencingProductTypeKey_WithEmptyMap_ShouldRemoveNothing() {
    // preparation
    final ConcurrentHashMap<String,
        ConcurrentHashMap<String, ConcurrentHashMap.KeySetView<AttributeDefinitionDraft, Boolean>>>
        missingProductTypeReferences = new ConcurrentHashMap<>();

    final ProductTypeSyncStatistics productTypeSyncStatistics =
        new ProductTypeSyncStatistics(missingProductTypeReferences);

    // test
    productTypeSyncStatistics.removeReferencingProductTypeKey("foo");

    // assertion
    assertThat(productTypeSyncStatistics.getProductTypeKeysWithMissingParents()).isEmpty();
}
 
Example 2
Source File: ConcurrentHashMap8Test.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * KeySetView.getMappedValue returns the map's mapped value
 */
public void testGetMappedValue() {
    ConcurrentHashMap map = map5();
    assertNull(map.keySet().getMappedValue());
    try {
        map.keySet(null);
        shouldThrow();
    } catch (NullPointerException success) {}
    ConcurrentHashMap.KeySetView set = map.keySet(one);
    assertFalse(set.add(one));
    assertTrue(set.add(six));
    assertTrue(set.add(seven));
    assertTrue(set.getMappedValue() == one);
    assertTrue(map.get(one) != one);
    assertTrue(map.get(six) == one);
    assertTrue(map.get(seven) == one);
}
 
Example 3
Source File: ProductTypeSyncStatistics.java    From commercetools-sync-java with Apache License 2.0 6 votes vote down vote up
/**
 * Removes all occurrences of the referencing product type key from {@link #missingNestedProductTypes}.
 * If there are no referencing product types for any missing nested product type, the whole entry for this
 * missing nested product type will be removed from {@link #missingNestedProductTypes}.
 *
 * <p>Important: This method is meant to be used only for internal use of the library and should not be used by
 * externally.
 *
 * @param referencingProductTypeKey the key that should be removed from {@link #missingNestedProductTypes}.
 */
public void removeReferencingProductTypeKey(@Nonnull final String referencingProductTypeKey) {

    final Iterator<ConcurrentHashMap<String, ConcurrentHashMap.KeySetView<AttributeDefinitionDraft, Boolean>>>
        referencingProductTypesIterator = missingNestedProductTypes.values().iterator();

    while (referencingProductTypesIterator.hasNext()) {
        final ConcurrentHashMap<String, ConcurrentHashMap.KeySetView<AttributeDefinitionDraft, Boolean>>
            referencingProductTypes = referencingProductTypesIterator.next();

        referencingProductTypes.remove(referencingProductTypeKey);

        // If there are no referencing product types for this missing nested product type,
        // remove referencing product types map.
        if (referencingProductTypes.isEmpty()) {
            referencingProductTypesIterator.remove();
        }
    }
}
 
Example 4
Source File: ProductTypeSyncStatisticsTest.java    From commercetools-sync-java with Apache License 2.0 6 votes vote down vote up
@Test
void getNumberOfProductTypesWithMissingNestedProductTypes_WithDifferentReferencingProdTypes_CountDistinct() {
    // preparation
    final ConcurrentHashMap<String,
        ConcurrentHashMap<String, ConcurrentHashMap.KeySetView<AttributeDefinitionDraft, Boolean>>>
        missingProductTypeReferences = new ConcurrentHashMap<>();

    final ConcurrentHashMap<String, ConcurrentHashMap.KeySetView<AttributeDefinitionDraft, Boolean>>
        productTypesReferencingMissing1 = new ConcurrentHashMap<>();
    productTypesReferencingMissing1.put("referencing-product-type-1", ConcurrentHashMap.newKeySet());
    productTypesReferencingMissing1.put("referencing-product-type-2", ConcurrentHashMap.newKeySet());

    final ConcurrentHashMap<String, ConcurrentHashMap.KeySetView<AttributeDefinitionDraft, Boolean>>
        productTypesReferencingMissing2 = new ConcurrentHashMap<>();
    productTypesReferencingMissing2.put("referencing-product-type-3", ConcurrentHashMap.newKeySet());
    productTypesReferencingMissing2.put("referencing-product-type-4", ConcurrentHashMap.newKeySet());

    missingProductTypeReferences.put("missing1", productTypesReferencingMissing1);
    missingProductTypeReferences.put("missing2", productTypesReferencingMissing2);

    final ProductTypeSyncStatistics productTypeSyncStatistics =
        new ProductTypeSyncStatistics(missingProductTypeReferences);

    // test and assertion
    assertThat(productTypeSyncStatistics.getNumberOfProductTypesWithMissingNestedProductTypes()).isEqualTo(4);
}
 
Example 5
Source File: ConcurrentHashMap8Test.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * KeySetView.getMappedValue returns the map's mapped value
 */
public void testGetMappedValue() {
    ConcurrentHashMap map = map5();
    assertNull(((ConcurrentHashMap.KeySetView) map.keySet()).getMappedValue());
    try {
        map.keySet(null);
        shouldThrow();
    } catch (NullPointerException success) {}
    ConcurrentHashMap.KeySetView set = map.keySet(one);
    assertFalse(set.add(one));
    assertTrue(set.add(six));
    assertTrue(set.add(seven));
    assertTrue(set.getMappedValue() == one);
    assertTrue(map.get(one) != one);
    assertTrue(map.get(six) == one);
    assertTrue(map.get(seven) == one);
}
 
Example 6
Source File: ProductTypeSyncStatisticsTest.java    From commercetools-sync-java with Apache License 2.0 6 votes vote down vote up
@Test
void getNumberOfProductTypesWithMissingNestedProductTypes_WithOneReferencingProdTypes_ShouldBe1() {
    // preparation
    final ConcurrentHashMap<String,
        ConcurrentHashMap<String, ConcurrentHashMap.KeySetView<AttributeDefinitionDraft, Boolean>>>
        missingProductTypeReferences = new ConcurrentHashMap<>();

    final ConcurrentHashMap<String, ConcurrentHashMap.KeySetView<AttributeDefinitionDraft, Boolean>>
        productTypesReferencingMissing1 = new ConcurrentHashMap<>();
    productTypesReferencingMissing1.put("referencing-product-type-1", ConcurrentHashMap.newKeySet());

    missingProductTypeReferences.put("missing1", productTypesReferencingMissing1);

    final ProductTypeSyncStatistics productTypeSyncStatistics =
        new ProductTypeSyncStatistics(missingProductTypeReferences);

    // test and assertion
    assertThat(productTypeSyncStatistics.getNumberOfProductTypesWithMissingNestedProductTypes()).isEqualTo(1);
}
 
Example 7
Source File: ProductTypeSyncStatisticsTest.java    From commercetools-sync-java with Apache License 2.0 6 votes vote down vote up
@Test
void getNumberOfProductTypesWithMissingNestedProductTypes_WithSameReferencingProdTypes_CountDistinct() {
    // preparation
    final ConcurrentHashMap<String,
        ConcurrentHashMap<String, ConcurrentHashMap.KeySetView<AttributeDefinitionDraft, Boolean>>>
        missingProductTypeReferences = new ConcurrentHashMap<>();

    final ConcurrentHashMap<String, ConcurrentHashMap.KeySetView<AttributeDefinitionDraft, Boolean>>
        productTypesReferencingMissing1 = new ConcurrentHashMap<>();
    productTypesReferencingMissing1.put("referencing-product-type-1", ConcurrentHashMap.newKeySet());
    productTypesReferencingMissing1.put("referencing-product-type-2", ConcurrentHashMap.newKeySet());

    final ConcurrentHashMap<String, ConcurrentHashMap.KeySetView<AttributeDefinitionDraft, Boolean>>
        productTypesReferencingMissing2 = new ConcurrentHashMap<>();
    productTypesReferencingMissing2.put("referencing-product-type-1", ConcurrentHashMap.newKeySet());
    productTypesReferencingMissing2.put("referencing-product-type-2", ConcurrentHashMap.newKeySet());

    missingProductTypeReferences.put("missing1", productTypesReferencingMissing1);
    missingProductTypeReferences.put("missing2", productTypesReferencingMissing2);

    final ProductTypeSyncStatistics productTypeSyncStatistics =
        new ProductTypeSyncStatistics(missingProductTypeReferences);

    // test and assertion
    assertThat(productTypeSyncStatistics.getNumberOfProductTypesWithMissingNestedProductTypes()).isEqualTo(2);
}
 
Example 8
Source File: ProductTypeSyncStatisticsTest.java    From commercetools-sync-java with Apache License 2.0 5 votes vote down vote up
@Test
void removeReferencingProductTypeKey_WithMultipleOccurrence_ShouldRemoveAllOccurrences() {
    // preparation
    final ConcurrentHashMap<String,
        ConcurrentHashMap<String, ConcurrentHashMap.KeySetView<AttributeDefinitionDraft, Boolean>>>
        missingProductTypeReferences = new ConcurrentHashMap<>();

    final ConcurrentHashMap<String, ConcurrentHashMap.KeySetView<AttributeDefinitionDraft, Boolean>>
        productTypesReferencingMissing1 = new ConcurrentHashMap<>();

    productTypesReferencingMissing1.put("referencing-product-type-1", ConcurrentHashMap.newKeySet());
    productTypesReferencingMissing1.put("referencing-product-type-2", ConcurrentHashMap.newKeySet());

    final ConcurrentHashMap<String, ConcurrentHashMap.KeySetView<AttributeDefinitionDraft, Boolean>>
        productTypesReferencingMissing2 = new ConcurrentHashMap<>();
    productTypesReferencingMissing2.put("referencing-product-type-1", ConcurrentHashMap.newKeySet());
    productTypesReferencingMissing2.put("referencing-product-type-4", ConcurrentHashMap.newKeySet());

    missingProductTypeReferences.put("missing1", productTypesReferencingMissing1);
    missingProductTypeReferences.put("missing2", productTypesReferencingMissing2);

    final ProductTypeSyncStatistics productTypeSyncStatistics =
        new ProductTypeSyncStatistics(missingProductTypeReferences);

    // test
    productTypeSyncStatistics.removeReferencingProductTypeKey("referencing-product-type-1");

    // assertion
    assertThat(productTypeSyncStatistics.getProductTypeKeysWithMissingParents()).hasSize(2);
    assertThat(productTypeSyncStatistics.getProductTypeKeysWithMissingParents().get("missing1"))
        .containsOnlyKeys("referencing-product-type-2");
    assertThat(productTypeSyncStatistics.getProductTypeKeysWithMissingParents().get("missing2"))
        .containsOnlyKeys("referencing-product-type-4");
}
 
Example 9
Source File: ProductTypeSyncStatisticsTest.java    From commercetools-sync-java with Apache License 2.0 5 votes vote down vote up
@Test
void putMissingNestedProductType_WithIdenticalOneReferencingAttrToAnEmptyMap_ShouldOverwriteExisting() {
    // preparation
    final ConcurrentHashMap<String,
        ConcurrentHashMap<String, ConcurrentHashMap.KeySetView<AttributeDefinitionDraft, Boolean>>>
        missingProductTypeReferences = new ConcurrentHashMap<>();

    final ConcurrentHashMap<String, ConcurrentHashMap.KeySetView<AttributeDefinitionDraft, Boolean>>
        productTypesReferencingMissing1 = new ConcurrentHashMap<>();

    final AttributeDefinitionDraft referencingAttributeDefinitionDraft = AttributeDefinitionDraftBuilder
        .of(NestedAttributeType.of(
            ProductType.referenceOfId("missingPT")), "attr-name", ofEnglish("label"), true)
        .build();

    final ConcurrentHashMap.KeySetView<AttributeDefinitionDraft, Boolean> definitionDrafts =
        ConcurrentHashMap.newKeySet();
    definitionDrafts.add(referencingAttributeDefinitionDraft);
    productTypesReferencingMissing1.put("referencingPT", definitionDrafts);

    missingProductTypeReferences.put("missingPT", productTypesReferencingMissing1);

    final ProductTypeSyncStatistics productTypeSyncStatistics =
        new ProductTypeSyncStatistics(missingProductTypeReferences);


    // test
    productTypeSyncStatistics.putMissingNestedProductType("missingPT",
        "referencingPT",
        referencingAttributeDefinitionDraft);

    // assertion
    assertThat(productTypeSyncStatistics.getProductTypeKeysWithMissingParents()).hasSize(1);
    assertThat(productTypeSyncStatistics.getProductTypeKeysWithMissingParents().get("missingPT")).hasSize(1);
    assertThat(productTypeSyncStatistics.getProductTypeKeysWithMissingParents()
                                        .get("missingPT")
                                        .get("referencingPT"))
        .contains(referencingAttributeDefinitionDraft);
}
 
Example 10
Source File: ProductTypeSyncStatisticsTest.java    From commercetools-sync-java with Apache License 2.0 5 votes vote down vote up
@Test
void putMissingNestedProductType_WithNullExistingAttributeDefs_ShouldCreateANewMap() {
    // preparation
    final ConcurrentHashMap<String,
        ConcurrentHashMap<String, ConcurrentHashMap.KeySetView<AttributeDefinitionDraft, Boolean>>>
        missingProductTypeReferences = new ConcurrentHashMap<>();

    final ConcurrentHashMap<String, ConcurrentHashMap.KeySetView<AttributeDefinitionDraft, Boolean>>
        productTypesReferencingMissing1 = new ConcurrentHashMap<>();

    final AttributeDefinitionDraft referencingAttributeDefinitionDraft = AttributeDefinitionDraftBuilder
        .of(NestedAttributeType.of(
            ProductType.referenceOfId("missingPT")), "attr-name", ofEnglish("label"), true)
        .build();

    final ConcurrentHashMap.KeySetView<AttributeDefinitionDraft, Boolean> definitionDrafts =
        ConcurrentHashMap.newKeySet();
    definitionDrafts.add(referencingAttributeDefinitionDraft);

    missingProductTypeReferences.put("missingPT", productTypesReferencingMissing1);

    final ProductTypeSyncStatistics productTypeSyncStatistics =
        new ProductTypeSyncStatistics(missingProductTypeReferences);


    // test
    productTypeSyncStatistics.putMissingNestedProductType("missingPT",
        "referencingPT",
        referencingAttributeDefinitionDraft);

    // assertion
    assertThat(productTypeSyncStatistics.getProductTypeKeysWithMissingParents()).hasSize(1);
    assertThat(productTypeSyncStatistics.getProductTypeKeysWithMissingParents().get("missingPT")).hasSize(1);
    assertThat(productTypeSyncStatistics.getProductTypeKeysWithMissingParents()
                                        .get("missingPT")
                                        .get("referencingPT"))
        .contains(referencingAttributeDefinitionDraft);
}
 
Example 11
Source File: ProductTypeSyncStatisticsTest.java    From commercetools-sync-java with Apache License 2.0 5 votes vote down vote up
@Test
void putMissingNestedProductType_WithNullExistingReferencingProductTypes_ShouldCreateANewMap() {
    // preparation
    final ConcurrentHashMap<String,
        ConcurrentHashMap<String, ConcurrentHashMap.KeySetView<AttributeDefinitionDraft, Boolean>>>
        missingProductTypeReferences = new ConcurrentHashMap<>();

    final ConcurrentHashMap<String, ConcurrentHashMap.KeySetView<AttributeDefinitionDraft, Boolean>>
        productTypesReferencingMissing1 = new ConcurrentHashMap<>();

    final AttributeDefinitionDraft referencingAttributeDefinitionDraft = AttributeDefinitionDraftBuilder
        .of(NestedAttributeType.of(
            ProductType.referenceOfId("missingPT")), "attr-name", ofEnglish("label"), true)
        .build();

    final ConcurrentHashMap.KeySetView<AttributeDefinitionDraft, Boolean> definitionDrafts =
        ConcurrentHashMap.newKeySet();
    definitionDrafts.add(referencingAttributeDefinitionDraft);
    productTypesReferencingMissing1.put("referencingPT", definitionDrafts);

    missingProductTypeReferences.put("missingPT", productTypesReferencingMissing1);

    final ProductTypeSyncStatistics productTypeSyncStatistics =
        new ProductTypeSyncStatistics(missingProductTypeReferences);


    // test
    productTypeSyncStatistics.putMissingNestedProductType("newMissing",
        "referencingPT",
        referencingAttributeDefinitionDraft);

    // assertion
    assertThat(productTypeSyncStatistics.getProductTypeKeysWithMissingParents()).hasSize(2);
    assertThat(productTypeSyncStatistics.getProductTypeKeysWithMissingParents().get("newMissing")).hasSize(1);
    assertThat(productTypeSyncStatistics.getProductTypeKeysWithMissingParents()
                                        .get("newMissing")
                                        .get("referencingPT"))
        .contains(referencingAttributeDefinitionDraft);
}
 
Example 12
Source File: ProductTypeSyncStatisticsTest.java    From commercetools-sync-java with Apache License 2.0 5 votes vote down vote up
@Test
void getNumberOfProductTypesWithMissingNestedProductTypes_WithEmptyMap_ShouldReturn0() {
    // preparation
    final ConcurrentHashMap<String,
        ConcurrentHashMap<String, ConcurrentHashMap.KeySetView<AttributeDefinitionDraft, Boolean>>>
        missingProductTypeReferences = new ConcurrentHashMap<>();

    final ProductTypeSyncStatistics productTypeSyncStatistics =
        new ProductTypeSyncStatistics(missingProductTypeReferences);

    // test and assertion
    assertThat(productTypeSyncStatistics.getNumberOfProductTypesWithMissingNestedProductTypes()).isEqualTo(0);
}
 
Example 13
Source File: ProductTypeSyncStatistics.java    From commercetools-sync-java with Apache License 2.0 5 votes vote down vote up
@Nonnull
private ConcurrentHashMap<String, ConcurrentHashMap.KeySetView<AttributeDefinitionDraft, Boolean>> asMap(
        @Nonnull final String referencingProductTypeKey,
        @Nonnull final AttributeDefinitionDraft referencingAttributeDefinitionDraft) {

    final ConcurrentHashMap<String, ConcurrentHashMap.KeySetView<AttributeDefinitionDraft, Boolean>>
        newReferencingProductTypes = new ConcurrentHashMap<>();
    newReferencingProductTypes
        .put(
            referencingProductTypeKey,
            asSet(referencingAttributeDefinitionDraft));
    return newReferencingProductTypes;
}
 
Example 14
Source File: ProductTypeSyncStatisticsTest.java    From commercetools-sync-java with Apache License 2.0 5 votes vote down vote up
@Test
void removeReferencingProductTypeKey_WithOnlyOccurrenceForMissingRef_ShouldRemoveMissingRef() {
    // preparation
    final ConcurrentHashMap<String,
        ConcurrentHashMap<String, ConcurrentHashMap.KeySetView<AttributeDefinitionDraft, Boolean>>>
        missingProductTypeReferences = new ConcurrentHashMap<>();

    final ConcurrentHashMap<String, ConcurrentHashMap.KeySetView<AttributeDefinitionDraft, Boolean>>
        productTypesReferencingMissing1 = new ConcurrentHashMap<>();

    productTypesReferencingMissing1.put("referencing-product-type-1", ConcurrentHashMap.newKeySet());

    final ConcurrentHashMap<String, ConcurrentHashMap.KeySetView<AttributeDefinitionDraft, Boolean>>
        productTypesReferencingMissing2 = new ConcurrentHashMap<>();
    productTypesReferencingMissing2.put("referencing-product-type-1", ConcurrentHashMap.newKeySet());
    productTypesReferencingMissing2.put("referencing-product-type-4", ConcurrentHashMap.newKeySet());

    missingProductTypeReferences.put("missing1", productTypesReferencingMissing1);
    missingProductTypeReferences.put("missing2", productTypesReferencingMissing2);

    final ProductTypeSyncStatistics productTypeSyncStatistics =
        new ProductTypeSyncStatistics(missingProductTypeReferences);

    // test
    productTypeSyncStatistics.removeReferencingProductTypeKey("referencing-product-type-1");

    // assertion
    assertThat(productTypeSyncStatistics.getProductTypeKeysWithMissingParents()).hasSize(1);
    assertThat(productTypeSyncStatistics.getProductTypeKeysWithMissingParents().get("missing2"))
        .containsOnlyKeys("referencing-product-type-4");
}
 
Example 15
Source File: TConcurrentHashMap.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
@Override
public ConcurrentHashMap.KeySetView keySet() {
    return (ConcurrentHashMap.KeySetView) (Object) new KeySetView<K>(delegate.keySet());
}
 
Example 16
Source File: ProductTypeSyncStatisticsTest.java    From commercetools-sync-java with Apache License 2.0 4 votes vote down vote up
@Test
void putMissingNestedProductType_WithAdditionalAttribute_ShouldAppendAttribute() {
    // preparation
    final ConcurrentHashMap<String,
        ConcurrentHashMap<String, ConcurrentHashMap.KeySetView<AttributeDefinitionDraft, Boolean>>>
        missingProductTypeReferences = new ConcurrentHashMap<>();

    final ConcurrentHashMap<String, ConcurrentHashMap.KeySetView<AttributeDefinitionDraft, Boolean>>
        productTypesReferencingMissing1 = new ConcurrentHashMap<>();
    final ConcurrentHashMap.KeySetView<AttributeDefinitionDraft, Boolean> definitionDrafts =
        ConcurrentHashMap.newKeySet();
    final AttributeDefinitionDraft existingReferencingAttr = AttributeDefinitionDraftBuilder
        .of(NestedAttributeType.of(
            ProductType.referenceOfId("missing1")), "attr-name-1", ofEnglish("label"), true)
        .build();
    definitionDrafts.add(existingReferencingAttr);


    productTypesReferencingMissing1.put("referencing-product-type-1", definitionDrafts);
    productTypesReferencingMissing1.put("referencing-product-type-2", ConcurrentHashMap.newKeySet());

    final ConcurrentHashMap<String, ConcurrentHashMap.KeySetView<AttributeDefinitionDraft, Boolean>>
        productTypesReferencingMissing2 = new ConcurrentHashMap<>();
    productTypesReferencingMissing2.put("referencing-product-type-3", ConcurrentHashMap.newKeySet());
    productTypesReferencingMissing2.put("referencing-product-type-4", ConcurrentHashMap.newKeySet());

    missingProductTypeReferences.put("missing1", productTypesReferencingMissing1);
    missingProductTypeReferences.put("missing2", productTypesReferencingMissing2);

    final ProductTypeSyncStatistics productTypeSyncStatistics =
        new ProductTypeSyncStatistics(missingProductTypeReferences);

    final AttributeDefinitionDraft referencingAttributeDefinitionDraft = AttributeDefinitionDraftBuilder
        .of(NestedAttributeType.of(
            ProductType.referenceOfId("missing1")), "attr-name", ofEnglish("label"), true)
        .build();


    // test
    productTypeSyncStatistics.putMissingNestedProductType("missing1",
        "referencing-product-type-1",
        referencingAttributeDefinitionDraft);

    // assertion
    assertThat(productTypeSyncStatistics.getProductTypeKeysWithMissingParents()).hasSize(2);
    assertThat(productTypeSyncStatistics.getProductTypeKeysWithMissingParents().get("missing1")).hasSize(2);
    assertThat(productTypeSyncStatistics.getProductTypeKeysWithMissingParents()
                                        .get("missing1")
                                        .get("referencing-product-type-1"))
        .containsExactlyInAnyOrder(existingReferencingAttr, referencingAttributeDefinitionDraft);
}
 
Example 17
Source File: MongoDirectory.java    From lumongo with Apache License 2.0 4 votes vote down vote up
@Override
public String[] getFileNames() throws IOException {

	ConcurrentHashMap.KeySetView<String, MongoFile> strings = nameToFileMap.keySet();
	return strings.toArray(new String[strings.size()]);
}
 
Example 18
Source File: ProductTypeSyncStatisticsTest.java    From commercetools-sync-java with Apache License 2.0 4 votes vote down vote up
@Test
void removeReferencingProductTypeKey_WithOneOccurrence_ShouldRemoveOccurrence() {
    // preparation
    final ConcurrentHashMap<String,
        ConcurrentHashMap<String, ConcurrentHashMap.KeySetView<AttributeDefinitionDraft, Boolean>>>
        missingProductTypeReferences = new ConcurrentHashMap<>();

    final ConcurrentHashMap<String, ConcurrentHashMap.KeySetView<AttributeDefinitionDraft, Boolean>>
        productTypesReferencingMissing1 = new ConcurrentHashMap<>();
    final ConcurrentHashMap.KeySetView<AttributeDefinitionDraft, Boolean> definitionDrafts =
        ConcurrentHashMap.newKeySet();
    final AttributeDefinitionDraft existingReferencingAttr = AttributeDefinitionDraftBuilder
        .of(NestedAttributeType.of(
            ProductType.referenceOfId("missing1")), "attr-name-1", ofEnglish("label"), true)
        .build();
    definitionDrafts.add(existingReferencingAttr);


    productTypesReferencingMissing1.put("referencing-product-type-1", definitionDrafts);
    productTypesReferencingMissing1.put("referencing-product-type-2", ConcurrentHashMap.newKeySet());

    final ConcurrentHashMap<String, ConcurrentHashMap.KeySetView<AttributeDefinitionDraft, Boolean>>
        productTypesReferencingMissing2 = new ConcurrentHashMap<>();
    productTypesReferencingMissing2.put("referencing-product-type-3", ConcurrentHashMap.newKeySet());
    productTypesReferencingMissing2.put("referencing-product-type-4", ConcurrentHashMap.newKeySet());

    missingProductTypeReferences.put("missing1", productTypesReferencingMissing1);
    missingProductTypeReferences.put("missing2", productTypesReferencingMissing2);

    final ProductTypeSyncStatistics productTypeSyncStatistics =
        new ProductTypeSyncStatistics(missingProductTypeReferences);

    // test
    productTypeSyncStatistics.removeReferencingProductTypeKey("referencing-product-type-1");

    // assertion
    assertThat(productTypeSyncStatistics.getProductTypeKeysWithMissingParents()).hasSize(2);
    assertThat(productTypeSyncStatistics.getProductTypeKeysWithMissingParents().get("missing1"))
        .containsOnlyKeys("referencing-product-type-2");
    assertThat(productTypeSyncStatistics.getProductTypeKeysWithMissingParents().get("missing2"))
        .containsOnlyKeys("referencing-product-type-3", "referencing-product-type-4");
}
 
Example 19
Source File: ProductTypeSyncStatistics.java    From commercetools-sync-java with Apache License 2.0 2 votes vote down vote up
/**
 * @return an unmodifiable {@link ConcurrentHashMap} ({@code missingNestedProductTypes}) which keeps track of the
 *         keys of missing product types, the keys of the product types which are referencing those missing product
 *         types and a list of attribute definitions which contains those references.
 * <ul>
 * <li>key: key of the missing product type</li>
 * <li>value: a map of which consists of:
 *      <ul>
 *          <li>key: key of the product type referencing the missing product type.</li>
 *          <li>value: a set of the attribute definition drafts which contains the reference
 *          to the missing product type.</li>
 *      </ul>
 * </li>
 * </ul>
 */
public Map<String,
    ConcurrentHashMap<String,
        ConcurrentHashMap.KeySetView<AttributeDefinitionDraft, Boolean>>> getProductTypeKeysWithMissingParents() {
    return Collections.unmodifiableMap(missingNestedProductTypes);
}
 
Example 20
Source File: SendReceiveThread.java    From sawtooth-sdk-java with Apache License 2.0 2 votes vote down vote up
/**
 * Return an enumeration of the coorelation ids.
 * @return coorelation ids.
 */
ConcurrentHashMap.KeySetView<String, Future> getFuturesKeySet() {
  return this.futures.keySet();
}