Cleanup test format
[controller.git] / opendaylight / md-sal / eos-dom-akka / src / main / java / org / opendaylight / controller / eos / akka / owner / checker / command / GetEntityReply.java
1 /*
2  * Copyright (c) 2021 PANTHEON.tech, s.r.o. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.eos.akka.owner.checker.command;
9
10 import com.google.common.collect.ImmutableSet;
11 import java.io.Serializable;
12 import java.util.Set;
13 import java.util.stream.Collectors;
14 import org.eclipse.jdt.annotation.NonNull;
15 import org.eclipse.jdt.annotation.Nullable;
16 import org.opendaylight.controller.eos.akka.owner.supervisor.command.GetEntityBackendReply;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.GetEntityOutput;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.GetEntityOutputBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.NodeName;
20
21 public final class GetEntityReply extends StateCheckerReply implements Serializable {
22     private static final long serialVersionUID = 1L;
23
24     private final ImmutableSet<String> candidates;
25     private final String owner;
26
27     public GetEntityReply(final GetEntityBackendReply backendReply) {
28         candidates = backendReply.getCandidates();
29         owner = backendReply.getOwner();
30     }
31
32     public GetEntityReply(final @Nullable String owner, final @Nullable Set<String> candidates) {
33         this.owner = owner;
34         this.candidates = candidates == null ? ImmutableSet.of() : ImmutableSet.copyOf(candidates);
35     }
36
37     public @NonNull GetEntityOutput toOutput() {
38         final GetEntityOutputBuilder builder = new GetEntityOutputBuilder();
39         if (owner != null) {
40             builder.setOwnerNode(new NodeName(owner));
41         }
42         return builder
43             .setCandidateNodes(candidates.stream().map(NodeName::new).collect(Collectors.toUnmodifiableList()))
44             .build();
45     }
46 }