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

com.enonic.xp.site.SiteConfigs Maven / Gradle / Ivy

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

import java.util.Collection;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;

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

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

    private SiteConfigs( final ImmutableList list )
    {
        super( list );
    }

    public SiteConfig get( final ApplicationKey applicationKey )
    {
        return list.stream().filter( sc -> applicationKey.equals( sc.getApplicationKey() ) ).findAny().orElse( null );
    }

    @Deprecated
    public SiteConfig get( final String applicationKey )
    {
        return get( ApplicationKey.from( applicationKey ) );
    }

    @Deprecated
    public ImmutableSet getApplicationKeys()
    {
        return list.stream().map( SiteConfig::getApplicationKey ).collect( ImmutableSet.toImmutableSet() );
    }

    public static SiteConfigs empty()
    {
        return EMPTY;
    }

    public static SiteConfigs from( final SiteConfig... siteConfigs )
    {
        return fromInternal( ImmutableList.copyOf( siteConfigs ) );
    }

    public static SiteConfigs from( final Iterable siteConfigs )
    {
        return fromInternal( ImmutableList.copyOf( siteConfigs ) );
    }

    public static SiteConfigs from( final Collection siteConfigs )
    {
        return fromInternal( ImmutableList.copyOf( siteConfigs ) );
    }

    private static SiteConfigs fromInternal( final ImmutableList siteConfigs )
    {
        if ( siteConfigs.isEmpty() )
        {
            return EMPTY;
        }
        else
        {
            return new SiteConfigs( siteConfigs );
        }
    }

    public static Builder create()
    {
        return new Builder();
    }

    public static final class Builder
    {
        private final ImmutableList.Builder builder = ImmutableList.builder();

        public Builder add( final SiteConfig siteConfig )
        {
            builder.add( siteConfig );
            return this;
        }

        public SiteConfigs build()
        {
            return fromInternal( builder.build() );
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy