StringUtil { public static Map<String, String> trimStringMap( Map<String, String> map ) { return map == null ? map : map.entrySet().stream().collect( Collectors.toMap( e -> StringUtils.trimToEmpty( e.getKey() ), e -> StringUtils.trimToEmpty( e.getValue() ) ) ); } private  StringUtil(); static String[] tokenStringToArray( final String tokenizedString, final String token ); static boolean doesPathContainParentPathSegment( final String path ); static void main( final String[] args ); static boolean isEmpty( final String str ); static String getMapAsPrettyString( final Map map ); static Map<String, String> trimStringMap( Map<String, String> map ); static List<String> trimStringList( List<String> list ); static String trimToEmpty( String string );  }
@Test public void testTrimStringMap() { Map<String, String> nullMap = null; Assert.assertNull( StringUtil.trimStringMap( nullMap ) ); Map<String, String> stringMap = new HashMap<>(); stringMap.put( " spaces ", " spacesval " ); stringMap.put( "\t tabs \t", "\t tabsval \t" ); stringMap.put( "\n newline \n", "\n newlineval \n" ); stringMap.put( "empty", "" ); stringMap.put( "null", null ); stringMap.put( null, null ); stringMap = StringUtil.trimStringMap( stringMap ); Assert.assertEquals( stringMap.get( "spaces" ), "spacesval" ); Assert.assertEquals( stringMap.get( "tabs" ), "tabsval" ); Assert.assertEquals( stringMap.get( "newline" ), "newlineval" ); Assert.assertEquals( stringMap.get( "empty" ), "" ); Assert.assertEquals( stringMap.get( "null" ), "" ); Assert.assertEquals( stringMap.get( "" ), "" ); }