<commit_before>package at.innovative_solutions.tlv;

import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.List;

import at.innovative_solutions.tlvvisualizer.views.TagInfo;

public class DecodingFormatter implements Formatter<String> {
	final String _indentChars;
	int _indentLevel;
	final ValueDecoder fDecoder;
	
	public DecodingFormatter(final String indentChars, ValueDecoder decoder) {
		_indentChars = indentChars;
		_indentLevel = 0;
		fDecoder = decoder;
	}
	
	public String format(final List<TLV> tlvs) {
		StringBuilder sb = new StringBuilder();
		for(TLV t : tlvs)
			sb.append(format(t));
		return sb.toString();
	}
	
	@Override
	public String format(final TLV tlv) {
		return tlv.accept(this);
	}
	
	@Override
	public String format(final PrimitiveTLV tlv) {
		final StringBuilder sb = new StringBuilder();
		
		String idString = Utils.bytesToHexString(tlv.getID().toBytes());
		Long id = tlv.getID().toLong();
		String encoded = Utils.bytesToHexString(tlv.getData());
		
		sb.append(Utils.printChars(_indentChars, _indentLevel));
		sb.append(idString);
		sb.append(" > ");
		String name = fDecoder.getName(tlv);
		if(name != null) {
			sb.append(name);
			sb.append("\n");
			sb.append(Utils.printChars(_indentChars, _indentLevel));
			sb.append(Utils.printChars(" ", idString.length() + 3));
			
			String decoded = fDecoder.toString(tlv);
			
			if(!decoded.equals(""))
				sb.append(decoded).append(" (").append(encoded).append(")");
			else
				sb.append(encoded);
		} else {
			sb.append(encoded);
		}
		
		sb.append("\n");
		return sb.toString();
	}
	
	@Override
	public String format(final ConstructedTLV tlv) {
		final StringBuilder sb = new StringBuilder();
		
		Long id = tlv.getID().toLong();
		
		sb.append(Utils.printChars(_indentChars, _indentLevel));
		sb.append(Utils.bytesToHexString(tlv.getID().toBytes()));
		
		sb.append(" : ").append(fDecoder.getName(tlv));
		
		sb.append("\n");
		_indentLevel += 1;
		
		for(TLV child : tlv.getTLVs())
			sb.append(child.accept(this));
		_indentLevel -= 1;
		return sb.toString();
	}
	
	// TODO implement
	@Override
	public String format(final ErrorTLV tlv) {
		final StringBuilder sb = new StringBuilder();
		sb.append(Utils.printChars(_indentChars, _indentLevel));
		sb.append("ERROR");
		return sb.toString();
	}
}
<commit_msg>Cleanup DecodingFormatter<commit_after>package at.innovative_solutions.tlv;

import java.util.List;

public class DecodingFormatter implements Formatter<String> {
	final String fIndentChars;
	int fIndentLevel;
	final ValueDecoder fDecoder;
	
	public DecodingFormatter(final String indentChars, ValueDecoder decoder) {
		fIndentChars = indentChars;
		fIndentLevel = 0;
		fDecoder = decoder;
	}
	
	public String format(final List<TLV> tlvs) {
		StringBuilder sb = new StringBuilder();
		for(TLV t : tlvs)
			sb.append(format(t));
		return sb.toString();
	}
	
	@Override
	public String format(final TLV tlv) {
		return tlv.accept(this);
	}
	
	@Override
	public String format(final PrimitiveTLV tlv) {
		final StringBuilder sb = new StringBuilder();
		
		String idString = Utils.bytesToHexString(tlv.getID().toBytes());
		String encoded = Utils.bytesToHexString(tlv.getData());
		
		sb.append(Utils.printChars(fIndentChars, fIndentLevel));
		sb.append(idString);
		sb.append(" > ");
		String name = fDecoder.getName(tlv);
		if(name != null) {
			sb.append(name);
			sb.append("\n");
			sb.append(Utils.printChars(fIndentChars, fIndentLevel));
			sb.append(Utils.printChars(" ", idString.length() + 3));
			
			String decoded = fDecoder.toString(tlv);
			
			if(!decoded.equals(""))
				sb.append(decoded).append(" (").append(encoded).append(")");
			else
				sb.append(encoded);
		} else {
			sb.append(encoded);
		}
		
		sb.append("\n");
		return sb.toString();
	}
	
	@Override
	public String format(final ConstructedTLV tlv) {
		final StringBuilder sb = new StringBuilder();
		
		sb.append(Utils.printChars(fIndentChars, fIndentLevel));
		sb.append(Utils.bytesToHexString(tlv.getID().toBytes()));
		
		sb.append(" : ").append(fDecoder.getName(tlv));
		
		sb.append("\n");
		fIndentLevel += 1;
		
		for(TLV child : tlv.getTLVs())
			sb.append(child.accept(this));
		fIndentLevel -= 1;
		return sb.toString();
	}
	
	// TODO implement
	@Override
	public String format(final ErrorTLV tlv) {
		final StringBuilder sb = new StringBuilder();
		sb.append(Utils.printChars(fIndentChars, fIndentLevel));
		sb.append("ERROR");
		return sb.toString();
	}
}

{'fraction_non_alphanumeric': 0.142282778646415, 'fraction_numerical': 0.0017869108778199687, 'mean_word_length': 4.28066037735849, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '2020665', 'n_tokens_mistral': 1710, 'n_tokens_neox': 1473, 'n_words': 299}