class ResourceProfile implements Serializable {

	public boolean isMatching(final ResourceProfile required) {
		checkNotNull(required, "Cannot check matching with null resources");

		if (this.equals(ANY)) {
			return true;
		}

		if (this.equals(required)) {
			return true;
		}

		if (this.equals(UNKNOWN)) {
			return false;
		}

		if (required.equals(UNKNOWN)) {
			return true;
		}

		if (cpuCores.getValue().compareTo(required.cpuCores.getValue()) >= 0 &&
			taskHeapMemory.compareTo(required.taskHeapMemory) >= 0 &&
			taskOffHeapMemory.compareTo(required.taskOffHeapMemory) >= 0 &&
			managedMemory.compareTo(required.managedMemory) >= 0 &&
			networkMemory.compareTo(required.networkMemory) >= 0) {

			for (Map.Entry<String, Resource> resource : required.extendedResources.entrySet()) {
				if (!extendedResources.containsKey(resource.getKey()) ||
					extendedResources.get(resource.getKey()).getValue().compareTo(resource.getValue().getValue()) < 0) {
					return false;
				}
			}
			return true;
		}
		return false;
	}

	private  ResourceProfile(
			final Resource cpuCores,
			final MemorySize taskHeapMemory,
			final MemorySize taskOffHeapMemory,
			final MemorySize managedMemory,
			final MemorySize networkMemory,
			final Map<String, Resource> extendedResources);
	private  ResourceProfile();

}