<commit_before>package uk.ac.surrey.soc.cress.extrawidgets

import java.util.concurrent.ConcurrentHashMap

import scala.collection.JavaConverters.asScalaConcurrentMapConverter
import scala.collection.Map
import scala.collection.mutable.ConcurrentMap

import org.nlogo.api.ExtensionManager
import org.nlogo.api.SimpleChangeEventPublisher

import uk.ac.surrey.soc.cress.extrawidgets.state.Reader
import uk.ac.surrey.soc.cress.extrawidgets.state.Writer

package object state {

  type WidgetKind = String
  type WidgetKey = String
  type PropertyKey = String
  type PropertyValue = Any
  type PropertyMap = Map[PropertyKey, PropertyValue]
  type MutablePropertyMap = ConcurrentMap[PropertyKey, PropertyValue]
  type WidgetMap = Map[WidgetKey, PropertyMap]
  type MutableWidgetMap = ConcurrentMap[WidgetKey, MutablePropertyMap]

  def getOrCreateModel(extensionManager: ExtensionManager): (Reader, Writer) = {
    // TODO: if there is already some object stored in the extensionManager,
    // we should catch the cast exception and explain the situation to the user...
    val (publisher, widgetMap) =
      Option(extensionManager.retrieveObject)
        .map(_.asInstanceOf[(SimpleChangeEventPublisher, MutableWidgetMap)])
        .getOrElse { (new SimpleChangeEventPublisher, newWidgetMap) }
    extensionManager.storeObject((publisher, widgetMap))
    val reader = new Reader(widgetMap, publisher)
    val writer = new Writer(widgetMap, publisher, reader)
    (reader, writer)
  }

  /*  Parameters for the ConcurrentHashMaps. concurrencyLevel is 2 as only
   *  the job thread and the AWT event should ever write to the map.
   *  initialCapacity and loadFactor are set at the regular Java defaults.
   *  NP 2014-09-25 */
  private val initialCapacity = 16
  private val loadFactor = 0.75f
  private val concurrencyLevel = 2

  private def newWidgetMap: MutableWidgetMap = {
    new ConcurrentHashMap[WidgetKey, MutablePropertyMap](
      initialCapacity, loadFactor, concurrencyLevel
    ).asScala
  }

  def newPropertyMap: MutablePropertyMap = {
    new ConcurrentHashMap[PropertyKey, PropertyValue](
      initialCapacity, loadFactor, concurrencyLevel
    ).asScala
  }
}
<commit_msg>change PropertyValue to AnyRef instead of Any<commit_after>package uk.ac.surrey.soc.cress.extrawidgets

import java.util.concurrent.ConcurrentHashMap

import scala.collection.JavaConverters.asScalaConcurrentMapConverter
import scala.collection.Map
import scala.collection.mutable.ConcurrentMap

import org.nlogo.api.ExtensionManager
import org.nlogo.api.SimpleChangeEventPublisher

import uk.ac.surrey.soc.cress.extrawidgets.state.Reader
import uk.ac.surrey.soc.cress.extrawidgets.state.Writer

package object state {

  type WidgetKind = String
  type WidgetKey = String
  type PropertyKey = String
  type PropertyValue = AnyRef
  type PropertyMap = Map[PropertyKey, PropertyValue]
  type MutablePropertyMap = ConcurrentMap[PropertyKey, PropertyValue]
  type WidgetMap = Map[WidgetKey, PropertyMap]
  type MutableWidgetMap = ConcurrentMap[WidgetKey, MutablePropertyMap]

  def getOrCreateModel(extensionManager: ExtensionManager): (Reader, Writer) = {
    // TODO: if there is already some object stored in the extensionManager,
    // we should catch the cast exception and explain the situation to the user...
    val (publisher, widgetMap) =
      Option(extensionManager.retrieveObject)
        .map(_.asInstanceOf[(SimpleChangeEventPublisher, MutableWidgetMap)])
        .getOrElse { (new SimpleChangeEventPublisher, newWidgetMap) }
    extensionManager.storeObject((publisher, widgetMap))
    val reader = new Reader(widgetMap, publisher)
    val writer = new Writer(widgetMap, publisher, reader)
    (reader, writer)
  }

  /*  Parameters for the ConcurrentHashMaps. concurrencyLevel is 2 as only
   *  the job thread and the AWT event should ever write to the map.
   *  initialCapacity and loadFactor are set at the regular Java defaults.
   *  NP 2014-09-25 */
  private val initialCapacity = 16
  private val loadFactor = 0.75f
  private val concurrencyLevel = 2

  private def newWidgetMap: MutableWidgetMap = {
    new ConcurrentHashMap[WidgetKey, MutablePropertyMap](
      initialCapacity, loadFactor, concurrencyLevel
    ).asScala
  }

  def newPropertyMap: MutablePropertyMap = {
    new ConcurrentHashMap[PropertyKey, PropertyValue](
      initialCapacity, loadFactor, concurrencyLevel
    ).asScala
  }
}

{'fraction_non_alphanumeric': 0.07244736246321032, 'fraction_numerical': 0.006791940230925968, 'mean_word_length': 4.488198757763975, 'pattern_counts': {'":': 0, '<': 3, '<?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': '378515', 'n_tokens_mistral': 1280, 'n_tokens_neox': 1241, 'n_words': 346}