private static RollUpBitMask buildMaskFromTagPositions(final SortedSet<Integer> tagPositions) {
        short tempMask = 0;
        if (tagPositions != null) {
            for (final Integer tagPosition : tagPositions) {
                if (tagPosition >= MASK_LENGTH || tagPosition < 0) {
                    throw new RuntimeException(
                            String.format("Passed array [%s] contains a value that is not a valid mask position [%s]",
                                    tagPositions, tagPosition));
                }
                tempMask = setMaskValueAtPosition(tagPosition, tempMask);
            }
        }

        return new RollUpBitMask(tempMask);
    }
Generates a {@link RollUpBitMask} from the passed set of rolled up tag
positions. It uses a cache of tag positions to save it having to build
the objects each time. For that reason the passed set must be sorted to
ensure it can be compared to ones in the cache, i.e. [0,1] == [1,0]

@param tagPositions A sorted set of the array position values at which a tag is
                    rolled up. E.g. if you have Tag1, Tag2 & Tag3 and only Tag2 is
                    rolled up then [1] would be passed as only tag at position 1
                    is rolled up.
@return The {@link RollUpBitMask} object representing the rolled up tag
positions.
stroom-statistics/stroom-statistics-impl-hbase/src/main/java/stroom/statistics/impl/hbase/rollup/RollUpBitMask.java