Search in sources :

Example 1 with MutableObjectIntMap

use of org.eclipse.collections.api.map.primitive.MutableObjectIntMap in project legend-pure by finos.

the class TestIdBuilder method testIdUniqueness.

private void testIdUniqueness(IdBuilder idBuilder) {
    MutableSet<CoreInstance> excludedClassifiers = PrimitiveUtilities.getPrimitiveTypes(processorSupport).toSet();
    MutableMap<CoreInstance, MutableSet<String>> classifierIds = Maps.mutable.empty();
    MutableMap<CoreInstance, MutableObjectIntMap<String>> idConflicts = Maps.mutable.empty();
    GraphNodeIterable.fromModelRepository(runtime.getModelRepository()).forEach(instance -> {
        CoreInstance classifier = instance.getClassifier();
        if (!excludedClassifiers.contains(classifier)) {
            String id = idBuilder.buildId(instance);
            if (!classifierIds.getIfAbsentPut(classifier, Sets.mutable::empty).add(id)) {
                idConflicts.getIfAbsentPut(classifier, ObjectIntMaps.mutable::empty).updateValue(id, 1, n -> n + 1);
            }
        }
    });
    if (idConflicts.notEmpty()) {
        MutableMap<CoreInstance, String> classifierPaths = idConflicts.keysView().toMap(c -> c, PackageableElement::getUserPathForPackageableElement);
        StringBuilder builder = new StringBuilder("The following ids have conflicts:");
        idConflicts.keysView().toSortedListBy(classifierPaths::get).forEach(classifier -> {
            builder.append("\n\t").append(classifierPaths.get(classifier));
            ObjectIntMap<String> classifierIdConflicts = idConflicts.get(classifier);
            classifierIdConflicts.forEachKeyValue((id, count) -> builder.append("\n\t\t").append(id).append(": ").append(count).append(" instances"));
        });
        Assert.fail(builder.toString());
    }
}
Also used : MutableSet(org.eclipse.collections.api.set.MutableSet) PackageableElement(org.finos.legend.pure.m3.navigation.PackageableElement.PackageableElement) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) ObjectIntMaps(org.eclipse.collections.impl.factory.primitive.ObjectIntMaps) MutableObjectIntMap(org.eclipse.collections.api.map.primitive.MutableObjectIntMap)

Example 2 with MutableObjectIntMap

use of org.eclipse.collections.api.map.primitive.MutableObjectIntMap in project legend-pure by finos.

the class TestIdBuilderCore method testIdUniqueness.

private void testIdUniqueness(IdBuilder idBuilder) {
    // ImportGroup is excluded because of a known issue with conflicts with ImportGroup ids independent of IdBuilder
    MutableSet<CoreInstance> excludedClassifiers = PrimitiveUtilities.getPrimitiveTypes(processorSupport).toSet().with(processorSupport.package_getByUserPath(M3Paths.ImportGroup));
    MutableMap<CoreInstance, MutableSet<String>> classifierIds = Maps.mutable.empty();
    MutableMap<CoreInstance, MutableObjectIntMap<String>> idConflicts = Maps.mutable.empty();
    GraphNodeIterable.fromModelRepository(runtime.getModelRepository()).forEach(instance -> {
        CoreInstance classifier = instance.getClassifier();
        if (!excludedClassifiers.contains(classifier)) {
            String id = idBuilder.buildId(instance);
            if (!classifierIds.getIfAbsentPut(classifier, Sets.mutable::empty).add(id)) {
                idConflicts.getIfAbsentPut(classifier, ObjectIntMaps.mutable::empty).updateValue(id, 1, n -> n + 1);
            }
        }
    });
    if (idConflicts.notEmpty()) {
        MutableMap<CoreInstance, String> classifierPaths = idConflicts.keysView().toMap(c -> c, PackageableElement::getUserPathForPackageableElement);
        StringBuilder builder = new StringBuilder("The following ids have conflicts:");
        idConflicts.keysView().toSortedListBy(classifierPaths::get).forEach(classifier -> {
            builder.append("\n\t").append(classifierPaths.get(classifier));
            ObjectIntMap<String> classifierIdConflicts = idConflicts.get(classifier);
            classifierIdConflicts.forEachKeyValue((id, count) -> builder.append("\n\t\t").append(id).append(": ").append(count).append(" instances"));
        });
        Assert.fail(builder.toString());
    }
}
Also used : MutableSet(org.eclipse.collections.api.set.MutableSet) PackageableElement(org.finos.legend.pure.m3.navigation.PackageableElement.PackageableElement) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) ObjectIntMaps(org.eclipse.collections.impl.factory.primitive.ObjectIntMaps) MutableObjectIntMap(org.eclipse.collections.api.map.primitive.MutableObjectIntMap)

Aggregations

MutableObjectIntMap (org.eclipse.collections.api.map.primitive.MutableObjectIntMap)2 MutableSet (org.eclipse.collections.api.set.MutableSet)2 ObjectIntMaps (org.eclipse.collections.impl.factory.primitive.ObjectIntMaps)2 PackageableElement (org.finos.legend.pure.m3.navigation.PackageableElement.PackageableElement)2 CoreInstance (org.finos.legend.pure.m4.coreinstance.CoreInstance)2