0

I know this may seem like a pretty simple question, but I am new to Scala and could not find a solution online.

Basically I am converting an AI based program and all of my data is in JSON format in Mongo. The final little bit of this is a function that runs a simulation. I have run into a problem of comparing [Ljava.lang.String to a basic Array[String].

//temporary way to store variable
var g = row.as[MongoDBObject]("country").as[BasicDBList]("league").toArray(new Array[String](row.as[MongoDBObject]("country").as[BasicDBList]("league").length))

if (g.contains(Array("primera","division")))
  //Do stuff

That always returns false even though the array will return true if I do

     if (g.contains("primera") && g.contains("division"))

How can I compare the two of these without writing a separate method to loop through and check (and be horribly inefficient)

I need the array to be dynamic. "primera" and "division" are just placeholders for the function to check against a string Array named league that is feed in.

//EDIT I got closer with Array[String]("primera","division").exists(g.contains) but that matches either "primera" or "division" not both.

The API is: http://mongodb.github.io/casbah/api/#com.mongodb.casbah.package

When I call g.getClass it returns class [Ljava.lang.String. So I am comparing that against an Array[String]

Mitchell Ingram
  • 686
  • 2
  • 11
  • 23

1 Answers1

0

Figured it out. I needed to convert both to a Set and use subsetOf

So the final answer was:

      if(Set("primera","division").subsetOf(g.toSet))
      //do Stuff
Mitchell Ingram
  • 686
  • 2
  • 11
  • 23