mixed_collection 0.1.5

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 70

mixed_collection #

A sortable, filterable collection, which can be clubbed with configurable filter and/or sorters to enable sorting or filtering support.

The main features of this custom data structure is listed below.

  • Support multiple filters.
  • Filters can be added on the fly.
  • Filters can be filter callbacks or configurations.
  • Filters can be cached.
  • Supports multiple sorters.
  • Sorters can be activated/deactivated by name/callback.
  • Sorters can be comparators or configurations.
  • APIs to manipulate sort and filter logic.
  • Iterators and multiple helper functions.
  • Simple interface for the data model for the collection.
  • Supports multiple mixins, which can be used in third party applications.

Example usage.

bool filterByNameStartsWith(dynamic entry, dynamic data) {
  if (null != entry && null != data) {
    return (entry.getValue('') as String).startsWith(data);
  }

  return false;
}

bool containsFilter(dynamic entry, dynamic data) {
  if (null != entry && null != data) {
    return (entry.getValue('') as String).contains(data);
  }

  return false;
}

int sortByStringAsc(dynamic a, dynamic b) {
  if (a == null) return -1;
  if (b == null) return 0;
  return a.toString().compareTo(b.toString());
}

int sortByStringdesc(dynamic a, dynamic b) {
  if (a == null) return -1;
  if (b == 1) return 0;
  return b.toString().compareTo(a.toString());
}

void main() {
  var items = ["John", "Harry", "Albert", "Paul", "Emilie", "Frank"];

  Collection collection = new Collection();
  var entries = items.map((item) => new StringCollectionEntry(item)).toList();
  collection.load(entries, (res, err) {
    print(collection.count);
  });

  collection.filter(filterByNameStartsWith, true, true, "A");
  assert(collection.records.length == 1);

  collection.clearFilters();
  collection.filter(containsFilter, true, true, "rr");
  assert(collection.records.length == 1);
  var filters = [
    {"callback": filterByNameStartsWith, "value": "A"},
    {"callback": containsFilter, "value": "er"}
  ];

  // Perform this operation if you have filtered the collection already.
  collection.suspendFilter();
  collection.clearFilters();

  // Add the new filter to the collection.
  // This is one way you can change filtering at run time.
  collection.filters.addAll(filters);

  // Let collection resume filtering. A next call to filter API will perfrom filtering.
  collection.resumeFilters();
  collection.filter();
  assert(collection.records.length == 1);

// Remove all filters.
  collection.clearFilters();

  print("Actual Collection");
  collection.records.forEach((f) => print(f.item));

  print("Sort By Ascending");
  collection.sort(sortByStringAsc);
  collection.records.forEach((f) => print(f.item));

  collection.clearSorters();
  print("Sort By Descending");

  // Sort by using a custom comparer.
  collection.sort(sortByStringdesc);
  collection.records.forEach((f) => print(f.item));

  collection.clearSorters();

  ///
  /// Configuration for sorting.
  ///
  /// The sorting is not stable, which means, the indexes of "equal" elements could be
  /// juggled.
  ///
  ///
  var sorter = {
    "caseSensitive": false,
    "direction": "desc",
    "enabled": true,
    "property": ''
  };

  print("Case insensitive sort - config.");
  collection.sort(sorter);
  collection.records.forEach((f) => print(f.item));
}

0.1.5 #

  • Updated filterable API to consider data passed to the function, if the filter don't have a value field.

0.1.4 #

  • Changed meta version to be compatible with flutter application.

0.1.3 #

  • Formatted readme.

0.1.2 #

  • Updated readme.
  • Addressed suggestions from dart analyzer.

0.1.1 #

  • Added additional APIs. Fixed issues with cached items.

0.1.0 #

  • Code documentation. Provided cached collection for faster repeated retrieval.

0.0.9 #

  • Modified collection entry getValue API not to provide optional argument. An argument need to be passed while calling that API.

0.0.8 #

  • Fixed bugs with sample application, which was performing toString on CollectionEntry.

0.0.7 #

  • Fixed bugs with library code for sorter. Sorter was not taking input value and throwing exception while performing string comparison.

0.0.6 #

  • Fixed bugs with library code for filter.

0.0.5 #

  • Implemented sample application.

