org.projectfloodlight.openflow.protocol.OFOxsList Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of openflowj Show documentation
Show all versions of openflowj Show documentation
OpenFlowJ API supporting OpenFlow versions 1.0 through 1.5.1, generated by LoxiGen
The newest version!
package org.projectfloodlight.openflow.protocol;
import java.util.EnumMap;
import java.util.Iterator;
import java.util.Map;
import org.projectfloodlight.openflow.exceptions.OFParseError;
import org.projectfloodlight.openflow.protocol.oxs.OFOxs;
import org.projectfloodlight.openflow.protocol.stat.StatField;
import org.projectfloodlight.openflow.protocol.stat.StatFields;
import org.projectfloodlight.openflow.types.OFValueType;
import org.projectfloodlight.openflow.types.PrimitiveSinkable;
import org.projectfloodlight.openflow.util.ChannelUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.collect.ImmutableMap;
import com.google.common.hash.PrimitiveSink;
import io.netty.buffer.ByteBuf;
public class OFOxsList implements Iterable>, Writeable, PrimitiveSinkable {
private static final Logger logger = LoggerFactory.getLogger(OFOxsList.class);
private final Map> oxsMap;
public final static OFOxsList EMPTY = new OFOxsList(ImmutableMap.>of());
private OFOxsList(Map> oxsMap) {
this.oxsMap = oxsMap;
}
@SuppressWarnings("unchecked")
public > OFOxs get(StatField statField) {
return (OFOxs) oxsMap.get(statField.id);
}
public static class Builder {
private final Map> oxsMap;
public Builder() {
oxsMap = new EnumMap>(StatFields.class);
}
public Builder(EnumMap> oxsMap) {
this.oxsMap = oxsMap;
}
public > void set(OFOxs oxs) {
oxsMap.put(oxs.getStatField().id, oxs);
}
public > void unset(StatField statField) {
oxsMap.remove(statField.id);
}
public OFOxsList build() {
return OFOxsList.ofList(oxsMap.values());
}
}
@Override
public Iterator> iterator() {
return oxsMap.values().iterator();
}
public static OFOxsList ofList(Iterable> oxsList) {
Map> map = new EnumMap>(
StatFields.class);
for (OFOxs> o : oxsList) {
map.put(o.getStatField().id, o);
}
return new OFOxsList(map);
}
public static OFOxsList of(OFOxs>... oxss) {
Map> map = new EnumMap>(
StatFields.class);
for (OFOxs> o : oxss) {
map.put(o.getStatField().id, o);
}
return new OFOxsList(map);
}
public static OFOxsList readFrom(ByteBuf bb, int length,
OFMessageReader> reader) throws OFParseError {
return ofList(ChannelUtils.readList(bb, length, reader));
}
@Override
public void writeTo(ByteBuf bb) {
for (OFOxs> o : this) {
o.writeTo(bb);
}
}
public OFOxsList.Builder createBuilder() {
return new OFOxsList.Builder(new EnumMap>(oxsMap));
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((oxsMap == null) ? 0 : oxsMap.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
OFOxsList other = (OFOxsList) obj;
if (oxsMap == null) {
if (other.oxsMap != null)
return false;
} else if (!oxsMap.equals(other.oxsMap))
return false;
return true;
}
@Override
public String toString() {
return "OFOxsList" + oxsMap;
}
@Override
public void putTo(PrimitiveSink sink) {
for (OFOxs> o : this) {
o.putTo(sink);
}
}
}