Java Code Examples for org.apache.mesos.Protos.Value#getType()
The following examples show how to use
org.apache.mesos.Protos.Value#getType() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ValueUtils.java From dcos-commons with Apache License 2.0 | 6 votes |
public static Value add(Value val1, Value val2) { Type type1 = val1.getType(); Type type2 = val2.getType(); if (type1 != type2) { throw new IllegalArgumentException(String.format( "Values to add do not have matching type: %s vs %s", TextFormat.shortDebugString(val1), TextFormat.shortDebugString(val2))); } switch (type1) { case SCALAR: Value.Scalar scalar = add(val1.getScalar(), val2.getScalar()); return Value.newBuilder().setType(type1).setScalar(scalar).build(); case RANGES: Value.Ranges ranges = add(val1.getRanges(), val2.getRanges()); return Value.newBuilder().setType(type1).setRanges(ranges).build(); default: throw new IllegalArgumentException(String.format( "Unsupported type %s when adding %s to %s", type1, TextFormat.shortDebugString(val1), TextFormat.shortDebugString(val2))); } }
Example 2
Source File: ValueUtils.java From dcos-commons with Apache License 2.0 | 6 votes |
public static Value subtract(Value val1, Value val2) { Type type1 = val1.getType(); Type type2 = val2.getType(); if (type1 != type2) { throw new IllegalArgumentException(String.format( "Values to subtract do not have matching type: %s vs %s", TextFormat.shortDebugString(val1), TextFormat.shortDebugString(val2))); } switch (type1) { case SCALAR: Value.Scalar scalar = subtract(val1.getScalar(), val2.getScalar()); return Value.newBuilder().setType(type1).setScalar(scalar).build(); case RANGES: Value.Ranges ranges = subtract(val1.getRanges(), val2.getRanges()); return Value.newBuilder().setType(type1).setRanges(ranges).build(); default: throw new IllegalArgumentException(String.format( "Unsupported type %s when subtracting %s from %s", type1, TextFormat.shortDebugString(val2), TextFormat.shortDebugString(val1))); } }
Example 3
Source File: ValueUtils.java From dcos-commons with Apache License 2.0 | 6 votes |
public static Integer compare(Value val1, Value val2) { Type type1 = val1.getType(); Type type2 = val2.getType(); if (type1 != type2) { throw new IllegalArgumentException(String.format( "Values to compare do not have matching type: %s vs %s", TextFormat.shortDebugString(val1), TextFormat.shortDebugString(val2))); } switch (type1) { case SCALAR: return compare(val1.getScalar(), val2.getScalar()); case RANGES: return compare(val1.getRanges(), val2.getRanges()); default: throw new IllegalArgumentException(String.format( "Unsupported type %s when comparing values: %s vs %s", type1, TextFormat.shortDebugString(val1), TextFormat.shortDebugString(val2))); } }