@@ -15,9 +15,7 @@ package core
1515
1616import typeclasses .ExtractSchemaKey
1717
18- /**
19- * Class to filter Schemas by [[SchemaKey ]]
20- */
18+ /** Filter self-describing schemas by [[SchemaKey ]]. */
2119final case class SchemaCriterion (
2220 vendor : String ,
2321 name : String ,
@@ -28,33 +26,34 @@ final case class SchemaCriterion(
2826) {
2927
3028 /**
31- * Whether a SchemaKey is valid.
29+ * Check if a [[ SchemaKey ]] is valid.
3230 *
3331 * It's valid if the vendor, name, format, and model all match
34- * and the supplied key's revision and addition do not exceed the
35- * criterion's revision and addition .
32+ * and the supplied key's REVISION and ADDITION do not exceed the
33+ * criterion's REVISION and ADDITION .
3634 *
37- * @param key The SchemaKey to validate
38- * @return whether the SchemaKey is valid
35+ * @param key The [[ SchemaKey ]] to validate.
36+ * @return `true` if the [[ SchemaKey ]] is valid.
3937 */
4038 def matches (key : SchemaKey ): Boolean =
4139 prefixMatches(key) && verMatch(key.version)
4240
4341 /**
44- * Filter sequence of entities by this [[SchemaCriterion ]]
45- * It can be applied for getting only right JSON instances
46- * out of array with custom context
42+ * Filter a sequence of entities by this [[SchemaCriterion ]].
43+ *
44+ * Can be used for getting only the `Right` JSON instances
45+ * out of an array of custom contexts.
4746 *
4847 * Usage:
4948 * {{{
50- * // This will get best matching entity
49+ * // This will get the best match for an entity
5150 * criterion.takeFrom(_.schema)(entities).sort.getOption
5251 * }}}
5352 *
54- * @param entities list of Self -describing instances (or Schemas)
55- * @tparam E type of Self -describing entity , having
56- * an `ExtractSchemaKey` instance in scope
57- * @return list of matching entities
53+ * @param entities A list of self -describing data blobs.
54+ * @tparam E The base type of the self -describing data , having
55+ * an `ExtractSchemaKey` instance in scope.
56+ * @return A list of matching entities.
5857 */
5958 def pickFrom [E : ExtractSchemaKey ](entities : Seq [E ]): Seq [E ] =
6059 entities.foldLeft(Seq .empty[E ]) { (acc, cur) =>
@@ -65,46 +64,45 @@ final case class SchemaCriterion(
6564 }
6665
6766 /**
68- * Format as a schema URI, but the revision and addition
69- * may be replaced with "*" wildcards.
67+ * Format this [[SchemaCriterion ]] as an Iglu schema URI,
68+ * whereby the REVISION and ADDITION may be replaced with
69+ * "*" wildcards.
7070 *
71- * @return the String representation of this criterion
71+ * @return The string representation of this criterion.
7272 */
7373 def asString : String =
7474 s " iglu: $vendor/ $name/ $format/ $versionString"
7575
76- /**
77- * Stringify version part of criterion
78- */
76+ /** Stringify the version of this [[SchemaCriterion ]]. */
7977 def versionString : String =
8078 " %s-%s-%s" .format(model.getOrElse(" *" ), revision.getOrElse(" *" ), addition.getOrElse(" *" ))
8179
8280 /**
83- * Whether the vendor, name, and format are all correct .
81+ * Check if the vendor, name, and format are all valid .
8482 *
85- * @param key The SchemaKey to validate
86- * @return whether the first three fields are correct
83+ * @param key The [[ SchemaKey ]] to validate.
84+ * @return `true` if the first three fields are correct.
8785 */
8886 private def prefixMatches (key : SchemaKey ): Boolean =
8987 key.vendor == vendor && key.name == name && key.format == format
9088
9189 /**
92- * Match only [[SchemaVer ]]
90+ * Match only [[SchemaVer ]].
9391 *
94- * @param ver SchemaVer of some other [[SchemaKey ]]
95- * @return true if all specified groups matched
92+ * @param ver A [[ SchemaVer ]] of some other [[SchemaKey ]].
93+ * @return ` true` if all specified groups match.
9694 */
9795 private [this ] def verMatch (ver : SchemaVer ): Boolean =
9896 groupMatch(ver.getModel, model) &&
9997 groupMatch(ver.getRevision, revision) &&
10098 groupMatch(ver.getAddition, addition)
10199
102100 /**
103- * Helper function for [[ verMatch ]] . Compares two numbers for same group
101+ * Helper function for ` verMatch` . Compares two numbers for the same group.
104102 *
105- * @param other Schema 's SchemaVer group (MODEL, REVISION, ADDITION)
106- * @param crit this Criterion 's corresponding group
107- * @return true if groups match or criterion not specific about it
103+ * @param other The other schema 's [[ SchemaVer ]] group (MODEL, REVISION, ADDITION).
104+ * @param crit This [[ SchemaCriterion ]] 's corresponding group.
105+ * @return ` true` if the groups match or if either entities are unknown.
108106 */
109107 private [this ] def groupMatch (other : Option [Int ], crit : Option [Int ]): Boolean = crit match {
110108 case Some (c) if other == Some (c) => true
@@ -114,14 +112,10 @@ final case class SchemaCriterion(
114112 }
115113}
116114
117- /**
118- * Companion object containing alternative constructor for a [[SchemaCriterion ]]
119- */
115+ /** Companion object, which contains custom constructors for [[SchemaCriterion ]]. */
120116object SchemaCriterion {
121117
122- /**
123- * Canonical regex to extract Schema criterion
124- */
118+ /** Canonical regular expression to extract [[SchemaCriterion ]]. */
125119 val criterionRegex = (" ^iglu:" + // Protocol
126120 " ([a-zA-Z0-9-_.]+)/" + // Vendor
127121 " ([a-zA-Z0-9-_]+)/" + // Name
@@ -131,11 +125,14 @@ object SchemaCriterion {
131125 " ((?:0|[1-9][0-9]*)|\\ *)$" ).r // ADDITION
132126
133127 /**
134- * Custom constructor for an SchemaCriterion from a string, like
135- * iglu:com.snowplowanalytics.snowplow/mobile_context/jsonschema/1-*-*
128+ * A custom constructor for a [[SchemaCriterion ]] from
129+ * a string like:
130+ * "iglu:com.vendor/schema_name/jsonschema/1-*-*".
131+ *
132+ * An Iglu schema URI is the default for schema lookup.
136133 *
137- * @param criterion string supposed to be criterion
138- * @return criterion object if string satisfies a format
134+ * @param criterion The string to convert to a [[ SchemaCriterion ]].
135+ * @return A [[ SchemaCriterion ]] if the string satisfies the format.
139136 */
140137 def parse (criterion : String ): Option [SchemaCriterion ] =
141138 criterion match {
@@ -145,9 +142,9 @@ object SchemaCriterion {
145142 }
146143
147144 /**
148- * Constructs an exhaustive SchemaCriterion.
145+ * Constructs a comprehensive [[ SchemaCriterion ]] .
149146 *
150- * @return our constructed SchemaCriterion
147+ * @return the constructed [[ SchemaCriterion ]].
151148 */
152149 def apply (
153150 vendor : String ,
@@ -160,10 +157,10 @@ object SchemaCriterion {
160157 SchemaCriterion (vendor, name, format, Some (model), Some (revision), Some (addition))
161158
162159 /**
163- * Constructs a SchemaCriterion from everything
164- * except the addition .
160+ * Constructs a [[ SchemaCriterion ]] with everything
161+ * except ADDITION .
165162 *
166- * @return our constructed SchemaCriterion
163+ * @return the constructed [[ SchemaCriterion ]].
167164 */
168165 def apply (
169166 vendor : String ,
@@ -175,18 +172,17 @@ object SchemaCriterion {
175172 SchemaCriterion (vendor, name, format, Some (model), Some (revision))
176173
177174 /**
178- * Constructs a SchemaCriterion which is agnostic
179- * of addition and revision.
180- * Restricts to model only.
175+ * Constructs a [[SchemaCriterion ]], which is agnostic
176+ * about REVISION and ADDITION (restricted to MODEL only).
181177 *
182- * @return our constructed SchemaCriterion
178+ * @return the constructed [[ SchemaCriterion ]].
183179 */
184180 def apply (vendor : String , name : String , format : String , model : Int ): SchemaCriterion =
185181 SchemaCriterion (vendor, name, format, Some (model), None , None )
186182
187183 /**
188- * Try to parse string number
189- * Helper method for [[parse ]]
184+ * Try to parse a string as a number.
185+ * Helper method for [[parse ]].
190186 */
191187 private def parseInt (number : String ): Option [Int ] =
192188 try {
0 commit comments