/**
 * Copyright 2015 Delft University of Technology
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package nl.tudelft.graphalytics.reporting.html;

import nl.tudelft.graphalytics.domain.Graph;

import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.text.FieldPosition;

/**
 * Utility class for use in the HTML report templates.
 *
 * @author Tim Hegeman
 */
public class TemplateUtility {

	/**
	 * Formats an integer value into a condensed human readable format using 'K' (thousands), 'M' (millions), or 'B'
	 * (billions) postfixes. Values are rounded to two decimal places.
	 *
	 * @param value the value to format
	 * @return a human-readable string representation of the value
	 */
	public String formatIntegerHumanReadable(long value) {
		final long THOUSAND = 1000;
		final long MILLION = THOUSAND * THOUSAND;
		final long BILLION = THOUSAND * MILLION;

		StringBuffer sb = new StringBuffer();

		// Insert minus sign if needed
		if (value < 0) {
			sb.append("-");
			value = -value;
		}

		// Check for billions/millions/thousands
		double scaledValue = value;
		String humanReadableScale = "";
		if (value >= BILLION) {
			scaledValue /= BILLION;
			humanReadableScale = "B";
		} else if (value >= MILLION) {
			scaledValue /= MILLION;
			humanReadableScale = "M";
		} else if (value >= THOUSAND) {
			scaledValue /= THOUSAND;
			humanReadableScale = "K";
		}

		// Round the scaled value
		DecimalFormat format = new DecimalFormat("#.##");
		format.setRoundingMode(RoundingMode.HALF_UP);
		format.format(scaledValue, sb, new FieldPosition(DecimalFormat.INTEGER_FIELD));

		sb.append(humanReadableScale);
		return sb.toString();
	}

	/**
	 * Generates a string containing the name and size of a graph, with format: "graphname (X vertices, Y edges)".
	 *
	 * @param graph the graph to generate a human-readable string for
	 * @return a string representation of the graph name and size
	 */
	public String formatGraphNameSize(Graph graph) {
		StringBuffer sb = new StringBuffer();
		sb.append(graph.getName()).append(" (")
				.append(formatIntegerHumanReadable(graph.getNumberOfVertices())).append(" vertices, ")
				.append(formatIntegerHumanReadable(graph.getNumberOfEdges())).append(" edges)");
		return sb.toString();
	}

}

@@ -723,89 +723,26 @@
 ava.
-math.RoundingMode;%0Aimport java.text.DecimalFormat;%0Aimport java.text.FieldPosition
+text.DecimalFormat
 ;%0A%0A/
@@ -865,1261 +865,8 @@
  %7B%0A%0A
-%09/**%0A%09 * Formats an integer value into a condensed human readable format using 'K' (thousands), 'M' (millions), or 'B'%0A%09 * (billions) postfixes. Values are rounded to two decimal places.%0A%09 *%0A%09 * @param value the value to format%0A%09 * @return a human-readable string representation of the value%0A%09 */%0A%09public String formatIntegerHumanReadable(long value) %7B%0A%09%09final long THOUSAND = 1000;%0A%09%09final long MILLION = THOUSAND * THOUSAND;%0A%09%09final long BILLION = THOUSAND * MILLION;%0A%0A%09%09StringBuffer sb = new StringBuffer();%0A%0A%09%09// Insert minus sign if needed%0A%09%09if (value %3C 0) %7B%0A%09%09%09sb.append(%22-%22);%0A%09%09%09value = -value;%0A%09%09%7D%0A%0A%09%09// Check for billions/millions/thousands%0A%09%09double scaledValue = value;%0A%09%09String humanReadableScale = %22%22;%0A%09%09if (value %3E= BILLION) %7B%0A%09%09%09scaledValue /= BILLION;%0A%09%09%09humanReadableScale = %22B%22;%0A%09%09%7D else if (value %3E= MILLION) %7B%0A%09%09%09scaledValue /= MILLION;%0A%09%09%09humanReadableScale = %22M%22;%0A%09%09%7D else if (value %3E= THOUSAND) %7B%0A%09%09%09scaledValue /= THOUSAND;%0A%09%09%09humanReadableScale = %22K%22;%0A%09%09%7D%0A%0A%09%09// Round the scaled value%0A%09%09DecimalFormat format = new DecimalFormat(%22#.##%22);%0A%09%09format.setRoundingMode(RoundingMode.HALF_UP);%0A%09%09format.format(scaledValue, sb, new FieldPosition(DecimalFormat.INTEGER_FIELD));%0A%0A%09%09sb.append(humanReadableScale);%0A%09%09return sb.toString();%0A%09%7D%0A%0A
 %09/**
@@ -1167,16 +1167,65 @@
 raph) %7B%0A
+%09%09DecimalFormat df = new DecimalFormat(%22#,###%22);%0A
 %09%09String
@@ -1314,34 +1314,17 @@
 end(
+df.
 format
-IntegerHumanReadable
 (gra
@@ -1388,34 +1388,17 @@
 end(
+df.
 format
-IntegerHumanReadable
 (gra

Change graph size formatting in report to thousand separated