com.enonic.xp.content.CompareContentResults Maven / Gradle / Ivy
The newest version!
package com.enonic.xp.content;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.stream.Stream;
import com.google.common.collect.ImmutableMap;
import com.enonic.xp.annotation.PublicApi;
@PublicApi
public class CompareContentResults
implements Iterable
{
private final Map compareContentResultsMap;
private CompareContentResults( Builder builder )
{
compareContentResultsMap = ImmutableMap.copyOf( builder.compareResultsMap );
}
public static Builder create()
{
return new Builder();
}
public Stream stream()
{
return this.compareContentResultsMap.values().stream();
}
@Override
public Iterator iterator()
{
return compareContentResultsMap.values().iterator();
}
public Map getCompareContentResultsMap()
{
return compareContentResultsMap;
}
public ContentIds contentIds()
{
return ContentIds.from( compareContentResultsMap.keySet() );
}
public int size()
{
return compareContentResultsMap.size();
}
public static final class Builder
{
private final Map compareResultsMap = new LinkedHashMap<>();
private Builder()
{
}
public Builder add( final CompareContentResult result )
{
this.compareResultsMap.put( result.getContentId(), result );
return this;
}
public Builder addAll( final CompareContentResults results )
{
this.compareResultsMap.putAll( results.compareContentResultsMap );
return this;
}
public CompareContentResults build()
{
return new CompareContentResults( this );
}
}
}