### Question:
ResourceProfile implements Serializable, Comparable<ResourceProfile> { @Override public int compareTo(@Nonnull ResourceProfile other) { int cmp = Integer.compare(this.getMemoryInMB(), other.getMemoryInMB()); if (cmp == 0) { cmp = Double.compare(this.cpuCores, other.cpuCores); } if (cmp == 0) { Iterator<Map.Entry<String, Resource>> thisIterator = extendedResources.entrySet().iterator(); Iterator<Map.Entry<String, Resource>> otherIterator = other.extendedResources.entrySet().iterator(); while (thisIterator.hasNext() && otherIterator.hasNext()) { Map.Entry<String, Resource> thisResource = thisIterator.next(); Map.Entry<String, Resource> otherResource = otherIterator.next(); if ((cmp = otherResource.getKey().compareTo(thisResource.getKey())) != 0) { return cmp; } if (!otherResource.getValue().getResourceAggregateType().equals(thisResource.getValue().getResourceAggregateType())) { return 1; } if ((cmp = Double.compare(thisResource.getValue().getValue(), otherResource.getValue().getValue())) != 0) { return cmp; } } if (thisIterator.hasNext()) { return 1; } if (otherIterator.hasNext()) { return -1; } } return cmp; } ResourceProfile(
			double cpuCores,
			int heapMemoryInMB,
			int directMemoryInMB,
			int nativeMemoryInMB,
			int networkMemoryInMB,
			Map<String, Resource> extendedResources);  ResourceProfile(double cpuCores, int heapMemoryInMB);  ResourceProfile(ResourceProfile other); double getCpuCores(); int getHeapMemoryInMB(); int getDirectMemoryInMB(); int getNativeMemoryInMB(); int getNetworkMemoryInMB(); int getMemoryInMB(); int getOperatorsMemoryInMB(); Map<String, Resource> getExtendedResources(); boolean isMatching(ResourceProfile required); @Override int compareTo(@Nonnull ResourceProfile other); @Override int hashCode(); @Override boolean equals(Object obj); @Override String toString(); static final ResourceProfile UNKNOWN; static final ResourceProfile ANY; }### Answer:
@Test public void testCompareTo() throws Exception { ResourceSpec rs1 = ResourceSpec.newBuilder().setCpuCores(1.0).setHeapMemoryInMB(100).build(); ResourceSpec rs2 = ResourceSpec.newBuilder().setCpuCores(1.0).setHeapMemoryInMB(100).build(); assertEquals(0, ResourceProfile.fromResourceSpec(rs1, 0).compareTo(ResourceProfile.fromResourceSpec(rs2, 0))); ResourceSpec rs3 = ResourceSpec.newBuilder(). setCpuCores(1.0). setHeapMemoryInMB(100). setGPUResource(2.2). build(); assertEquals(-1, ResourceProfile.fromResourceSpec(rs1, 0).compareTo(ResourceProfile.fromResourceSpec(rs3, 0))); assertEquals(1, ResourceProfile.fromResourceSpec(rs3, 0).compareTo(ResourceProfile.fromResourceSpec(rs1, 0))); ResourceSpec rs4 = ResourceSpec.newBuilder(). setCpuCores(1.0). setHeapMemoryInMB(100). setGPUResource(1.1). build(); assertEquals(1, ResourceProfile.fromResourceSpec(rs3, 0).compareTo(ResourceProfile.fromResourceSpec(rs4, 0))); assertEquals(-1, ResourceProfile.fromResourceSpec(rs4, 0).compareTo(ResourceProfile.fromResourceSpec(rs3, 0))); ResourceSpec rs5 = ResourceSpec.newBuilder(). setCpuCores(1.0). setHeapMemoryInMB(100). setGPUResource(2.2). build(); assertEquals(0, ResourceProfile.fromResourceSpec(rs3, 0).compareTo(ResourceProfile.fromResourceSpec(rs5, 0))); }