scala.collection.GenMap Scala Examples

The following examples show how to use scala.collection.GenMap. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.
Example 1
Source File: DebugUtil.scala    From sangria-slowlog   with Apache License 2.0 5 votes vote down vote up
package sangria.slowlog.util

import org.scalactic.Prettifier
import org.scalactic.PrettyMethods.Prettyizer
import sangria.ast._
import sangria.util.StringUtil

import scala.collection.GenMap

object DebugUtil {

  private val indentClasses: PartialFunction[Any, Boolean] = {
    case v if v.getClass.getSimpleName.startsWith("Introspection") => true
    case _: Document |
         _: Definition |
         _: SelectionContainer |
         _: Directive |
         _: VariableDefinition |
         _: ObjectValue |
         _: ObjectField |
         _: ListValue |
         _: Argument => true
  }

  private val myPrettifier: Prettifier =
    new Prettifier {
      def apply(o: Any): String = {
        def indent(n: Int) = "  " * n

        def loop(obj: Any, level: Int, indentLists: Boolean = false, indentMap: Boolean = false): String =
          obj match {
            case null => "null"
            case aString: String => "\"" + StringUtil.escapeString(aString) + "\""
            case aStringWrapper: scala.collection.immutable.StringOps => "\"" + aStringWrapper + "\""
            case aChar: Char =>  "\'" + aChar + "\'"
            case ot: OperationType => "OperationType." + ot
            case aGenMap: GenMap[_, _] =>
              (if (indentMap) indent(level + 1) else "") + "Map(\n" +
                aGenMap.toIterator.map { case (key, value) =>
                  indent(level + 1) + loop(key, level) + " -> " + loop(value, level + 1, indentMap = false, indentLists = true)
                }.mkString(",\n") + ")"
            case list: scala.collection.immutable.List[_] =>
              if (list.isEmpty) "Nil"
              else
                if (indentLists)
                  "List(\n" + list.map(x => indent(level + 1) + loop(x, level + 1)).mkString(",\n") + ")"
                else
                  "List(" + list.map(x => loop(x, level)).mkString(", ") + ")"
            case list: scala.collection.immutable.Vector[_] =>
              if (list.isEmpty) "Vector.empty"
              else
                if (indentLists)
                  "Vector(\n" + list.map(x => indent(level + 1) + loop(x, level + 1)).mkString(",\n") + ")"
                else
                  "Vector(" + list.map(x => loop(x, level)).mkString(", ") + ")"
            case prod: Product =>
              val args = prod.productIterator.toList

              if (args.nonEmpty)
                if (indentClasses.isDefinedAt(prod) && indentClasses(prod))
                  prod.productPrefix + "(\n" + args.map(x => indent(level + 1) + loop(x, level + 1, true)).mkString(",\n") + "\n" + indent(level) + ")"
                else
                  prod.productPrefix + "(" + args.map(x => loop(x, level, false)).mkString(", ") + ")"
              else
                prod.productPrefix
            case anythingElse =>
              anythingElse.toString
          }

        loop(o, 0, false)
      }
    }

  private implicit val conf = myPrettifier

  def prettyRender(obj: Any) = obj.pretty

  def prettyPrint(obj: Any) = println(prettyRender(obj))

} 
Example 2
Source File: DebugUtil.scala    From sangria   with Apache License 2.0 5 votes vote down vote up
package sangria.util

import org.scalactic.Prettifier

import scala.collection.GenMap
import org.scalactic.PrettyMethods.Prettyizer
import sangria.ast._
import spray.json.JsValue

object DebugUtil {

  private val indentClasses: PartialFunction[Any, Boolean] = {
    case v if v.getClass.getSimpleName.startsWith("Introspection") => true
    case _: Document |
         _: InputDocument |
         _: Definition |
         _: SelectionContainer |
         _: Directive |
         _: VariableDefinition |
         _: ObjectValue |
         _: ObjectField |
         _: ListValue |
         _: Argument => true
  }

  private val myPrettifier: Prettifier =
    new Prettifier {
      def apply(o: Any): String = {
        def indent(n: Int) = "  " * n

        def loop(obj: Any, level: Int, indentLists: Boolean = false, indentMap: Boolean = false): String =
          obj match {
            case null => "null"
            case json: JsValue => json.prettyPrint
            case aString: String => "\"" + StringUtil.escapeString(aString) + "\""
            case aStringWrapper: scala.collection.immutable.StringOps => "\"" + aStringWrapper + "\""
            case aChar: Char =>  "\'" + aChar + "\'"
            case ot: OperationType => "OperationType." + ot
            case aGenMap: GenMap[_, _] =>
              (if (indentMap) indent(level + 1) else "") + "Map(\n" +
                aGenMap.toIterator.map { case (key, value) =>
                  indent(level + 1) + loop(key, level) + " -> " + loop(value, level + 1, indentMap = false, indentLists = true)
                }.mkString(",\n") + ")"
            case list: scala.collection.immutable.List[_] =>
              if (list.isEmpty) "Nil"
              else
                if (indentLists)
                  "List(\n" + list.map(x => indent(level + 1) + loop(x, level + 1)).mkString(",\n") + ")"
                else
                  "List(" + list.map(x => loop(x, level)).mkString(", ") + ")"
            case list: scala.collection.immutable.Vector[_] =>
              if (list.isEmpty) "Vector.empty"
              else
                if (indentLists)
                  "Vector(\n" + list.map(x => indent(level + 1) + loop(x, level + 1)).mkString(",\n") + ")"
                else
                  "Vector(" + list.map(x => loop(x, level)).mkString(", ") + ")"
            case prod: Product =>
              val args = prod.productIterator.toList

              if (args.nonEmpty)
                if (indentClasses.isDefinedAt(prod) && indentClasses(prod))
                  prod.productPrefix + "(\n" + args.map(x => indent(level + 1) + loop(x, level + 1, true)).mkString(",\n") + "\n" + indent(level) + ")"
                else
                  prod.productPrefix + "(" + args.map(x => loop(x, level, false)).mkString(", ") + ")"
              else
                prod.productPrefix
            case anythingElse =>
              anythingElse.toString
          }

        loop(o, 0, false)
      }
    }

  private implicit val conf = myPrettifier

  def prettyRender[T](obj: T): String = {
    obj.pretty
  }

  def prettyPrint[T](obj: T): T = {
    println(prettyRender(obj))

    obj
  }

} 
Example 3
Source File: VectorGrid.scala    From osmesa   with Apache License 2.0 5 votes vote down vote up
package osmesa.analytics

import java.io.ByteArrayInputStream
import java.net.URI
import java.util.zip.GZIPInputStream

import geotrellis.proj4.WebMercator
import geotrellis.spark.tiling.ZoomedLayoutScheme
import geotrellis.vector.{Extent, PointFeature}
import geotrellis.vectortile.{Layer, VInt64, VectorTile}
import org.apache.commons.io.IOUtils
import org.apache.spark.internal.Logging
import osmesa.analytics.updater.Implicits._
import osmesa.analytics.updater._

import scala.collection.GenMap
import scala.collection.parallel.TaskSupport

trait VectorGrid extends Logging {
  // Default base zoom (highest resolution tiles produced)
  val DefaultBaseZoom: Int = 10

  // Number of cells per side in a gridded tile
  implicit val Cells: Int = 128

  // Number of cells in a gridded tile at the base of the pyramid (may be used for over-zooming)
  val BaseCells: Int = Cells

  // Default upload concurrency
  val DefaultUploadConcurrency: Int = 8

  implicit val LayoutScheme: ZoomedLayoutScheme = ZoomedLayoutScheme(WebMercator)
  val SequenceLayerName: String = "__sequences__"

  def getCommittedSequences(tile: VectorTile): Set[Int] =
    // NOTE when working with hashtags, this should be the changeset sequence, since changes from a
    // single sequence may appear in different batches depending on when changeset metadata arrives
    tile.layers
      .get(SequenceLayerName)
      .map(_.features.flatMap(f => f.data.values.map(valueToLong).map(_.intValue)))
      .map(_.toSet)
      .getOrElse(Set.empty)

