private static Map copy(Map data, boolean useMarshalledValueMaps)
{
if (data == null) return null;
if (data.isEmpty()) return Collections.emptyMap();
if (safe(data)) return useMarshalledValueMaps ? new MarshalledValueMap(data) : data;
Map defensivelyCopiedData = new MapCopy(data);
return useMarshalledValueMaps ? new MarshalledValueMap(defensivelyCopiedData) : defensivelyCopiedData;
}