Skip to content

Commit

Permalink
chore(geodata): iterables with toList in Links
Browse files Browse the repository at this point in the history
  • Loading branch information
navispatial committed Jul 31, 2023
1 parent cb665af commit cbfce87
Showing 1 changed file with 33 additions and 23 deletions.
56 changes: 33 additions & 23 deletions dart/geodata/lib/src/common/links/links.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,19 @@ class Links with EquatableMixin {
@override
List<Object?> get props => [all];

/// All links matching by the given [rel], and optional [type] and [hreflang].
Iterable<Link> byRel(String rel, {String? type, String? hreflang}) =>
Iterable<Link> _byRelInternal(String rel, {String? type, String? hreflang}) =>
all.where(
(e) =>
e.rel == rel &&
(type == null || e.type == type) &&
(hreflang == null || e.hreflang == hreflang),
);

/// All links matching by the given [rel], and optional [type] and [hreflang].
Iterable<Link> byRel(String rel, {String? type, String? hreflang}) =>
_byRelInternal(rel, type: type, hreflang: hreflang)
.toList(growable: false);

/// All links with `rel` matching `alternate`.
///
/// IANA description: "Refers to a substitute for this context".
Expand Down Expand Up @@ -191,13 +195,15 @@ class Links with EquatableMixin {
///
/// Optional [type] and [hreflang] params can specify links more precisely.
Iterable<Link> items({String? type, String? hreflang}) =>
byRel('items', type: type, hreflang: hreflang).followedBy(
byRel(
'http://www.opengis.net/def/rel/ogc/1.0/items',
type: type,
hreflang: hreflang,
),
);
_byRelInternal('items', type: type, hreflang: hreflang)
.followedBy(
_byRelInternal(
'http://www.opengis.net/def/rel/ogc/1.0/items',
type: type,
hreflang: hreflang,
),
)
.toList(growable: false);

/// All links with `rel` matching `conformance` or
/// `http://www.opengis.net/def/rel/ogc/1.0/conformance`.
Expand All @@ -207,13 +213,15 @@ class Links with EquatableMixin {
///
/// Optional [type] and [hreflang] params can specify links more precisely.
Iterable<Link> conformance({String? type, String? hreflang}) =>
byRel('conformance', type: type, hreflang: hreflang).followedBy(
byRel(
'http://www.opengis.net/def/rel/ogc/1.0/conformance',
type: type,
hreflang: hreflang,
),
);
_byRelInternal('conformance', type: type, hreflang: hreflang)
.followedBy(
_byRelInternal(
'http://www.opengis.net/def/rel/ogc/1.0/conformance',
type: type,
hreflang: hreflang,
),
)
.toList(growable: false);

/// All links with `rel` matching `data` or
/// `http://www.opengis.net/def/rel/ogc/1.0/data`.
Expand All @@ -226,13 +234,15 @@ class Links with EquatableMixin {
///
/// Optional [type] and [hreflang] params can specify links more precisely.
Iterable<Link> data({String? type, String? hreflang}) =>
byRel('data', type: type, hreflang: hreflang).followedBy(
byRel(
'http://www.opengis.net/def/rel/ogc/1.0/data',
type: type,
hreflang: hreflang,
),
);
_byRelInternal('data', type: type, hreflang: hreflang)
.followedBy(
_byRelInternal(
'http://www.opengis.net/def/rel/ogc/1.0/data',
type: type,
hreflang: hreflang,
),
)
.toList(growable: false);

/// All links with `rel` matching
/// `http://www.opengis.net/def/rel/ogc/1.0/data-meta`.
Expand Down

0 comments on commit cbfce87

Please sign in to comment.