@Override public List<SubjectReference> getParents(Set<Context> contexts) { List<Map.Entry<String, String>> ret = this.parents.get(contexts); return ret == null ? Collections.emptyList() : toSubjectList(ret); }
@Override public CompletableFuture<Boolean> removeParent(Set<Context> contexts, SubjectReference parent) { contexts = ImmutableSet.copyOf(contexts); while (true) { Map.Entry<String, String> removeEnt = Maps.immutableEntry(parent.getCollectionIdentifier(), parent.getSubjectIdentifier()); List<Map.Entry<String, String>> oldParents = this.parents.get(contexts); List<Map.Entry<String, String>> newParents; if (oldParents == null || !oldParents.contains(removeEnt)) { return CompletableFuture.completedFuture(false); } newParents = new ArrayList<>(oldParents); newParents.remove(removeEnt); if (updateCollection(this.parents, contexts, oldParents, Collections.unmodifiableList(newParents))) { return CompletableFuture.completedFuture(true); } } }
@Override public Map<Set<Context>, List<SubjectReference>> getAllParents() { ImmutableMap.Builder<Set<Context>, List<SubjectReference>> ret = ImmutableMap.builder(); for (Map.Entry<Set<Context>, List<Map.Entry<String, String>>> ent : this.parents.entrySet()) { ret.put(ent.getKey(), toSubjectList(ent.getValue())); } return ret.build(); }
@Override public CompletableFuture<Boolean> addParent(Set<Context> contexts, SubjectReference parent) { contexts = ImmutableSet.copyOf(contexts); while (true) { Map.Entry<String, String> newEnt = Maps.immutableEntry(parent.getCollectionIdentifier(), parent.getSubjectIdentifier()); List<Map.Entry<String, String>> oldParents = this.parents.get(contexts); List<Map.Entry<String, String>> newParents = ImmutableList.<Map.Entry<String, String>>builder() .addAll(oldParents == null ? Collections.emptyList() : oldParents) .add(newEnt) .build(); if (oldParents != null && oldParents.contains(newEnt)) { return CompletableFuture.completedFuture(false); } if (updateCollection(this.parents, contexts, oldParents, newParents)) { return CompletableFuture.completedFuture(true); } } }
@Override public List<Subject> getParents(Set<Context> contexts) { List<Map.Entry<String, String>> ret = this.parents.get(contexts); return ret == null ? Collections.emptyList() : toSubjectList(ret); }
@Override public boolean addParent(Set<Context> contexts, Subject parent) { contexts = ImmutableSet.copyOf(contexts); while (true) { Map.Entry<String, String> newEnt = Maps.immutableEntry(parent.getContainingCollection().getIdentifier(), parent.getIdentifier()); List<Map.Entry<String, String>> oldParents = this.parents.get(contexts); List<Map.Entry<String, String>> newParents = ImmutableList.<Map.Entry<String, String>>builder() .addAll(oldParents == null ? Collections.emptyList() : oldParents) .add(newEnt) .build(); if (oldParents != null && oldParents.contains(newEnt)) { return false; } if (updateCollection(this.parents, contexts, oldParents, newParents)) { return true; } } }
@Override public Map<Set<Context>, List<Subject>> getAllParents() { ImmutableMap.Builder<Set<Context>, List<Subject>> ret = ImmutableMap.builder(); for (Map.Entry<Set<Context>, List<Map.Entry<String, String>>> ent : this.parents.entrySet()) { ret.put(ent.getKey(), toSubjectList(ent.getValue())); } return ret.build(); }
@Override public boolean removeParent(Set<Context> contexts, Subject parent) { contexts = ImmutableSet.copyOf(contexts); while (true) { Map.Entry<String, String> removeEnt = Maps.immutableEntry(parent.getContainingCollection().getIdentifier(), parent.getIdentifier()); List<Map.Entry<String, String>> oldParents = this.parents.get(contexts); List<Map.Entry<String, String>> newParents; if (oldParents == null || !oldParents.contains(removeEnt)) { return false; } newParents = new ArrayList<>(oldParents); newParents.remove(removeEnt); if (updateCollection(this.parents, contexts, oldParents, Collections.unmodifiableList(newParents))) { return true; } } }