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

com.enonic.xp.attachment.CreateAttachments Maven / Gradle / Ivy

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

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

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

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

@PublicApi
public final class CreateAttachments
    extends AbstractImmutableEntitySet
{
    private CreateAttachments( final Set set )
    {
        super( ImmutableSet.copyOf( set ) );
    }

    @Deprecated
    public ImmutableList getNames()
    {
        return this.set.stream().map( CreateAttachment::getName ).collect( ImmutableList.toImmutableList() );
    }

    @Deprecated
    public CreateAttachment getByName( final String name )
    {
        return this.set.stream().filter( ca -> ca.getName().equals( name ) ).findAny().orElse( null );
    }

    public static CreateAttachments empty()
    {
        return new CreateAttachments( ImmutableSet.of() );
    }

    public static CreateAttachments from( final CreateAttachment... contents )
    {
        return new CreateAttachments( ImmutableSet.copyOf( contents ) );
    }

    public static CreateAttachments from( final Iterable contents )
    {
        return new CreateAttachments( ImmutableSet.copyOf( contents ) );
    }

    public static CreateAttachments from( final Collection contents )
    {
        return new CreateAttachments( ImmutableSet.copyOf( contents ) );
    }

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

    @Override
    public boolean equals( final Object o )
    {
        return super.equals( o );
    }

    @Override
    public int hashCode()
    {
        return super.hashCode();
    }

    public static class Builder
    {
        private final Set contents = new LinkedHashSet<>();

        public Builder add( CreateAttachment value )
        {
            contents.add( value );
            return this;
        }

        public Builder add( CreateAttachments value )
        {
            contents.addAll( value.set );
            return this;
        }

        public CreateAttachments build()
        {
            return new CreateAttachments( contents );
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy