protected static FrequencySet<String> combineAndClip(FrequencySet<String> a, FrequencySet<String> b, int clip) {
		FrequencySet<String> result = new FrequencySet<String>();
		for (Map.Entry<String, MutableInt> entry : a.entrySet()) {
			for (int i = 0; i < entry.getValue().v; i++) {
				result.add(entry.getKey());
			}
		}

		for (Map.Entry<String, MutableInt> entry : b.entrySet()) {
			for (int i = 0; i < entry.getValue().v; i++) {
				result.add(entry.getKey());
			}
		}

		for (Map.Entry<String, MutableInt> entry : result.entrySet()) {
			entry.getValue().v = Math.min(entry.getValue().v, clip);
		}

		return result;
	}
Generate a frequency set as the union of two input sets, with the
values clipped to a specified maximum value. If an element is
contained in both sets, the value for the output, prior to clipping,
will be the sum of the two input values.

@param a The first set.
@param b The second set.
@param clip The maximum value to allow for any output.
@return The sum of the two sets, with the individual elements clipped
to the maximum value given by {@code clip}.
tool/src/org/antlr/v4/codegen/model/ElementFrequenciesVisitor.java