All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.enonic.xp.app.ApplicationKeys Maven / Gradle / Ivy

There is a newer version: 7.14.4
Show newest version
package com.enonic.xp.app;

import java.util.Arrays;
import java.util.Collection;

import com.google.common.collect.ImmutableSet;

import com.enonic.xp.annotation.PublicApi;
import com.enonic.xp.support.AbstractImmutableEntityList;

@PublicApi
public final class ApplicationKeys
    extends AbstractImmutableEntityList
{
    private static final ApplicationKeys EMPTY = new ApplicationKeys( ImmutableSet.of() );

    private ApplicationKeys( final ImmutableSet list )
    {
        // ApplicationKeys is supposed to be set, but it was made as list initially. We deduplicate values and store them in list.
        super( list.asList() );
    }

    public static ApplicationKeys from( final ApplicationKey... applicationKeys )
    {
        return fromInternal( ImmutableSet.copyOf( applicationKeys ) );
    }

    public static ApplicationKeys from( final Iterable applicationKeys )
    {
        return fromInternal( ImmutableSet.copyOf( applicationKeys ) );
    }

    public static ApplicationKeys from( final Collection applicationKeys )
    {
        return fromInternal( ImmutableSet.copyOf( applicationKeys ) );
    }

    public static ApplicationKeys from( final String... applicationKeys )
    {
        return fromInternal( Arrays.stream( applicationKeys ).map( ApplicationKey::from ).collect( ImmutableSet.toImmutableSet() ) );
    }

    public static ApplicationKeys empty()
    {
        return EMPTY;
    }

    private static ApplicationKeys fromInternal( final ImmutableSet applicationKeys )
    {
        if ( applicationKeys.isEmpty() )
        {
            return EMPTY;
        }
        else
        {
            return new ApplicationKeys( applicationKeys );
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy