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

com.enonic.xp.region.RegionDescriptors Maven / Gradle / Ivy

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


import java.util.Iterator;

import com.google.common.collect.ImmutableSet;

import com.enonic.xp.annotation.PublicApi;

@PublicApi
public final class RegionDescriptors
    implements Iterable
{
    private final ImmutableSet regionDescriptors;

    public RegionDescriptors( final ImmutableSet regionDescriptors )
    {
        this.regionDescriptors = regionDescriptors;
    }

    @Deprecated
    public RegionDescriptor getRegionDescriptor( final String name )
    {
        return regionDescriptors.stream().filter( regionDescriptor -> regionDescriptor.getName().equals( name ) ).findAny().orElse( null );
    }

    public int numberOfRegions()
    {
        return this.regionDescriptors.size();
    }

    @Override
    public Iterator iterator()
    {
        return regionDescriptors.iterator();
    }

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

    public static class Builder
    {
        private final ImmutableSet.Builder regionsDescriptors = new ImmutableSet.Builder<>();

        public Builder add( final RegionDescriptor value )
        {
            regionsDescriptors.add( value );
            return this;
        }

        public RegionDescriptors build()
        {
            return new RegionDescriptors( regionsDescriptors.build() );
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy