<commit_before>package pl.edu.icm.cermine.tools.classification.general;

import java.util.*;
import pl.edu.icm.cermine.tools.classification.features.FeatureVector;

/**
 * Simple feature vector.
 *
 * @author <NAME> (<EMAIL>)
 */
public class SimpleFeatureVector implements FeatureVector {

    Map<String, Double> features = new HashMap<String, Double>();

    @Override
    public double getFeature(String name) {
        if (features.get(name) == null) {
            throw new IllegalArgumentException("Feature vector does not contain feature '" + name + "'.");
        }
        return features.get(name);
    }

    @Override
    public void addFeature(String name, double calculateFeatureValue) {
        features.put(name, calculateFeatureValue);
    }

    public Set<String> getFeatureNames() {
        return features.keySet();
    }
    
    @Override
    public String dump() {
    	String ret = "";
    	Set<String> keysSet = features.keySet();
    	ArrayList<String> keys = new ArrayList<String>(keysSet);
    	Collections.sort(keys);
    	for(String name: keys) {
    		String shortName = (name.length() > 18 ? name.substring(0, 18) : name);
    		ret += String.format("%18s: %5.2f\n", shortName, features.get(name));
    	}
    	return ret;
    }

    @Override
    public Integer size() {
    	return features.size();
    }

	@Override
	public Double[] getFeatures() {
		Double[] ret = new Double[features.size()];
		return features.values().toArray(ret);
	}

	@Override
	public void setFeature(String name, Double value) throws RuntimeException {
		if(!features.containsKey(name))
			throw new RuntimeException("Bad feature name: " + name);
		features.put(name, value);
	}
	
	@Override
	public SimpleFeatureVector clone() {
		SimpleFeatureVector ret = new SimpleFeatureVector();
		for(String feature: features.keySet()) {
			ret.features.put(new String(feature), new Double(features.get(feature)));
		}
		return ret;<commit_msg>StringBuilder used instead of String concatenation, new String() constructur deleted<commit_after>package pl.edu.icm.cermine.tools.classification.general;

import java.util.*;
import pl.edu.icm.cermine.tools.classification.features.FeatureVector;

/**
 * Simple feature vector.
 *
 * @author <NAME> (<EMAIL>)
 */
public class SimpleFeatureVector implements FeatureVector {

    Map<String, Double> features = new HashMap<String, Double>();

    @Override
    public double getFeature(String name) {
        if (features.get(name) == null) {
            throw new IllegalArgumentException("Feature vector does not contain feature '" + name + "'.");
        }
        return features.get(name);
    }

    @Override
    public void addFeature(String name, double calculateFeatureValue) {
        features.put(name, calculateFeatureValue);
    }

    @Override
    public Set<String> getFeatureNames() {
        return features.keySet();
    }
    
    @Override
    public String dump() {
    	StringBuilder ret = new StringBuilder();
    	Set<String> keysSet = features.keySet();
    	ArrayList<String> keys = new ArrayList<String>(keysSet);
    	Collections.sort(keys);
    	for(String name: keys) {
    		String shortName = (name.length() > 18 ? name.substring(0, 18) : name);
    		ret.append(String.format("%18s: %5.2f\n", shortName, features.get(name)));
    	}
    	return ret.toString();
    }

    @Override
    public Integer size() {
    	return features.size();
    }

	@Override
	public Double[] getFeatures() {
		Double[] ret = new Double[features.size()];
		return features.values().toArray(ret);
	}

	@Override
	public void setFeature(String name, Double value) throws RuntimeException {
		if(!features.containsKey(name))
			throw new RuntimeException("Bad feature name: " + name);
		features.put(name, value);
	}
	
	@Override
	public SimpleFeatureVector clone() {
		SimpleFeatureVector ret = new SimpleFeatureVector();
		for(String feature: features.keySet()) {
			ret.features.put(feature, new Double(features.get(feature)));
		}
		return ret;
{'fraction_non_alphanumeric': 0.12734082397003746, 'fraction_numerical': 0.0044943820224719105, 'mean_word_length': 3.496071829405163, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 21, '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': '5941314', 'n_tokens_mistral': 1200, 'n_tokens_neox': 1139, 'n_words': 285}