blob: f53806b23f2ad04b903c7d467104bf6cb8a88fde [file] [log] [blame]
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.bmv2.api.model;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Maps;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Objects;
import static com.google.common.base.MoreObjects.toStringHelper;
/**
* BMv2 model action.
*/
public final class Bmv2ModelAction {
private final String name;
private final int id;
private final LinkedHashMap<String, Bmv2ModelRuntimeData> runtimeDatas = Maps.newLinkedHashMap();
/**
* Creates a new action object.
*
* @param name name
* @param id id
* @param runtimeDatas list of runtime data
*/
protected Bmv2ModelAction(String name, int id, List<Bmv2ModelRuntimeData> runtimeDatas) {
this.name = name;
this.id = id;
runtimeDatas.forEach(r -> this.runtimeDatas.put(r.name(), r));
}
/**
* Returns the name of this action.
*
* @return a string value
*/
public String name() {
return name;
}
/**
* Returns the id of this action.
*
* @return an integer value
*/
public int id() {
return id;
}
/**
* Returns this action's runtime data defined by the passed name, null
* if not present.
*
* @return runtime data or null
*/
public Bmv2ModelRuntimeData runtimeData(String name) {
return runtimeDatas.get(name);
}
/**
* Returns an immutable list of runtime data for this action.
* The list is ordered according to the values defined in the model.
*
* @return list of runtime data.
*/
public List<Bmv2ModelRuntimeData> runtimeDatas() {
return ImmutableList.copyOf(runtimeDatas.values());
}
@Override
public int hashCode() {
return Objects.hash(name, id, runtimeDatas);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null || getClass() != obj.getClass()) {
return false;
}
final Bmv2ModelAction other = (Bmv2ModelAction) obj;
return Objects.equals(this.name, other.name)
&& Objects.equals(this.id, other.id)
&& Objects.equals(this.runtimeDatas, other.runtimeDatas);
}
@Override
public String toString() {
return toStringHelper(this)
.add("name", name)
.add("id", id)
.add("runtimeDatas", runtimeDatas)
.toString();
}
}