0.0.4 #

  • Provided support for collection with filterable, sortable and collection entry.

0.0.3 #

  • Provided support for filterable and sortable.

0.0.2 #

  • Updated library with collection entry

0.0.1 #

First version.

example/example.dart

// Copyright (c) 2019, iMeshAcademy authors.  Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// MIT-style license that can be found in the LICENSE file.

import 'package:mixed_collection/mixed_collection.dart';
import 'stringentry.dart';

bool filterByNameStartsWith(dynamic entry, dynamic data) {
  if (null != entry && null != data) {
    return (entry.getValue('') as String).startsWith(data);
  }

  return false;
}

bool containsFilter(dynamic entry, dynamic data) {
  if (null != entry && null != data) {
    return (entry.getValue('') as String).contains(data);
  }

  return false;
}

int sortByStringAsc(dynamic a, dynamic b) {
  if (a == null) return -1;
  if (b == null) return 0;
  return a.toString().compareTo(b.toString());
}

int sortByStringdesc(dynamic a, dynamic b) {
  if (a == null) return -1;
  if (b == 1) return 0;
  return b.toString().compareTo(a.toString());
}

void main() {
  var items = ["John", "Harry", "Albert", "Paul", "Emilie", "Frank"];

  Collection collection = new Collection();
  var entries = items.map((item) => new StringCollectionEntry(item)).toList();
  collection.load(entries, (res, err) {
    print(collection.count);
  });

  collection.filter(filterByNameStartsWith, true, true, "A");
  assert(collection.records.length == 1);

  collection.clearFilters();
  collection.filter(containsFilter, true, true, "rr");
  assert(collection.records.length == 1);
  var filters = [
    {"callback": filterByNameStartsWith, "value": "A"},
    {"callback": containsFilter, "value": "er"}
  ];

  // Perform this operation if you have filtered the collection already.
  collection.suspendFilter();
  collection.clearFilters();

  // Add the new filter to the collection.
  // This is one way you can change filtering at run time.
  collection.filters.addAll(filters);

  // Let collection resume filtering. A next call to filter API will perfrom filtering.
  collection.resumeFilters();
  collection.filter();
  assert(collection.records.length == 1);

// Remove all filters.
  collection.clearFilters();

  print("Actual Collection");
  collection.records.forEach((f) => print(f.item));

  print("Sort By Ascending");
  collection.sort(sortByStringAsc);
  collection.records.forEach((f) => print(f.item));

  collection.clearSorters();
  print("Sort By Descending");

  // Sort by using a custom comparer.
  collection.sort(sortByStringdesc);
  collection.records.forEach((f) => print(f.item));

  collection.clearSorters();

  ///
  /// Configuration for sorting.
  ///
  /// The sorting is not stable, which means, the indexes of "equal" elements could be
  /// juggled.
  ///
  ///
  var sorter = {
    "caseSensitive": false,
    "direction": "desc",
    "enabled": true,
    "property": ''
  };

  print("Case insensitive sort - config.");
  collection.sort(sorter);
  collection.records.forEach((f) => print(f.item));
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  mixed_collection: ^0.1.5

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:mixed_collection/mixed_collection.dart';
  
Version Uploaded Documentation Archive
0.1.5 Feb 11, 2019 Go to the documentation of mixed_collection 0.1.5 Download mixed_collection 0.1.5 archive
0.1.4 Feb 11, 2019 Go to the documentation of mixed_collection 0.1.4 Download mixed_collection 0.1.4 archive
0.1.3 Feb 11, 2019 Go to the documentation of mixed_collection 0.1.3 Download mixed_collection 0.1.3 archive
0.1.2 Feb 11, 2019 Go to the documentation of mixed_collection 0.1.2 Download mixed_collection 0.1.2 archive
0.1.1 Feb 11, 2019 Go to the documentation of mixed_collection 0.1.1 Download mixed_collection 0.1.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
41
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
70
Learn more about scoring.

We analyzed this package on Apr 12, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.2.0
  • pana: 0.12.14

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:mixed_collection/mixed_collection.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
eventify >0.1.1 <1.0.0 0.1.4
meta ^1.1.6 1.1.7
Dev dependencies
test ^1.0.0