mirror of
https://github.com/opennetworkinglab/onos.git
synced 2025-10-17 10:21:52 +02:00
Added builder for PortDescription
Change-Id: I37cf78ba7d2cebb021806a0441f2bf231a855c28
This commit is contained in:
parent
498fa1d321
commit
9f2d724c0b
@ -17,9 +17,9 @@ package org.onosproject.net.device;
|
|||||||
|
|
||||||
import com.google.common.base.MoreObjects;
|
import com.google.common.base.MoreObjects;
|
||||||
import org.onosproject.net.AbstractDescription;
|
import org.onosproject.net.AbstractDescription;
|
||||||
|
import org.onosproject.net.DefaultAnnotations;
|
||||||
import org.onosproject.net.PortNumber;
|
import org.onosproject.net.PortNumber;
|
||||||
import org.onosproject.net.SparseAnnotations;
|
import org.onosproject.net.SparseAnnotations;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import static org.onosproject.net.Port.Type;
|
import static org.onosproject.net.Port.Type;
|
||||||
import com.google.common.base.Objects;
|
import com.google.common.base.Objects;
|
||||||
@ -177,4 +177,118 @@ public class DefaultPortDescription extends AbstractDescription
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates port description builder with default parameters.
|
||||||
|
*
|
||||||
|
* @return builder
|
||||||
|
*/
|
||||||
|
public static Builder builder() {
|
||||||
|
return new Builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates port description builder inheriting with default parameters,
|
||||||
|
* from specified port description.
|
||||||
|
*
|
||||||
|
* @param desc to inherit default from
|
||||||
|
* @return builder
|
||||||
|
*/
|
||||||
|
public static Builder builder(PortDescription desc) {
|
||||||
|
return new Builder(desc);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Builder {
|
||||||
|
private PortNumber number;
|
||||||
|
private boolean isEnabled = true;
|
||||||
|
private boolean isRemoved = false;
|
||||||
|
private Type type = Type.COPPER;
|
||||||
|
private long portSpeed = DEFAULT_SPEED;
|
||||||
|
private SparseAnnotations annotations = DefaultAnnotations.EMPTY;
|
||||||
|
|
||||||
|
Builder() {}
|
||||||
|
|
||||||
|
Builder(PortDescription desc) {
|
||||||
|
this.number = desc.portNumber();
|
||||||
|
this.isEnabled = desc.isEnabled();
|
||||||
|
this.isRemoved = desc.isRemoved();
|
||||||
|
this.type = desc.type();
|
||||||
|
this.portSpeed = desc.portSpeed();
|
||||||
|
this.annotations = desc.annotations();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets mandatory field PortNumber.
|
||||||
|
*
|
||||||
|
* @param number to set
|
||||||
|
* @return self
|
||||||
|
*/
|
||||||
|
public Builder withPortNumer(PortNumber number) {
|
||||||
|
this.number = checkNotNull(number);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets enabled state.
|
||||||
|
*
|
||||||
|
* @param enabled state
|
||||||
|
* @return self
|
||||||
|
*/
|
||||||
|
public Builder isEnabled(boolean enabled) {
|
||||||
|
this.isEnabled = enabled;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets removed state.
|
||||||
|
*
|
||||||
|
* @param removed state
|
||||||
|
* @return self
|
||||||
|
*/
|
||||||
|
public Builder isRemoved(boolean removed) {
|
||||||
|
this.isRemoved = removed;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets port type.
|
||||||
|
*
|
||||||
|
* @param type of the port
|
||||||
|
* @return self
|
||||||
|
*/
|
||||||
|
public Builder type(Type type) {
|
||||||
|
this.type = type;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets port speed.
|
||||||
|
*
|
||||||
|
* @param mbps port speed in Mbps
|
||||||
|
* @return self
|
||||||
|
*/
|
||||||
|
public Builder portSpeed(long mbps) {
|
||||||
|
this.portSpeed = mbps;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets annotations.
|
||||||
|
*
|
||||||
|
* @param annotations of the port
|
||||||
|
* @return self
|
||||||
|
*/
|
||||||
|
public Builder annotations(SparseAnnotations annotations) {
|
||||||
|
this.annotations = checkNotNull(annotations);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds the port description.
|
||||||
|
*
|
||||||
|
* @return port description
|
||||||
|
*/
|
||||||
|
public DefaultPortDescription build() {
|
||||||
|
return new DefaultPortDescription(number, isEnabled, isRemoved, type, portSpeed, annotations);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user