com.enonic.xp.node.BinaryAttachments Maven / Gradle / Ivy
package com.enonic.xp.node;
import java.util.HashSet;
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 BinaryAttachments
extends AbstractImmutableEntitySet
{
private static final BinaryAttachments EMPTY = new BinaryAttachments( ImmutableSet.of(), false );
@Deprecated
public BinaryAttachments( final ImmutableSet set )
{
super( set );
}
private BinaryAttachments( final ImmutableSet set, boolean ignore )
{
super( set );
}
public BinaryAttachment get( final BinaryReference binaryReference )
{
return this.set.stream().filter( ba -> ba.getReference().equals( binaryReference ) ).findAny().orElse( null );
}
private static BinaryAttachments fromInternal( final ImmutableSet set )
{
return set.isEmpty() ? EMPTY : new BinaryAttachments( set, false );
}
public static Builder create()
{
return new Builder();
}
public static BinaryAttachments empty()
{
return EMPTY;
}
public static final class Builder
{
private final Set binaryAttachments = new HashSet<>();
public Builder add( final BinaryAttachment binaryAttachment )
{
this.binaryAttachments.add( binaryAttachment );
return this;
}
public BinaryAttachments build()
{
return fromInternal( ImmutableSet.copyOf( binaryAttachments ) );
}
}
}