  def makeSequenceLayer(sequences: Set[Int], extent: Extent, tileWidth: Int = 4096): (String, Layer) = {
    // create a second layer w/ a feature corresponding to committed sequences (in the absence of
    // available tile / layer metadata)
    val updatedSequences =
      sequences.toSeq.sorted
        .takeRight(1000)
        .zipWithIndex
        .map {
          case (seq, idx) =>
            idx.toString -> VInt64(seq)
        }
        .toMap

    val sequenceFeature = PointFeature(extent.center, updatedSequences)

    makeLayer(SequenceLayerName, extent, Seq(sequenceFeature), tileWidth)
  }

  def loadMVTs(urls: Map[URI, Extent])(
      implicit taskSupport: TaskSupport): GenMap[URI, VectorTile] = {
    // convert to a parallel collection to load more tiles concurrently
    val parUrls = urls.par
    parUrls.tasksupport = taskSupport

    parUrls.map {
      case (uri, extent) =>
        (uri,
         read(uri).map(
           bytes =>
             VectorTile.fromBytes(
               IOUtils.toByteArray(new GZIPInputStream(new ByteArrayInputStream(bytes))),
               extent)))
    } filter {
      case (_, mvt) => mvt.isDefined
    } map {
      case (uri, mvt) => uri -> mvt.get
    }
  }
} 
Example 4
Source File: DebugUtil.scala    From sangria-relay   with Apache License 2.0 5 votes vote down vote up
package sangria.relay.util

import org.scalactic.Prettifier
import org.scalactic.PrettyMethods.Prettyizer
import sangria.ast._
import sangria.util.StringUtil

import scala.collection.GenMap

object DebugUtil {

  private val indentClasses: PartialFunction[Any, Boolean] = {
    case v if v.getClass.getSimpleName.startsWith("Introspection") => true
    case _: Document |
         _: Definition |
         _: SelectionContainer |
         _: Directive |
         _: VariableDefinition |
         _: ObjectValue |
         _: ObjectField |
         _: ListValue |
         _: Argument => true
  }

  private val myPrettifier: Prettifier =
    new Prettifier {
      def apply(o: Any): String = {
        def indent(n: Int) = "  " * n

        def loop(obj: Any, level: Int, indentLists: Boolean = false, indentMap: Boolean = false): String =
          obj match {
            case null => "null"
            case aString: String => "\"" + StringUtil.escapeString(aString) + "\""
            case aStringWrapper: scala.collection.immutable.StringOps => "\"" + aStringWrapper + "\""
            case aChar: Char =>  "\'" + aChar + "\'"
            case ot: OperationType => "OperationType." + ot
            case aGenMap: GenMap[_, _] =>
              (if (indentMap) indent(level + 1) else "") + "Map(\n" +
                aGenMap.iterator.map { case (key, value) =>
                  indent(level + 1) + loop(key, level) + " -> " + loop(value, level + 1, indentMap = false, indentLists = true)
                }.mkString(",\n") + ")"
            case list: scala.collection.immutable.List[_] =>
              if (list.isEmpty) "Nil"
              else
                if (indentLists)
                  "List(\n" + list.map(x => indent(level + 1) + loop(x, level + 1)).mkString(",\n") + ")"
                else
                  "List(" + list.map(x => loop(x, level)).mkString(", ") + ")"
            case list: scala.collection.immutable.Vector[_] =>
              if (list.isEmpty) "Vector.empty"
              else
                if (indentLists)
                  "Vector(\n" + list.map(x => indent(level + 1) + loop(x, level + 1)).mkString(",\n") + ")"
                else
                  "Vector(" + list.map(x => loop(x, level)).mkString(", ") + ")"
            case prod: Product =>
              val args = prod.productIterator.toList

              if (args.nonEmpty)
                if (indentClasses.isDefinedAt(prod) && indentClasses(prod))
                  prod.productPrefix + "(\n" + args.map(x => indent(level + 1) + loop(x, level + 1, true)).mkString(",\n") + "\n" + indent(level) + ")"
                else
                  prod.productPrefix + "(" + args.map(x => loop(x, level, false)).mkString(", ") + ")"
              else
                prod.productPrefix
            case anythingElse =>
              anythingElse.toString
          }

        loop(o, 0, false)
      }
    }

  private implicit val conf = myPrettifier

  def prettyRender(obj: Any) = obj.pretty

  def prettyPrint(obj: Any) = println(prettyRender(obj))

}