public void keepPaths(List<? extends ItemPath> keep) { if (items != null) { for (Iterator<Item<?, ?>> iterator = items.iterator(); iterator.hasNext(); ) { Item<?, ?> item = iterator.next(); ItemPath itemPath = item.getPath().removeIds(); if (!ItemPathCollectionsUtil.containsSuperpathOrEquivalent(keep, itemPath)) { iterator.remove(); } else { if (item instanceof PrismContainer) { ((PrismContainer<?>) item).getValues().forEach(v -> v.keepPaths(keep)); } else { // TODO some additional checks here (e.g. when trying to keep 'name/xyz' - this is illegal) } } } } }
@Override public void trimTo(@NotNull Collection<ItemPath> paths) { if (shared) { // TODO switch this to warning before releasing this code (3.6.1 or 3.7) throw new IllegalStateException("Couldn't trim shared definition: " + this); } for (Iterator<ItemDefinition> iterator = itemDefinitions.iterator(); iterator.hasNext(); ) { ItemDefinition<?> itemDef = iterator.next(); ItemPath itemPath = itemDef.getName(); if (!ItemPathCollectionsUtil.containsSuperpathOrEquivalent(paths, itemPath)) { iterator.remove(); } else if (itemDef instanceof PrismContainerDefinition) { PrismContainerDefinition<?> itemPcd = (PrismContainerDefinition<?>) itemDef; if (itemPcd.getComplexTypeDefinition() != null) { itemPcd.getComplexTypeDefinition().trimTo(ItemPathCollectionsUtil.remainder(paths, itemPath, false)); } } } }
assertFalse(ItemPathCollectionsUtil.containsSuperpathOrEquivalent(onlyEmpty, pathFoo)); assertFalse(ItemPathCollectionsUtil.containsSuperpath(onlyEmpty, pathFoo)); assertTrue(ItemPathCollectionsUtil.containsSuperpathOrEquivalent(onlyEmpty, empty)); assertFalse(ItemPathCollectionsUtil.containsSuperpath(onlyEmpty, empty)); assertTrue(ItemPathCollectionsUtil.containsSuperpathOrEquivalent(onlyFoo, pathFoo)); assertFalse(ItemPathCollectionsUtil.containsSuperpath(onlyFoo, pathFoo)); assertTrue(ItemPathCollectionsUtil.containsSuperpathOrEquivalent(onlyFoo, empty)); assertTrue(ItemPathCollectionsUtil.containsSuperpath(onlyFoo, empty)); assertFalse(ItemPathCollectionsUtil.containsSuperpathOrEquivalent(onlyFoo, pathZoo)); assertFalse(ItemPathCollectionsUtil.containsSuperpath(onlyFoo, pathZoo)); assertTrue(ItemPathCollectionsUtil.containsSuperpathOrEquivalent(onlyFooBar, pathFoo)); assertTrue(ItemPathCollectionsUtil.containsSuperpath(onlyFooBar, pathFoo)); assertFalse(ItemPathCollectionsUtil.containsSuperpathOrEquivalent(onlyFooBar, pathFooBarBaz)); assertFalse(ItemPathCollectionsUtil.containsSuperpath(onlyFooBar, pathFooBarBaz));