<commit_before>/*
 * Copyright (c) 2009-2013 <NAME>
 */
package fi.tnie.db.model.cm;

import fi.tnie.db.model.AbstractValueModel;
import fi.tnie.db.model.ChangeListener;
import fi.tnie.db.model.ValueModel;

/** 
 *
 * @param <V> Type of the value (computation result) of this model. 
 * @param <S> Type of the input of the computation this model represents.
 */
public abstract class AbstractTransformationModel<V, S>
	extends AbstractValueModel<V> {
	
	public AbstractTransformationModel(final ValueModel<S> source) {
		source.addChangeHandler(new ChangeListener<S>() {
			@Override
			public void changed(S from, S to) {
				V result = transform(to);
				fireIfChanged(get(), result);
			}
		});
	}
	
	/**
	 * @param source
	 * @return
	 */
	public abstract V transform(S source);
}
<commit_msg>Fix bug in AbstractTransformationModel<commit_after>/*
 * Copyright (c) 2009-2013 <NAME>
 */
package fi.tnie.db.model.cm;

import fi.tnie.db.model.AbstractValueModel;
import fi.tnie.db.model.ChangeListener;
import fi.tnie.db.model.ValueModel;

/** 
 *
 * @param <V> Type of the value (computation result) of this model. 
 * @param <S> Type of the input of the computation this model represents.
 */
public abstract class AbstractTransformationModel<V, S>
	extends AbstractValueModel<V> {
	
	private ValueModel<S> source;
	
	public AbstractTransformationModel(final ValueModel<S> source) {
		source.addChangeHandler(new ChangeListener<S>() {
			@Override
			public void changed(S from, S to) {
				// change has already taken place:
				V previous = transform(from);				
				fireIfChanged(previous, get());
			}
		});
		
		this.source = source;
	}
	
	/**
	 * @param source
	 * @return
	 */
	public abstract V transform(S source);

	public ValueModel<S> getSource() {
		return source;
	}
	
	@Override
	public V get() {		
		return transform(getSource().get());
	}
}

{'fraction_non_alphanumeric': 0.12526881720430108, 'fraction_numerical': 0.008602150537634409, 'mean_word_length': 3.8087855297157622, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, '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': '2010908', 'n_tokens_mistral': 664, 'n_tokens_neox': 585, 'n_words': 162}