<commit_before>package com.collection;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import com.alibaba.fastjson.JSON;

public class Map2Json {
	static String map2Json(Map<String, String> map) {
		if (map.isEmpty()) {
			return "{}";
		}
		StringBuilder sb = new StringBuilder(map.size() << 4);
		sb.append('{');
		Set<String> keys = map.keySet();
		for (String key : keys) {
			String value = map.get(key);
			sb.append('\"');
			sb.append(key);
			sb.append('\"');
			sb.append(':');
			sb.append('\"');
			sb.append(value);
			sb.append('\"');
			sb.append(',');
		}
		// 将最后的 ',' 变为 '}':
		sb.setCharAt(sb.length() - 1, '}');
		return sb.toString();
	}

	public static void main(String[] args) {
		Map<String, String> map = new HashMap<String, String>();
		map.put("name", "john");
		map.put("sex", "man");
		map.put("interest", "woman");

		String json = map2Json(map);
		System.out.println(json);

		System.out.println(JSON.toJSONString(map));
	}
}<commit_msg>keySet  改为 entrySet<commit_after>package com.collection;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import com.alibaba.fastjson.JSON;

public class Map2Json {
	static String map2Json(Map<String, String> map) {
		if (map.isEmpty()) {
			return "{}";
		}
		StringBuilder sb = new StringBuilder(map.size() << 4);
		sb.append('{');
		Set<Map.Entry<String, String>> keys = map.entrySet();

		for (Map.Entry entry : keys) {
			sb.append("\"");
			sb.append(entry.getKey());
			sb.append("\":\"");
			sb.append(entry.getValue());
			sb.append("\",");
		}
		// 将最后的 ',' 变为 '}':
		sb.setCharAt(sb.length() - 1, '}');
		return sb.toString();
	}

	public static void main(String[] args) {
		Map<String, String> map = new HashMap<String, String>();
		map.put("name", "john");
		map.put("sex", "man");
		map.put("interest", "woman");

		String json = map2Json(map);
		System.out.println(json);

		System.out.println(JSON.toJSONString(map));
	}
}
{'fraction_non_alphanumeric': 0.20993343573988735, 'fraction_numerical': 0.005120327700972862, 'mean_word_length': 3.800982800982801, 'pattern_counts': {'":': 1, '<': 16, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2223604', 'n_tokens_mistral': 800, 'n_tokens_neox': 720, 'n_words': 143}