Migrate entity ownership to JDT annotations
[mdsal.git] / entityownership / mdsal-eos-common-api / src / main / java / org / opendaylight / mdsal / eos / common / api / GenericEntityOwnershipChange.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 org.eclipse.jdt.annotation.NonNull;
13 import org.opendaylight.yangtools.concepts.Path;
14
15 /**
16  * A DTO that encapsulates an ownership change for an entity.
17  *
18  * @author Thomas Pantelis
19  *
20  * @param <P> the instance identifier path type
21  * @param <E> the GenericEntity type
22  */
23 public class GenericEntityOwnershipChange<P extends Path<P>, E extends GenericEntity<P>> {
24     private final @NonNull E entity;
25     private final @NonNull EntityOwnershipChangeState state;
26     private final boolean inJeopardy;
27
28     public GenericEntityOwnershipChange(final @NonNull E entity, final @NonNull EntityOwnershipChangeState state) {
29         this(entity, state, false);
30     }
31
32     public GenericEntityOwnershipChange(final @NonNull E entity, final @NonNull EntityOwnershipChangeState state,
33             final boolean inJeopardy) {
34         this.entity = requireNonNull(entity, "entity can't be null");
35         this.state = requireNonNull(state, "state can't be null");
36         this.inJeopardy = inJeopardy;
37     }
38
39     /**
40      * Returns the entity whose ownership status changed.
41      * @return the entity
42      */
43     public @NonNull E getEntity() {
44         return entity;
45     }
46
47     /**
48      * Returns the ownership change state.
49      * @return an EntityOwnershipChangeState enum
50      */
51     public @NonNull EntityOwnershipChangeState getState() {
52         return state;
53     }
54
55     /**
56      * Returns the current jeopardy state. When in a jeopardy state, the values from other methods may potentially
57      * be out of date.
58      *
59      * @return true if the local node is in a jeopardy state. If false, the reported information is accurate.
60      */
61     public boolean inJeopardy() {
62         return inJeopardy;
63     }
64
65     @Override
66     public String toString() {
67         return getClass().getSimpleName() + " [entity=" + entity + ", state=" + state
68                 + ", inJeopardy=" + inJeopardy + "]";
69     }
70 }