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

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

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

import java.util.Collection;

import com.google.common.collect.ImmutableSet;

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

@PublicApi
public final class Nodes
    extends AbstractImmutableEntitySet
{
    private Nodes( final ImmutableSet set )
    {
        super( set );
    }

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

    public static Nodes from( final Node... nodes )
    {
        return new Nodes( ImmutableSet.copyOf( nodes ) );
    }

    public static Nodes from( final Iterable nodes )
    {
        return new Nodes( ImmutableSet.copyOf( nodes ) );
    }

    public static Nodes from( final Collection nodes )
    {
        return new Nodes( ImmutableSet.copyOf( nodes ) );
    }

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

    @Deprecated
    public Node getNodeById( final NodeId nodeId )
    {
        return this.set.stream().filter( n -> nodeId.equals( n.id() ) ).findAny().orElse( null );
    }

    public NodePaths getPaths()
    {
        return NodePaths.from( set.stream().map( Node::path ).collect( ImmutableSet.toImmutableSet() ) );
    }

    public NodeIds getIds()
    {
        return NodeIds.from( set.stream().map( Node::id ).collect( ImmutableSet.toImmutableSet() ) );
    }

    public static final class Builder
    {
        private final ImmutableSet.Builder nodes = new ImmutableSet.Builder<>();

        public Builder add( Node node )
        {
            nodes.add( node );
            return this;
        }

        public Builder addAll( Nodes nodes )
        {
            this.nodes.addAll( nodes.getSet() );
            return this;
        }

        public Nodes build()
        {
            return new Nodes( nodes.build() );
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy