<commit_before>package quotidian.web.controller

import com.bryanjswift.persistence.Savable
import java.io.Serializable
import quotidian.Logging
import quotidian.model.Quote
import quotidian.persistence.datastore.DatastorePersister

object QuoteController extends Logging {
// TODO: DatastorePersister should be abstracted to a Persister
	def all:List[Quote] = savablesToQuotes(DatastorePersister.getAll(Quote.kind))
	def bySource(source:String):List[Quote] = savablesToQuotes(DatastorePersister.search(Quote.kind,"source",source))
	def get(id:Serializable):Quote = DatastorePersister.get(Quote.kind,id).asInstanceOf[Quote]
	def random:Quote = {
		val quotes = all
		val position = (quotes.length * Math.random).toInt
		quotes(position)
	}
	private def savablesToQuotes(savables:List[Savable]):List[Quote] = {
		for {
			savable <- savables
		} yield savable.asInstanceOf[Quote]
	}
	def save(quote:Quote):Serializable = DatastorePersister.save(quote)
}<commit_msg>changed QuoteController to use a generic Persister rather than a specific DatastorePersister<commit_after>package quotidian.web.controller

import com.bryanjswift.persistence.{Persister,Savable}
import java.io.Serializable
import quotidian.Logging
import quotidian.model.Quote

abstract class QuoteController extends Logging {
	def persister:Persister
	def all:List[Quote] = savablesToQuotes(persister.getAll(Quote.kind))
	def bySource(source:String):List[Quote] = savablesToQuotes(persister.search(Quote.kind,"source",source))
	def get(id:Serializable):Quote = persister.get(Quote.kind,id).asInstanceOf[Quote]
	def random:Quote = {
		val quotes = all
		val position = (quotes.length * Math.random).toInt
		quotes(position)
	}
	private def savablesToQuotes(savables:List[Savable]):List[Quote] = {
		for {
			savable <- savables
		} yield savable.asInstanceOf[Quote]
	}
	def save(quote:Quote):Serializable = persister.save(quote)
}
{'fraction_non_alphanumeric': 0.10559662090813093, 'fraction_numerical': 0.0, 'mean_word_length': 6.703252032520325, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '2013355', 'n_tokens_mistral': 665, 'n_tokens_neox': 607, 'n_words': 112}