Created
October 12, 2015 15:26
-
-
Save jamesanto/1dc88d6345f1e3050c7e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package me.socure.service.pipl | |
/** | |
* Created by jamesanto on 10/12/15. | |
*/ | |
object PersonUtil { | |
import scala.language.implicitConversions | |
import com.pipl.api.data.containers.Person | |
import scala.collection.JavaConverters._ | |
case class Range[T](min: T, max: T) | |
implicit class RichPerson(persons: Traversable[Person]) { | |
def countNames = persons.flatMap(_.getNames.asScala).toSet.size | |
def validSinceRange = { | |
val vs = persons.flatMap(_.getAddresses.asScala).map(_.validSince) | |
(vs.min, vs.max) | |
} | |
} | |
implicit def toRichPerson(persons: java.util.Collection[Person]): RichPerson = new RichPerson(persons.asScala) | |
def countNames(persons: java.util.Collection[Person]) = persons.countNames | |
def validSinceRange(persons: java.util.Collection[Person]) = { | |
import PersonUtil._ | |
val r = persons.validSinceRange | |
Range(r._1, r._2) | |
} | |
} | |
//Usage from java | |
import me.socure.service.pipl.PersonUtil | |
SearchAPIResponseRaw response = //Response | |
int namesCount = PersonUtil.countNames(response.getPossiblePersons()) | |
PersonUtil.Range<Date> validSince = PersonUtil.validSinceRange(response.getPossiblePersons()) | |
Date min = validSince.min() | |
Date max = validSince.max() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment