From 4efa498fab2dbe9ffc83f5ed5046c74541b66b2b Mon Sep 17 00:00:00 2001 From: Carmelo Cascone Date: Wed, 18 Apr 2018 18:58:56 +0900 Subject: [PATCH] Simplify creation of PiActionParam from primitive types Change-Id: I52053cbe60c4cba3746de1cbf67b16a47ce053bc --- .../net/pi/runtime/PiActionParam.java | 62 ++++++++++++++++++- 1 file changed, 60 insertions(+), 2 deletions(-) diff --git a/core/api/src/main/java/org/onosproject/net/pi/runtime/PiActionParam.java b/core/api/src/main/java/org/onosproject/net/pi/runtime/PiActionParam.java index 449810986e..a8d565cb1c 100644 --- a/core/api/src/main/java/org/onosproject/net/pi/runtime/PiActionParam.java +++ b/core/api/src/main/java/org/onosproject/net/pi/runtime/PiActionParam.java @@ -23,9 +23,11 @@ import org.onosproject.net.pi.model.PiActionParamId; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; +import static org.onlab.util.ImmutableByteSequence.copyFrom; /** - * Instance of an action runtime parameter in a match+action table of a protocol-independent pipeline. + * Instance of an action runtime parameter in a match+action table of a + * protocol-independent pipeline. */ @Beta public final class PiActionParam { @@ -34,7 +36,8 @@ public final class PiActionParam { private final ImmutableByteSequence value; /** - * Creates an action's runtime parameter. + * Creates an action's runtime parameter for the given param ID and byte + * sequence value. * * @param id parameter identifier * @param value value @@ -45,6 +48,61 @@ public final class PiActionParam { checkArgument(value.size() > 0, "Value can't have size 0"); } + /** + * Creates an action's runtime parameter for the given param ID and byte + * value. + * + * @param id parameter identifier + * @param value value + */ + public PiActionParam(PiActionParamId id, byte value) { + this(id, copyFrom(value)); + } + + /** + * Creates an action's runtime parameter for the given param ID and short + * value. + * + * @param id parameter identifier + * @param value value + */ + public PiActionParam(PiActionParamId id, short value) { + this(id, copyFrom(value)); + } + + /** + * Creates an action's runtime parameter for the given param ID and int + * value. + * + * @param id parameter identifier + * @param value value + */ + public PiActionParam(PiActionParamId id, int value) { + this(id, copyFrom(value)); + } + + /** + * Creates an action's runtime parameter for the given param ID and long + * value. + * + * @param id parameter identifier + * @param value value + */ + public PiActionParam(PiActionParamId id, long value) { + this(id, copyFrom(value)); + } + + /** + * Creates an action's runtime parameter for the given param ID and byte + * array value. + * + * @param id parameter identifier + * @param value value + */ + public PiActionParam(PiActionParamId id, byte[] value) { + this(id, copyFrom(value)); + } + /** * Returns the identifier of this parameter. *