class PluckNodeTransformer implements NodeTransformer {

    @Override
    public Node transform( Node node, List<String> args )
    {
        checkNotNull( node );
        checkNotNull( node.getProperty() );

        Property property = node.getProperty();

        if ( property.isCollection() )
        {
            final String fieldName = ( args == null || args.isEmpty() ) ? null : StringUtils.defaultIfEmpty( args.get( 0 ), null );

            final CollectionNode collectionNode = new CollectionNode( node.getName(), node.getUnorderedChildren().size() );
            collectionNode.setNamespace( node.getNamespace() );

            for ( final Node objectNode : node.getUnorderedChildren() )
            {
                for ( final Node fieldNode : objectNode.getUnorderedChildren() )
                {
                    if ( fieldNode instanceof SimpleNode && ( fieldName == null || fieldName.equals( fieldNode.getName() ) ) )
                    {
                        final SimpleNode childNode = new SimpleNode( fieldNode.getName(), ( (SimpleNode) fieldNode ).getValue() );
                        childNode.setProperty( collectionNode.getProperty() );
                        collectionNode.addChild( childNode );

                        break;
                    }
                }
            }

            return collectionNode;
        }

        return node;
    }

}