question: private static ArrayList < PresetElement > filterElements ( ArrayList < PresetElement > originalElements , ElementType type ) { ArrayList < PresetElement > filteredElements = new ArrayList < PresetElement > ( ) ; for ( PresetElement e : originalElements ) { if ( e . appliesTo ( type ) ) { filteredElements . add ( e ) ; } else if ( ( e instanceof PresetSeparator ) && ! filteredElements . isEmpty ( ) && ! ( filteredElements . get ( filteredElements . size ( ) - 1 ) instanceof PresetSeparator ) ) { filteredElements . add ( e ) ; } } return filteredElements ; }
target:  Filter a list of elements by type