public Map<String,String[]> crop(final Map<String,String[]> original){
  Map<String,String[]> result=new HashMap<String,String[]>(original.size());
  for (  Map.Entry<String,String[]> entry : original.entrySet()) {
    String key=entry.getKey();
    if (null == key) {
      continue;
    }
    String[] value=entry.getValue();
    String[] convertedValue;
    if (null == value) {
      convertedValue=new String[1];
      convertedValue[0]="<notset>";
    }
 else {
      boolean croppingWasNeeded=false;
      convertedValue=value;
      for (int i=0, l=value.length; i < l; i++) {
        String curValue=value[i];
        String croppingResult=crop(curValue);
        if ((curValue != croppingResult) & !croppingWasNeeded) {
          croppingWasNeeded=true;
          convertedValue=new String[value.length];
          System.arraycopy(value,0,convertedValue,0,i);
          convertedValue[i]=croppingResult;
        }
        if (croppingWasNeeded) {
          convertedValue[i]=croppingResult;
        }
      }
    }
    result.put(key,convertedValue);
  }
  return result;
}

public Map < String , String [ ] > crop ( final Map < String , String [ ] > original ) { Map < String , String [ ] > result = new HashMap < String , String [ ] > ( original . size ( ) ) ; for ( Map . Entry < String , String [ ] > entry : original . entrySet ( ) ) { String key = entry . getKey ( ) ; if ( null == key ) { continue ; } String [ ] value = entry . getValue ( ) ; String [ ] convertedValue ; if ( null == value ) { convertedValue = new String [ 1 ] ; convertedValue [ 0 ] = "<notset>" ; } else { boolean croppingWasNeeded = false ; convertedValue = value ; for ( int i = 0 , l = value . length ; i < l ; i ++ ) { String curValue = value [ i ] ; String croppingResult = crop ( curValue ) ; if ( ( curValue != croppingResult ) & ! croppingWasNeeded ) { croppingWasNeeded = true ; convertedValue = new String [ value . length ] ; System . arraycopy ( value , 0 , convertedValue , 0 , i ) ; convertedValue [ i ] = croppingResult ; } if ( croppingWasNeeded ) { convertedValue [ i ] = croppingResult ; } } } result . put ( key , convertedValue ) ; } return result ; }
analyzes the given map and tries to re - use the values in string arrays and the string arrays themself to converse memory . a new string array for values is only created if one entry in the values needed cropping to ensure that the original map is not changed .
