<commit_before>package org.bimserver.utils;

/******************************************************************************
 * Copyright (C) 2009-2019  BIMserver.org
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see {@literal<http://www.gnu.org/licenses/>}.
 *****************************************************************************/

import java.util.Calendar;
import java.util.Formatter;
import java.util.GregorianCalendar;

public class Formatters {
	private Formatters() {
	}

	public static String bytesToString(long bytes) {
		Formatter formatter = new Formatter();
		try {
			if (bytes > 1024) {
				if (bytes > 1024L * 1024L) {
					if (bytes > 1024L * 1024L * 1024L) {
						if (bytes > 1024L * 1024L * 1024L * 1024L) {
							return formatter.format("%9.2f", ((float) bytes / (float) (1024L * 1024L * 1024L * 1024L))) + " TB";
						} else {
							return formatter.format("%9.2f", (float) bytes / (float) (1024L * 1024L * 1024L)) + " GB";
						}
					} else {
						return formatter.format("%9.2f", ((float) bytes / (float) (1024L * 1024L))) + " MB";
					}
				} else {
					return formatter.format("%9.2f", ((float) bytes / (float) 1024L)) + " KB";
				}
			} else {
				return "" + bytes + " B";
			}
		} finally {
			formatter.close();
		}
	}

	public static final String timeSpanToString(GregorianCalendar startGc, GregorianCalendar stopGc) {
		long millis = stopGc.getTimeInMillis() - startGc.getTimeInMillis();
		return millis / 60000 + " minutes";
	}
	
	public static final String nanosToString(long nanos) {
		return millisecondsToString(nanos / 1000000);
	}
	
	public static final String millisecondsToString(long millis) {
		if (millis < 1000) {
			return millis + "ms";
		}
		if (millis < 60 * 1000) {
			return (millis / 1000f) + "s";
		}
		if (millis < 60 * 60 * 1000) {
			long m = millis / 60000;
			long s = (millis % 60000) / 1000;
			return addBefore(m, 2, "0") + "m " + addBefore(s, 2, "0") + "s";<commit_msg>Got rid of leading spaces<commit_after>package org.bimserver.utils;

/******************************************************************************
 * Copyright (C) 2009-2019  BIMserver.org
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see {@literal<http://www.gnu.org/licenses/>}.
 *****************************************************************************/

import java.util.Calendar;
import java.util.Formatter;
import java.util.GregorianCalendar;

public class Formatters {
	private Formatters() {
	}

	public static String bytesToString(long bytes) {
		Formatter formatter = new Formatter();
		try {
			if (bytes > 1024) {
				if (bytes > 1024L * 1024L) {
					if (bytes > 1024L * 1024L * 1024L) {
						if (bytes > 1024L * 1024L * 1024L * 1024L) {
							return formatter.format("%9.2f", ((float) bytes / (float) (1024L * 1024L * 1024L * 1024L))).toString().trim() + " TB";
						} else {
							return formatter.format("%9.2f", (float) bytes / (float) (1024L * 1024L * 1024L)).toString().trim() + " GB";
						}
					} else {
						return formatter.format("%9.2f", ((float) bytes / (float) (1024L * 1024L))).toString().trim() + " MB";
					}
				} else {
					return formatter.format("%9.2f", ((float) bytes / (float) 1024L)).toString().trim() + " KB";
				}
			} else {
				return "" + bytes + " B";
			}
		} finally {
			formatter.close();
		}
	}

	public static final String timeSpanToString(GregorianCalendar startGc, GregorianCalendar stopGc) {
		long millis = stopGc.getTimeInMillis() - startGc.getTimeInMillis();
		return millis / 60000 + " minutes";
	}
	
	public static final String nanosToString(long nanos) {
		return millisecondsToString(nanos / 1000000);
	}
	
	public static final String millisecondsToString(long millis) {
		if (millis < 1000) {
			return millis + "ms";
		}
		if (millis < 60 * 1000) {
			return (millis / 1000f) + "s";
		}
		if (millis < 60 * 60 * 1000) {
			long m = millis / 60000;
			long s = (millis % 60000) / 1000;
			return addBefore(m, 2, "0") + "m " + addBefore(s, 2, "0") + "s";
{'fraction_non_alphanumeric': 0.17952694842962388, 'fraction_numerical': 0.05777433113609926, 'mean_word_length': 3.4435831180017225, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '405517', 'n_tokens_mistral': 2022, 'n_tokens_neox': 1526, 'n_words': 519}