All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.shiftleft.Implicits.scala Maven / Gradle / Ivy

There is a newer version: 0.10.25
Show newest version
package io.shiftleft

object Implicits {

  /**
    * A wrapper around a Java iterator that throws a proper NoSuchElementException.
    *
    * Proper in this case means an exception with a stack trace.
    * This is intended to be used as a replacement for next() on the iterators
    * returned from TinkerPop since those are missing stack traces.
    */
  implicit class JavaIteratorDeco[T](iterator: java.util.Iterator[T]) {
    def nextChecked: T = {
      try {
        iterator.next
      } catch {
        case _: NoSuchElementException =>
          throw new NoSuchElementException()
      }
    }

    def nextOption: Option[T] = {
      if (iterator.hasNext) {
        Some(iterator.next)
      } else {
        None
      }
    }
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy