Skip to content

pankajtripathi/TypescriptCollectionsAPI

Repository files navigation

Typescript Collection

Collection API in typescript following Java’s collection framework. Fully unit tested with test coverage.

github page

Table of Contents

Usage

  • For using in your project,

npm install typescript-collection

  • For contributing,

npm install

npm run test

npm run test-coverage

 

Following are the interfaces, classes along with their methods provided in the current API.

 

Collection

  • This is the basic interface containing the generic methods.
  • Parent interface of this API

Method Name

Return

Description

add(e:E)

Boolean

returns true if map contains the supplied key, K.

clear()

Boolean

clears the set and returns true is succeeds else returns false

contains(e:E)

Boolean

returns true is set contains e

isEmpty()

Boolean

returns true if set is empty

remove(e:E)

Boolean

removes object e from collection

size()

number

returns the size of the collection

toArray()

Array<E>

returns an array containing the collection

forEach(func)

function

Executes the supplied function on every element of the collection

filter(func)

function

filters map based on Boolean outcome of passed function

 

List

  • This interface extends collection interface
  • It represents collection of elements in sequential order

Following are some of the implementations of this interface.

LinkedList

  • This collection stores data in a list fashion.
  • Useful for random insertions, deletions is to be performed on list

Set

  • Another sub interface of collection
  • Models mathematical set abstraction
  • Unique values are stored

 

Following are some of the implementations of this interface.

HashSet

  • Stores data based on the hash generated from it.
  • It uses MD5 algorithm to calculate hash of the data.

Map

  • Map is collection of key, value pairs
  • Unlike other collections ,this is a collection of pairs
  • Stores unique keys, although values can be duplicate

Following are the methods provided by this interface,

Method Name

Return

Description

put(key:K,value:V)

value:V

Inserts value v, with key k and returns the stored value

clear()

Boolean

Clears map collection, returns true if succeeds in doing so else false

containsKey(key:K)

boolean

returns true if map contains the supplied key, K.

containsValue(value:V)

boolean

returns true if map contains the supplied value, V

isEmpty()

boolean

returns true if map is empty

size()

number

returns the number of entries in map

get(key:K)

value:V

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

forEach(func)

function

performs the supplied function on each entry

Filter(func)

function

filters map based on Boolean outcome of passed function

 

Treemap

  • Concrete implementation of map interface.
  • Stores data in binary search tree form

 

 

About

Implementing Collections for Angularjs

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •