Rename EntityOwnershipChangeState
[mdsal.git] / entityownership / mdsal-eos-common-api / src / main / java / org / opendaylight / mdsal / eos / common / api / EntityOwnershipChange.java
1 /*
2  * Copyright (c) 2015 Brocade Communications Systems, Inc. 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.mdsal.eos.common.api;
9
10 import static java.util.Objects.requireNonNull;
11
12 import com.google.common.base.MoreObjects;
13 import org.eclipse.jdt.annotation.NonNull;
14
15 /**
16  * A DTO that encapsulates an ownership change for an entity.
17  *
18  * @param <E> the {@link GenericEntity} type
19  * @author Thomas Pantelis
20  */
21 public final class EntityOwnershipChange<E extends GenericEntity<?>> {
22     private final @NonNull E entity;
23     private final @NonNull EntityOwnershipStateChange state;
24     private final boolean inJeopardy;
25
26     public EntityOwnershipChange(final @NonNull E entity, final @NonNull EntityOwnershipStateChange state) {
27         this(entity, state, false);
28     }
29
30     public EntityOwnershipChange(final @NonNull E entity, final @NonNull EntityOwnershipStateChange state,
31             final boolean inJeopardy) {
32         this.entity = requireNonNull(entity, "entity can't be null");
33         this.state = requireNonNull(state, "state can't be null");
34         this.inJeopardy = inJeopardy;
35     }
36
37     /**
38      * Returns the entity whose ownership status changed.
39      * @return the entity
40      */
41     public @NonNull E getEntity() {
42         return entity;
43     }
44
45     /**
46      * Returns the ownership change state.
47      * @return an EntityOwnershipStateChange enum
48      */
49     public @NonNull EntityOwnershipStateChange getState() {
50         return state;
51     }
52
53     /**
54      * Returns the current jeopardy state. When in a jeopardy state, the values from other methods may potentially
55      * be out of date.
56      *
57      * @return true if the local node is in a jeopardy state. If false, the reported information is accurate.
58      */
59     public boolean inJeopardy() {
60         return inJeopardy;
61     }
62
63     @Override
64     public String toString() {
65         return MoreObjects.toStringHelper(this)
66             .add("entity", entity)
67             .add("state", state)
68             .add("inJeopardy", inJeopardy)
69             .toString();
70     }
71 }