dfc5bcee75fd8a61f8bf7bf7a6740eb46c0b0d24
[genius.git] / mdsalutil / mdsalutil-api / src / main / java / org / opendaylight / genius / mdsalutil / AbstractActionInfoList.java
1 /*
2  * Copyright © 2016, 2017 Red Hat 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.genius.mdsalutil;
9
10 import java.util.ArrayList;
11 import java.util.Collections;
12 import java.util.List;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action;
14
15 /**
16  * List<ActionInfo> with method to build List<Action> from it.
17  *
18  * @author Michael Vorburger
19  */
20 public abstract class AbstractActionInfoList {
21
22     private final List<ActionInfo> actionInfos = new ArrayList<>();
23
24     protected AbstractActionInfoList(List<ActionInfo> actionInfos) {
25         super();
26         if (actionInfos != null) {
27             this.actionInfos.addAll(actionInfos);
28         }
29     }
30
31     public List<ActionInfo> getActionInfos() {
32         return Collections.unmodifiableList(actionInfos);
33     }
34
35     public List<Action> buildActions() {
36         int newActionKey = 0;
37         List<Action> actions = new ArrayList<>(actionInfos.size());
38         for (ActionInfo actionInfo: actionInfos) {
39             ActionType actionType = actionInfo.getActionType();
40             actions.add(actionType.buildAction(newActionKey++, actionInfo));
41         }
42         return actions;
43     }
44
45     @Override
46     public boolean equals(Object o) {
47         if (this == o) return true;
48         if (o == null || getClass() != o.getClass()) return false;
49
50         AbstractActionInfoList that = (AbstractActionInfoList) o;
51
52         return actionInfos != null ? actionInfos.equals(that.actionInfos) : that.actionInfos == null;
53     }
54
55     @Override
56     public int hashCode() {
57         return actionInfos != null ? actionInfos.hashCode() : 0;
58     }
59 }