def CheckForSize(collection, expected_size, equal_flag, unequal_flag,
                 unexpectedly_empty_flag=None):
  """Check conditions for collection size.

  Args:
    collection: A collection can be a list, set or dictionary.
    expected_size: The expected size.
    equal_flag: The value to return if the collection size equals the expected.
    unequal_flag: The value to return if the collection size differs from
        the expected.
    unexpectedly_empty_flag: The value to return if the collection size is
        unexpectedly empty.

  Returns:
    The flag chosen according to whether the collection size equals the
    expected. It can be one of
    [equal_flag, unequal_flag, unexpectedly_empty_flag].
  """

  if len(collection) == expected_size:
    return equal_flag
  elif collection or unexpectedly_empty_flag is None:
    return unequal_flag
  else:
    return unexpectedly_empty_flag