class ReferenceCollectionKeyGenerator implements KeyGenerator {

    @Override
    @Nonnull
    public Object generate( @Nonnull Object target, @Nonnull Method method, @Nonnull Object... params )
    {
        @SuppressWarnings( "unchecked" ) final Collection<Reference> references = (Collection<Reference>) params[0];
        final SortedSet<String> referenceStrings = references.stream().map( Reference::toCacheString )
            .collect( Collectors.toCollection( TreeSet::new ) );

        final StringBuilder sb = new StringBuilder( method.getName() );

        // codes must have same order every time
        for ( final String string : referenceStrings )
        {
            sb.append( ',' ).append( string );
        }

        return sb.toString();
    }

}