class RelationshipExpanderBuilder {

    @SuppressWarnings( "unchecked" )
    public static PathExpander describeRelationships( Map<String, Object> description )
    {
        PathExpanderBuilder expander = PathExpanderBuilder.allTypesAndDirections();

        Object relationshipsDescription = description.get( "relationships" );
        if ( relationshipsDescription != null )
        {
            Collection<Object> pairDescriptions;
            if ( relationshipsDescription instanceof Collection )
            {
                pairDescriptions = (Collection<Object>) relationshipsDescription;
            }
            else
            {
                pairDescriptions = Arrays.asList( relationshipsDescription );
            }

            for ( Object pairDescription : pairDescriptions )
            {
                Map map = (Map) pairDescription;
                String name = (String) map.get( "type" );
                RelationshipType type = RelationshipType.withName( name );
                String directionName = (String) map.get( "direction" );
                expander = ( directionName == null ) ? expander.add( type ) : expander.add( type,
                        stringToEnum( directionName, RelationshipDirection.class, true ).internal );
            }
        }
        return expander.build();
    }

    private  RelationshipExpanderBuilder();

}