ResourceDimensions { public static ResourceDimension subtractPositive(ResourceDimension left, ResourceDimension right) { return ResourceDimension.newBuilder() .withCpus(Math.max(0, left.getCpu() - right.getCpu())) .withMemoryMB(Math.max(0, left.getMemoryMB() - right.getMemoryMB())) .withDiskMB(Math.max(0, left.getDiskMB() - right.getDiskMB())) .withNetworkMbs(Math.max(0, left.getNetworkMbs() - right.getNetworkMbs())) .withGpu(Math.max(0, left.getGpu() - right.getGpu())) .withOpportunisticCpus(Math.max(0, left.getOpportunisticCpu() - right.getOpportunisticCpu())) .build(); }  static ResourceDimension add(ResourceDimension... parts); static ResourceDimension add(Collection<ResourceDimension> parts); static ResourceDimension subtractPositive(ResourceDimension left, ResourceDimension right); static ResourceDimension multiply(ResourceDimension base, double multiplier); static Pair<Long, ResourceDimension> divide(ResourceDimension left, ResourceDimension right); static long divideAndRoundUp(ResourceDimension left, ResourceDimension right); static ResourceDimension alignUp(ResourceDimension source, ResourceDimension reference); static boolean isBigger(ResourceDimension dimension, ResourceDimension subDimension); static StringBuilder format(ResourceDimension input, StringBuilder output); static String format(ResourceDimension input); static ResourceDimension fromServerInfo(ServerInfo serverInfo); static ResourceDimension fromAwsInstanceType(AwsInstanceType instanceType); static ResAllocs toResAllocs(String name, ResourceDimension resourceDimension); static ResourceDimension fromResAllocs(ResAllocs resAllocs);  }
@Test public void testResourceDimensionSubtraction() throws Exception { ResourceDimension large = ResourceDimensionSample.SmallWithGpuAndOpportunisticX2.build(); ResourceDimension small = ResourceDimensionSample.SmallWithGpuAndOpportunistic.build(); assertThat(ResourceDimensions.subtractPositive(large, small)).isEqualTo(small); }