@Test public void testSortInstanceTypes_getValidOrderOfSortedElements() { List<String> sortedInstanceTypes = InstanceType.sortInstanceTypes( instanceTypes ); assertEquals( expectedSortedInstanceTypes, sortedInstanceTypes ); }
public static List<String> sortInstanceTypes( List<InstanceType> instances ) { List<InstanceType> instanceGroup; List<String> instanceGroupTypes; List<String> sortedInstances = new ArrayList<>(); Collections.sort( instances, ( o1, o2 ) -> o1.getType().compareTo( o2.getType() ) ); while ( instances.size() > 0 ) { instanceGroup = instances.stream() .filter( e -> instances.get( 0 ).getType().split( "\\." )[ 0 ].equals( e.getType().split( "\\." )[ 0 ] ) ) .collect( Collectors.toList() ); instances.removeAll( instanceGroup ); Collections.sort( instanceGroup ); instanceGroupTypes = instanceGroup.stream().map( e -> e.getType() ).collect( Collectors.toList() ); sortedInstances.addAll( instanceGroupTypes ); } return sortedInstances; }
InstanceType implements Comparable<InstanceType> { public static List<String> sortInstanceTypes( List<InstanceType> instances ) { List<InstanceType> instanceGroup; List<String> instanceGroupTypes; List<String> sortedInstances = new ArrayList<>(); Collections.sort( instances, ( o1, o2 ) -> o1.getType().compareTo( o2.getType() ) ); while ( instances.size() > 0 ) { instanceGroup = instances.stream() .filter( e -> instances.get( 0 ).getType().split( "\\." )[ 0 ].equals( e.getType().split( "\\." )[ 0 ] ) ) .collect( Collectors.toList() ); instances.removeAll( instanceGroup ); Collections.sort( instanceGroup ); instanceGroupTypes = instanceGroup.stream().map( e -> e.getType() ).collect( Collectors.toList() ); sortedInstances.addAll( instanceGroupTypes ); } return sortedInstances; } }
InstanceType implements Comparable<InstanceType> { public static List<String> sortInstanceTypes( List<InstanceType> instances ) { List<InstanceType> instanceGroup; List<String> instanceGroupTypes; List<String> sortedInstances = new ArrayList<>(); Collections.sort( instances, ( o1, o2 ) -> o1.getType().compareTo( o2.getType() ) ); while ( instances.size() > 0 ) { instanceGroup = instances.stream() .filter( e -> instances.get( 0 ).getType().split( "\\." )[ 0 ].equals( e.getType().split( "\\." )[ 0 ] ) ) .collect( Collectors.toList() ); instances.removeAll( instanceGroup ); Collections.sort( instanceGroup ); instanceGroupTypes = instanceGroup.stream().map( e -> e.getType() ).collect( Collectors.toList() ); sortedInstances.addAll( instanceGroupTypes ); } return sortedInstances; } InstanceType( String type, String instanceFamily ); }
InstanceType implements Comparable<InstanceType> { public static List<String> sortInstanceTypes( List<InstanceType> instances ) { List<InstanceType> instanceGroup; List<String> instanceGroupTypes; List<String> sortedInstances = new ArrayList<>(); Collections.sort( instances, ( o1, o2 ) -> o1.getType().compareTo( o2.getType() ) ); while ( instances.size() > 0 ) { instanceGroup = instances.stream() .filter( e -> instances.get( 0 ).getType().split( "\\." )[ 0 ].equals( e.getType().split( "\\." )[ 0 ] ) ) .collect( Collectors.toList() ); instances.removeAll( instanceGroup ); Collections.sort( instanceGroup ); instanceGroupTypes = instanceGroup.stream().map( e -> e.getType() ).collect( Collectors.toList() ); sortedInstances.addAll( instanceGroupTypes ); } return sortedInstances; } InstanceType( String type, String instanceFamily ); String getType(); void setType( String type ); String getInstanceFamily(); void setInstanceFamily( String instanceFamily ); static String createDescription( InstanceType type ); static String getTypeFromDescription( String description ); @Override boolean equals( Object o ); @Override int hashCode(); @Override int compareTo( InstanceType instanceType ); static List<String> sortInstanceTypes( List<InstanceType> instances ); }
InstanceType implements Comparable<InstanceType> { public static List<String> sortInstanceTypes( List<InstanceType> instances ) { List<InstanceType> instanceGroup; List<String> instanceGroupTypes; List<String> sortedInstances = new ArrayList<>(); Collections.sort( instances, ( o1, o2 ) -> o1.getType().compareTo( o2.getType() ) ); while ( instances.size() > 0 ) { instanceGroup = instances.stream() .filter( e -> instances.get( 0 ).getType().split( "\\." )[ 0 ].equals( e.getType().split( "\\." )[ 0 ] ) ) .collect( Collectors.toList() ); instances.removeAll( instanceGroup ); Collections.sort( instanceGroup ); instanceGroupTypes = instanceGroup.stream().map( e -> e.getType() ).collect( Collectors.toList() ); sortedInstances.addAll( instanceGroupTypes ); } return sortedInstances; } InstanceType( String type, String instanceFamily ); String getType(); void setType( String type ); String getInstanceFamily(); void setInstanceFamily( String instanceFamily ); static String createDescription( InstanceType type ); static String getTypeFromDescription( String description ); @Override boolean equals( Object o ); @Override int hashCode(); @Override int compareTo( InstanceType instanceType ); static List<String> sortInstanceTypes( List<InstanceType> instances );  }