com.enonic.xp.audit.AuditLogIds Maven / Gradle / Ivy
The newest version!
package com.enonic.xp.audit;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import com.google.common.collect.ImmutableSet;
import com.enonic.xp.annotation.PublicApi;
import com.enonic.xp.support.AbstractImmutableEntitySet;
@PublicApi
public final class AuditLogIds
extends AbstractImmutableEntitySet
implements Iterable
{
private AuditLogIds( final ImmutableSet set )
{
super( set );
}
public static AuditLogIds empty()
{
final ImmutableSet set = ImmutableSet.of();
return new AuditLogIds( set );
}
public static AuditLogIds from( final AuditLogId... ids )
{
return new AuditLogIds( ImmutableSet.copyOf( ids ) );
}
public static AuditLogIds from( final String... ids )
{
return new AuditLogIds( parseIds( ids ) );
}
public static AuditLogIds from( final Collection ids )
{
return new AuditLogIds( doParseIds( ids ) );
}
public static AuditLogIds from( final Iterable ids )
{
return new AuditLogIds( ImmutableSet.copyOf( ids ) );
}
private static ImmutableSet parseIds( final String... ids )
{
return doParseIds( Arrays.asList( ids ) );
}
private static ImmutableSet doParseIds( final Collection list )
{
return list.stream().map( AuditLogId::from ).collect( ImmutableSet.toImmutableSet() );
}
@Deprecated
public Set asStrings()
{
return this.set.stream().map( AuditLogId::toString ).collect( Collectors.toSet() );
}
public static Builder create()
{
return new Builder();
}
public static class Builder
{
private final List contents = new ArrayList<>();
public Builder add( final AuditLogId auditLogId )
{
this.contents.add( auditLogId );
return this;
}
public Builder addAll( final AuditLogIds auditLogIds )
{
this.contents.addAll( auditLogIds.getSet() );
return this;
}
public AuditLogIds build()
{
return AuditLogIds.from( contents );
}
}
}