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

com.enonic.xp.node.AttachedBinaries Maven / Gradle / Ivy

The newest version!
package com.enonic.xp.node;

import java.util.Collection;
import java.util.Set;

import com.google.common.collect.ImmutableSet;

import com.enonic.xp.annotation.PublicApi;
import com.enonic.xp.support.AbstractImmutableEntitySet;
import com.enonic.xp.util.BinaryReference;

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

    private AttachedBinaries( final ImmutableSet set )
    {
        super( set );
    }

    public static AttachedBinaries empty()
    {
        return EMPTY;
    }

    public AttachedBinary getByBinaryReference( final BinaryReference reference )
    {
        for ( final AttachedBinary attachedBinary : this.set )
        {
            if ( attachedBinary.getBinaryReference().equals( reference ) )
            {
                return attachedBinary;
            }
        }

        return null;
    }

    public static AttachedBinaries fromCollection( final Collection references )
    {
        return fromInternal( ImmutableSet.copyOf( references ) );
    }

    private static AttachedBinaries fromInternal( final ImmutableSet set )
    {
        return set.isEmpty() ? EMPTY : new AttachedBinaries( set );
    }

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

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

        public Builder add( final AttachedBinary attachedBinary )
        {
            this.nodeAttachedBinaries.add( attachedBinary );
            return this;
        }

        @Deprecated
        public Set getNodeAttachedBinaries()
        {
            return nodeAttachedBinaries.build();
        }

        public AttachedBinaries build()
        {
            return fromInternal( nodeAttachedBinaries.build() );
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy