package io.vertx.core.http;
import io.netty.handler.codec.http2.Http2CodecUtil;
import io.vertx.codegen.annotations.DataObject;
import io.vertx.core.json.JsonObject;
@DataObject
public class StreamPriority {
public static final int DEFAULT_DEPENDENCY = 0;
public static final short DEFAULT_WEIGHT = Http2CodecUtil.DEFAULT_PRIORITY_WEIGHT;
public static final boolean DEFAULT_EXCLUSIVE = false;
private short weight;
private int dependency;
private boolean exclusive;
public StreamPriority() {
weight = DEFAULT_WEIGHT;
dependency = DEFAULT_DEPENDENCY;
exclusive = DEFAULT_EXCLUSIVE;
}
public StreamPriority(JsonObject json) {
this.weight = json.getInteger("weight", (int)DEFAULT_WEIGHT).shortValue();
this.dependency = json.getInteger("dependency", DEFAULT_DEPENDENCY);
this.exclusive = json.getBoolean("exclusive", DEFAULT_EXCLUSIVE);
}
public StreamPriority(StreamPriority other) {
this.weight = other.weight;
this.dependency = other.dependency;
this.exclusive = other.exclusive;
}
public short getWeight() {
return weight;
}
public StreamPriority setWeight(short weight) {
this.weight = weight;
return this;
}
public int getDependency() {
return dependency;
}
public StreamPriority setDependency(int dependency) {
this.dependency = dependency;
return this;
}
public boolean isExclusive() {
return exclusive;
}
public StreamPriority setExclusive(boolean exclusive) {
this.exclusive = exclusive;
return this;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (exclusive ? 1231 : 1237);
result = prime * result + dependency;
result = prime * result + weight;
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null) return false;
if (getClass() != obj.getClass()) return false;
StreamPriority other = (StreamPriority) obj;
if (exclusive != other.exclusive) return false;
if (dependency != other.dependency) return false;
if (weight != other.weight) return false;
return true;
}
public JsonObject toJson() {
JsonObject json = new JsonObject();
json.put("weight", weight);
json.put("dependency", dependency);
json.put("exclusive", exclusive);
return json;
}
@Override
public String toString() {
return "StreamPriority [weight=" + weight + ", dependency=" + dependency + ", exclusive=" + exclusive + "]";
}
}