in server/src/main/scala/com/twitter/server/handler/RegistryHandler.scala [49:78]
private[this] def filterRegistry(filter: Option[String]): Registry = {
val registry = GlobalRegistry.get
filter match {
case None => registry
case Some(f) =>
val tokens = f.split("/").toList.dropWhile(_ == Formatter.RegistryKey)
if (tokens.isEmpty) {
registry
} else {
val matchers: Seq[Matcher] =
tokens.map { t =>
if (t == "*") WildcardMatcher
else new LiteralMatcher(t)
}
val filtered = new SimpleRegistry()
registry.foreach { entry =>
if (matchers.length <= entry.key.length) {
val allMatch = matchers.zip(entry.key).forall {
case (matcher, word) =>
matcher.matches(word)
}
if (allMatch)
filtered.put(entry.key, entry.value)
}
}
filtered
}
}
}