list method

List<ComponentEntry> list([
  1. ComponentQuery q = const ComponentQuery()
])

Liệt kê theo thứ tự add (addedAt, rồi seq).

Implementation

List<ComponentEntry> list([ComponentQuery q = const ComponentQuery()]) {
  Iterable<String> ids;
  if (q.stopOf != null) {
    ids = byOwner[q.stopOf]?.stops ?? const {};
  } else if (q.alongOf != null) {
    ids = byOwner[q.alongOf]?.along ?? const {};
  } else if (q.planOf != null) {
    ids = byPlan[q.planOf] ?? const {};
  } else if (q.tag != null) {
    ids = byTag[q.tag] ?? const {};
  } else if (q.type != null) {
    ids = byType[q.type] ?? const {};
  } else if (q.origin != null) {
    ids = byOrigin[q.origin] ?? const {};
  } else {
    ids = byId.keys;
  }
  final out = <ComponentEntry>[];
  for (final id in ids) {
    final e = byId[id];
    if (e == null) continue;
    if (q.type != null && e.type != q.type) continue;
    if (q.origin != null && e.origin != q.origin) continue;
    if (q.tag != null && !e.tags.contains(q.tag)) continue;
    if (q.tags != null && !q.tags!.every(e.tags.contains)) continue;
    if (q.visible != null && e.state.visible != q.visible) continue;
    if (q.bbox != null) {
      // Kế hoạch: khung bao hợp của mọi route nó sở hữu (14.4).
      final bb = e.type == 'trip-plan' ? planBounds(e.id) : null;
      final inside = e.type == 'trip-plan'
          ? bb != null && boundsIntersect(bb, q.bbox!)
          : _inBounds(e, q.bbox!);
      if (!inside) continue;
    }
    out.add(e);
  }
  out.sort((a, b) {
    final c = a.addedAt.compareTo(b.addedAt);
    return c != 0 ? c : a.seq.compareTo(b.seq);
  });
  return out;
}