class ResourceValidator {

  public void validate(ResourceDto resource) throws BadRequestException {
    if (resource == null) {
      throw new BadRequestException("Missed resource");
    }

    final Set<String> units = resourcesTypesToUnits.get(resource.getType());

    if (units == null) {
      throw new BadRequestException(
          "Specified resources type '" + resource.getType() + "' is not supported");
    }

    if (resource.getUnit() == null) {
      resource.setUnit(resourcesTypesToDefaultUnit.get(resource.getType()));
    } else {
      if (!units.contains(resource.getUnit())) {
        throw new BadRequestException(
            "Specified resources type '"
                + resource.getType()
                + "' support only following units: "
                + units.stream().collect(Collectors.joining(", ")));
      }
    }

    if (resource.getAmount() < -1) {
      throw new BadRequestException(
          "Resources with type '" + resource.getType() + "' has negative amount");
    }
  }

  @Inject public  ResourceValidator(Set<ResourceType> supportedResources);

}