class ResourceDimensions {

    public static ResourceDimension alignUp(ResourceDimension source, ResourceDimension reference) {
        double cpuRatio = source.getCpu() / reference.getCpu();
        double memoryRatio = source.getMemoryMB() / reference.getMemoryMB();

        if (cpuRatio == memoryRatio) {
            return source;
        }
        if (cpuRatio > memoryRatio) {
            return ResourceDimension.newBuilder()
                    .withCpus(source.getCpu())
                    .withMemoryMB((long) (reference.getMemoryMB() * cpuRatio))
                    .withDiskMB((long) (reference.getDiskMB() * cpuRatio))
                    .withNetworkMbs((long) (reference.getNetworkMbs() * cpuRatio))
                    .withGpu((long) (reference.getGpu() * cpuRatio))
                    .withOpportunisticCpus((long) (reference.getOpportunisticCpu() * cpuRatio))
                    .build();
        }

        // memoryRatio > cpuRatio
        return ResourceDimension.newBuilder()
                .withCpus(reference.getCpu() * memoryRatio)
                .withMemoryMB(source.getMemoryMB())
                .withDiskMB((long) (reference.getDiskMB() * memoryRatio))
                .withNetworkMbs((long) (reference.getNetworkMbs() * memoryRatio))
                .withGpu((long) (reference.getGpu() * memoryRatio))
                .withOpportunisticCpus((long) (reference.getOpportunisticCpu() * memoryRatio))
                .build();
    }

}