Guest User

Untitled

a guest
Jun 25th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. public interface JavaProductAPI {
  2. public Set<IProduct> getProducts(String isin);
  3. }
  4.  
  5. public class JavaProductAPIImpl implements JavaProductAPI {
  6. private Map<String, Set<ProductImpl>> productsByIsin;
  7.  
  8. public Set<IProduct> getProducts() {
  9. Set<ProductImpl> s = productsByIsin.get(isin);
  10. return s == null
  11. ? Collections.<IProduct>emptySet()
  12. : Collections.<IProduct>unmodifiableSet(s);
  13. }
  14.  
  15. }
  16.  
  17. val productsByIsin: Map[String, scala.collection.Set[ProductImpl]] = ...
  18. def getProducts(isin: String): scala.collection.immutable.Set[IProduct] = {
  19. productsByIsin.get(isin) match {
  20. case Some(s) => scala.collection.immutable.Set(s toSeq :_*)
  21. case None => scala.collection.immutable.Set.empty
  22. }
  23. }
  24.  
  25. val productsByIsin: Map[String, scala.collection.mutable.Set[ProductImpl]] = ...
  26. def getProducts(isin: String): scala.collection.Set[IProduct] = {
  27. productsByIsin.get(isin) match {
  28. case Some(s) => s readOnly
  29. case None => scala.collection.Set.empty
  30. }
  31. }
  32.  
  33. import scala.collection._
  34.  
  35. trait IProduct
  36. class ProductImpl extends IProduct
  37.  
  38. val productsByIsin: immutable.Map[String, immutable.Set[ProductImpl]] =
  39. immutable.Map.empty
  40. def getProducts(isin: String): immutable.Set[IProduct] =
  41. productsByIsin.getOrElse(isin, immutable.Set.empty).asInstanceOf[immutable.Set[IProduct]]
Add Comment
Please, Sign In to add comment