algoliasearch.internal.AlgoliaAgent.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of algoliasearch-scala_3 Show documentation
Show all versions of algoliasearch-scala_3 Show documentation
Scala client for Algolia Search API
package algoliasearch.internal
import algoliasearch.config.AgentSegment
import scala.collection.mutable
/** Handles Algolia agent segments.
*
* An instance of this class maintains a set of [AgentSegment]s, and provides methods to add, remove, and format these
* segments.
*
* @param clientVersion
* client version
*/
class AlgoliaAgent(clientVersion: String) {
private val segs = mutable.LinkedHashSet[AgentSegment](
AgentSegment("Algolia for Scala", clientVersion),
AgentSegment("JVM", System.getProperty("java.version"))
)
/** Adds a new segment to the agent segments. */
def addSegment(seg: AgentSegment): AlgoliaAgent = {
if (!segs.contains(seg)) {
segs += seg
}
this
}
/** Adds all segments to the agent segments */
def addSegments(segments: Seq[AgentSegment]): AlgoliaAgent = {
segs.addAll(segments)
this
}
override def toString: String = {
segs.mkString("; ")
}
}
object AlgoliaAgent {
/** Creates a new AlgoliaAgent instance with the given client version. */
def apply(clientVersion: String): AlgoliaAgent =
new AlgoliaAgent(clientVersion)
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy