/** * Removes the Resource with the given {@code resourceType} and {@code resourcePath} from a copy of this Resources. * * @param resourceType the type of the Resource to be removed. * @param resourcePath the path of the Resource to be removed. * @return a copy of this Resources with {@code resource} removed. * @throws NullPointerException if any argument is {@code null}. * @throws IllegalArgumentException if {@code resourceType} is empty. */ default Resources removeResource(final String resourceType, final CharSequence resourcePath) { return removeResource(ResourceKey.newInstance(resourceType, resourcePath)); }
@Override public Policy removeResourceFor(final CharSequence label, final ResourceKey resourceKey) { final Label lbl = Label.of(label); Policy result = this; final PolicyEntry existingEntry = entries.get(lbl); if (null != existingEntry) { final Resources existingResources = existingEntry.getResources(); final Resources newResources = existingResources.removeResource(resourceKey); if (!Objects.equals(existingResources, newResources)) { final Map<Label, PolicyEntry> entriesCopy = copyEntries(); entriesCopy.put(lbl, newPolicyEntry(lbl, existingEntry.getSubjects(), newResources)); result = new ImmutablePolicy(policyId, entriesCopy, lifecycle, revision, modified); } } return result; }