forked from HydraCG/Heracles.ts
/
MappingsCollection.ts
53 lines (47 loc) · 1.77 KB
/
MappingsCollection.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { IIriTemplateMapping } from "../IIriTemplateMapping";
import ResourceFilterableCollection from "./ResourceFilterableCollection";
/**
* Provides a collection of {@link IIriTemplateMapping} that can be filtered with relevant criteria.
* @class
*/
export default class MappingsCollection extends ResourceFilterableCollection<IIriTemplateMapping> {
/**
* Initializes a new instance of the {@link MappingsCollection}
* class with initial collections of mappings to filter.
* @param {Iterable<IIriTemplateMapping>} [mappings] Initial collection of mappings to filter.
*/
public constructor(mappings?: Iterable<IIriTemplateMapping>) {
super(mappings);
}
/**
* Obtains a collection of mappings for a given variable name.
* @param {string} variableName Variable name.
* @returns {IMappingsCollection}
*/
public ofVariableName(variableName: string): MappingsCollection {
let result: MappingsCollection = this;
if (typeof variableName === "string" && variableName.length > 0) {
result = this.narrowFiltersWith("variable", variableName) as MappingsCollection;
}
return result;
}
/**
* Obtains a collection of mappings for a given predicate.
* @param {string} property Predicate IRI.
* @returns {IMappingsCollection}
*/
public ofProperty(property: string): MappingsCollection {
let result: MappingsCollection = this;
if (typeof property === "string" && property.length > 0) {
result = this.narrowFiltersWith<IIriTemplateMapping>(
"property",
value => value.property.iri === property
) as MappingsCollection;
}
return result;
}
/** @inheritdoc */
protected createInstance(items: Iterable<IIriTemplateMapping>): MappingsCollection {
return new MappingsCollection(items);
}
}