ResourceDimensions { public static ResourceDimension add(ResourceDimension... parts) { if (isNullOrEmpty(parts)) { return ResourceDimension.empty(); } double cpuSum = 0; long memorySum = 0; long diskSum = 0; long networkSum = 0; long gpuSum = 0; long opportunisticCpuSum = 0; for (ResourceDimension part : parts) { cpuSum += part.getCpu(); memorySum += part.getMemoryMB(); diskSum += part.getDiskMB(); networkSum += part.getNetworkMbs(); gpuSum += part.getGpu(); opportunisticCpuSum += part.getOpportunisticCpu(); } return ResourceDimension.newBuilder() .withCpus(cpuSum) .withMemoryMB(memorySum) .withDiskMB(diskSum) .withNetworkMbs(networkSum) .withGpu(gpuSum) .withOpportunisticCpus(opportunisticCpuSum) .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 testResourceDimensionAddition() throws Exception { ResourceDimension small = ResourceDimensionSample.SmallWithGpuAndOpportunistic.build(); ResourceDimension expected = ResourceDimensionSample.SmallWithGpuAndOpportunisticX2.build(); assertThat(ResourceDimensions.add(small, small)).isEqualTo(expected); }