View Javadoc
1   package fr.paris.lutece.plugins.aot.modules.declarationimmat.utils;
2   
3   import java.util.Arrays;
4   import java.util.List;
5   import java.util.stream.Collectors;
6   
7   import org.apache.commons.collections.ListUtils;
8   import org.apache.commons.lang3.StringUtils;
9   
10  import fr.paris.lutece.plugins.aot.modules.declarationimmat.business.TypeVehicle;
11  
12  public class TypeVehicleUtils
13  {
14      private static final String SEPARATOR = ",";
15  
16      public static List<TypeVehicle> codesToTypes( String strCodes )
17      {
18          if ( StringUtils.isBlank( strCodes ) )
19          {
20              return ListUtils.EMPTY_LIST;
21          }
22          List<String> codes = Arrays.asList( StringUtils.split( strCodes, SEPARATOR ) );
23  
24          return codes.stream( ).map( code -> TypeVehicle.fromCode( code ) ).collect( Collectors.toList( ) );
25      }
26  
27      public static String typesToCodes( List<TypeVehicle> types )
28      {
29          List<String> codes = types.stream( ).map( type -> type.getCode( ) ).collect( Collectors.toList( ) );
30  
31          return StringUtils.join( codes, SEPARATOR );
32      }
33  
34  }