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