def get_desired_count(value, lower, upper):
  """Gets the desired count from an actual count and allowed value interval."""
  if lower != -1 and value < lower:
    return lower
  if upper != -1 and value > upper:
    return upper
  return value