alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Scala example source code file (map_java_conversions.scala)

This example Scala source code file (map_java_conversions.scala) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Scala tags/keywords

array, array, none, none, some, some, string, string, test

The Scala map_java_conversions.scala source code






object Test {
  
  def main(args: Array[String]) {
    import collection.JavaConversions._
    
    test(new java.util.HashMap[String, String])
    test(new java.util.Properties)
    testConcMap
  }
  
  def testConcMap {
    import collection.JavaConversions._
    
    val concMap = new java.util.concurrent.ConcurrentHashMap[String, String]
    
    test(concMap)
    val cmap = asConcurrentMap(concMap)
    cmap.putIfAbsent("absentKey", "absentValue")
    cmap.put("somekey", "somevalue")
    assert(cmap.remove("somekey", "somevalue") == true)
    assert(cmap.replace("absentKey", "newAbsentValue") == Some("absentValue"))
    assert(cmap.replace("absentKey", "newAbsentValue", ".......") == true)
  }
  
  def test(m: collection.mutable.Map[String, String]) {
    m.clear
    assert(m.size == 0)
    
    m.put("key", "value")
    assert(m.size == 1)
    
    assert(m.put("key", "anotherValue") == Some("value"))
    assert(m.put("key2", "value2") == None)
    assert(m.size == 2)
    
    m += (("key3", "value3"))
    assert(m.size == 3)
    
    m -= "key2"
    assert(m.size == 2)
    assert(m.nonEmpty)
    assert(m.remove("key") == Some("anotherValue"))
    
    m.clear
    for (i <- 0 until 10) m += (("key" + i, "value" + i))
    for ((k, v) <- m) assert(k.startsWith("key"))
  }
  
}






Other Scala examples (source code examples)

Here is a short list of links related to this Scala map_java_conversions.scala source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.