import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
+import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import java.util.ArrayList;
import java.util.Collection;
getSender().tell(SuccessReply.INSTANCE, getSelf());
searchForEntities((entityTypeNode, entityNode) -> {
- Optional<DataContainerChild<?, ?>> possibleType = entityTypeNode.getChild(ENTITY_TYPE_NODE_ID);
+ java.util.Optional<DataContainerChild<?, ?>> possibleType = entityTypeNode.getChild(ENTITY_TYPE_NODE_ID);
String entityType = possibleType.isPresent() ? possibleType.get().getValue().toString() : null;
if (registerListener.getEntityType().equals(entityType)) {
final boolean hasOwner;
final boolean isOwner;
- Optional<DataContainerChild<?, ?>> possibleOwner = entityNode.getChild(ENTITY_OWNER_NODE_ID);
+ java.util.Optional<DataContainerChild<?, ?>> possibleOwner = entityNode.getChild(ENTITY_OWNER_NODE_ID);
if (possibleOwner.isPresent()) {
isOwner = localMemberName.getName().equals(possibleOwner.get().getValue().toString());
hasOwner = true;
private void notifyAllListeners() {
searchForEntities((entityTypeNode, entityNode) -> {
- Optional<DataContainerChild<?, ?>> possibleType = entityTypeNode.getChild(ENTITY_TYPE_NODE_ID);
+ java.util.Optional<DataContainerChild<?, ?>> possibleType = entityTypeNode.getChild(ENTITY_TYPE_NODE_ID);
if (possibleType.isPresent()) {
final boolean hasOwner;
final boolean isOwner;
- Optional<DataContainerChild<?, ?>> possibleOwner = entityNode.getChild(ENTITY_OWNER_NODE_ID);
+ java.util.Optional<DataContainerChild<?, ?>> possibleOwner = entityNode.getChild(ENTITY_OWNER_NODE_ID);
if (possibleOwner.isPresent()) {
isOwner = localMemberName.getName().equals(possibleOwner.get().getValue().toString());
hasOwner = true;
.node(entityTypeNode.getIdentifier()).node(ENTITY_NODE_ID).node(entityNode.getIdentifier())
.node(ENTITY_OWNER_NODE_ID).build();
- Optional<String> possibleOwner = entityNode.getChild(ENTITY_OWNER_NODE_ID).transform(
- node -> node.getValue().toString());
- String newOwner = newOwner(possibleOwner.orNull(), getCandidateNames(entityNode),
+ java.util.Optional<String> possibleOwner =
+ entityNode.getChild(ENTITY_OWNER_NODE_ID).map(node -> node.getValue().toString());
+ String newOwner = newOwner(possibleOwner.orElse(null), getCandidateNames(entityNode),
getEntityOwnerElectionStrategy(entityPath));
- if (!newOwner.equals(possibleOwner.or(""))) {
+ if (!newOwner.equals(possibleOwner.orElse(""))) {
modifications.add(new WriteModification(entityPath,
ImmutableNodes.leafNode(ENTITY_OWNER_NODE_ID, newOwner)));
}
} else {
LOG.debug("{}: Found entity {} but no other candidates - not clearing owner", persistenceId(),
- entityPath, newOwner);
+ entityPath);
}
});
}
private static Collection<String> getCandidateNames(final MapEntryNode entity) {
- Collection<MapEntryNode> candidates = ((MapNode)entity.getChild(CANDIDATE_NODE_ID).get()).getValue();
- Collection<String> candidateNames = new ArrayList<>(candidates.size());
- for (MapEntryNode candidate: candidates) {
- candidateNames.add(candidate.getChild(CANDIDATE_NAME_NODE_ID).get().getValue().toString());
- }
-
- return candidateNames;
+ return entity.getChild(CANDIDATE_NODE_ID).map(child -> {
+ Collection<MapEntryNode> candidates = ((MapNode) child).getValue();
+ Collection<String> candidateNames = new ArrayList<>(candidates.size());
+ for (MapEntryNode candidate: candidates) {
+ candidateNames.add(candidate.getChild(CANDIDATE_NAME_NODE_ID).get().getValue().toString());
+ }
+ return candidateNames;
+ }).orElse(ImmutableList.of());
}
private void searchForEntitiesOwnedBy(final Set<String> ownedBy, final EntityWalker walker) {
LOG.debug("{}: Searching for entities owned by {}", persistenceId(), ownedBy);
searchForEntities((entityTypeNode, entityNode) -> {
- Optional<DataContainerChild<? extends PathArgument, ?>> possibleOwner =
+ java.util.Optional<DataContainerChild<? extends PathArgument, ?>> possibleOwner =
entityNode.getChild(ENTITY_OWNER_NODE_ID);
String currentOwner = possibleOwner.isPresent() ? possibleOwner.get().getValue().toString() : "";
if (ownedBy.contains(currentOwner)) {
}
private static boolean hasCandidate(final MapEntryNode entity, final MemberName candidateName) {
- return ((MapNode)entity.getChild(CANDIDATE_NODE_ID).get()).getChild(candidateNodeKey(candidateName.getName()))
+ return entity.getChild(CANDIDATE_NODE_ID)
+ .flatMap(child -> ((MapNode)child).getChild(candidateNodeKey(candidateName.getName())))
.isPresent();
}
}
for (MapEntryNode entityType: ((MapNode) possibleEntityTypes.get()).getValue()) {
- Optional<DataContainerChild<?, ?>> possibleEntities = entityType.getChild(ENTITY_NODE_ID);
+ java.util.Optional<DataContainerChild<?, ?>> possibleEntities = entityType.getChild(ENTITY_NODE_ID);
if (!possibleEntities.isPresent()) {
// shouldn't happen but handle anyway
continue;