Code Monkey home page Code Monkey logo

typescriptcollectionsframework's Introduction

"If you know the Java Collections Framework, you know the Typescript Collections Framework. It's the same API (mostly)"

I am working on an upgrade to this library to the newest version of TypeScript. This upgrade will be available to sponsors only and not open source ising the Github sponsorship tools - https://github.blog/2022-02-02-new-sponsors-only-repositories-custom-amounts-and-more/ To get access sponsor this project and you will be added when the sponsor only library is available.

It is designed for and written by Java coders who also needed to do TypeScript programming.

NPM Build Status Code Coverage Code Triage quality badge

Reliability Rating Bugs Code Smells Duplicated Lines (%) Lines of Code Maintainability Rating Quality Gate Status Security Rating Technical Debt Vulnerabilities paypal

TypeScript Collections Framework is a port of the Java Collections framework to TypeScript. It fully supports Generics and native types.

Demo & Tutorial project with Angular 7

Demo: https://larrydiamond.github.io/typescriptcollectionsframework-Demo-For-Angular7/dist/demoapp/

Source: https://github.com/larrydiamond/typescriptcollectionsframework-Demo-For-Angular7

Demo and Tutorial project with Node.js

Demo and Source: https://github.com/larrydiamond/typescriptcollectionsframeworktutorial

Classes documentation

https://larrydiamond.github.io/typescriptcollectionsframework/typedoc/

ArrayList, LinkedList, SkipListSet, TreeSet, PriorityQueue, HashSet, HashMap, SkipListMap, TreeMap are all live and available today.

Collection, List, JSet, JMap, Queue, and Deque interfaces are also available with many others to come soon (or are already here and aren't yet documented :) )

Goals for the next version include a tutorial with code examples in Java and TypeScript

My goals of this project

  • Port over as many of the classes and interfaces I've previously used as a Java developer to TypeScript
  • Support putting "stuff" from other libraries into Collections without having to box and unbox objects.
  • Use the compiler as much as possible to catch issues at compile rather than at run time or at test time.
  • Incorporate some of the classes from Google Guava and Apache Commons Collections to provide more than what the raw Java Collections Framework provides

Class Hierarchy

Class Hierarchy Map Class Hierarchy

Installation instructions

Install typescriptcollectionsframework from npm

npm install typescriptcollectionsframework --save

How to build for development

  • clone repository
  • npm install
  • npm test

Design methodology

The goal of this library is to provide a "as Java Collections" framework as possible so that developers can migrate their existing Java knowledge to TypeScript and be productive quicker. It won't be possible to perfectly recreate the framework since the language is not the same, but the goal is to provide as many of the "normal" classes as possible with as many of the "normal" methods as possible.

Semver was adopted as of version 1.0 of this framework.

In TypeScript all objects do not inherit from Object (which we do not control anyway), so we made added a parameter to the constructors of each class to compare objects and calculate hash codes. As a result, anything can be put into the Collections, even string, number, and classes from other packages. There is no String class to wrap string, no Number class to wrap number, and no Boolean class to wrap boolean. No autoboxing and no autounboxing. Generics are fully supported, as are native JavaScript types.

Ensuring that the Collection classes in this Framework fully supported generic types has been an important motivator for this framework, and we have accomplished this on the existing classes and ensure that all future Collection classes fully support generic types.

Immutability

I am a big proponent of Immutability. Google Guava explains this very well Google Guava Immutable Collections Explained.

Our implementations differ significantly. Collection subclasses ImmutableCollection. Every object created from this framework has an Immutable interface that is safe to pass around confident that the object cannot be changed via the methods exposed by the Immutable interface.

All Sets inherit from ImmutableSet and have an immutableSet method that returns an ImmutableSet. All Maps inherit from ImmutableMap and have an immutableMap method that returns an ImmutableMap. All Lists inherit from ImmutableList and have an immutableList method that returns an ImmutableList.

These interfaces provide immutable versions of the real Collection or Map that you can pass to methods confident that your Collection or Map will not be modified by that method. You can also write a method that takes an Immutable object and let your callers know that you promise not to modify the object you receive.

Thank you for all the support.

The number of NPM downloads has been way higher than I expected. 150 in the first three days, 350 in the first five days, 600 in the first week. That's way way way more interest in what I'm doing than I expected. Thank you! We first released in July of 2017, and by the end of 2017 we had over 10,000 downloads. That's phenomenal for half a year, with no marketing effort or a big company bankrolling the work. We felt there was a huge need, and the community has clearly supported our work, and we thank you.

Please feel free to email me at ldiamond at ldiamond dot com with feature requests. I love to hear from people putting my effort to good use. :)

Demo & Tutorial project with Angular 5

Demo: https://larrydiamond.github.io/typescriptcollectionsframework-Demo-For-Angular5/dist/

Source: https://github.com/larrydiamond/typescriptcollectionsframework-Demo-For-Angular5

Demo & Tutorial project with Angular 4

Demo: https://larrydiamond.github.io/typescriptcollectionsframework-Demo-For-Angular4/dist/

Source: https://github.com/larrydiamond/typescriptcollectionsframework-Demo-For-Angular4

Demo & Tutorial project with Angular 2

Demo: https://larrydiamond.github.io/typescriptcollectionsframework-Demo-For-Angular2/dist/

Source: https://github.com/larrydiamond/typescriptcollectionsframework-Demo-For-Angular2

Author

Larry Diamond https://www.linkedin.com/in/larry-diamond-3964042/ ldiamond at ldiamond dot com Please feel free to contact me for training or with questions

Please volunteer to contribute. All contributors will be listed here and I will of course help you to become recognized as a TypeScript expert so it helps your career :)

Contributors

Frank Giordano (https://github.com/frankgiordano)

Stephen E. Chiang (https://github.com/chiangs)

typescriptcollectionsframework's People

Contributors

chiangs avatar frankgiordano avatar greenkeeper[bot] avatar larrydiamond avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

typescriptcollectionsframework's Issues

The return type of TreeMap should be Iterator<MapEntry<K, V>>

In TreeMap's [Symbol.iterator]:
public [Symbol.iterator] ():Iterator<K> { return this.entrySet[Symbol.iterator](); }

The type of this.entrySet is a function, not an object of ImmutableEntrySetForTreeMap. So I think it should be defined like this:

public [Symbol.iterator]():Iterator<MapEntry<K, V>> { return this.entrySet()[Symbol.iterator](); }

Or there will get a ts(7053) error

CompositeList and CompositeMap

I created a CompositeCollection class, and I'd like to see a CompositeList and a CompositeMap class as well. I'm looking for a contributor to develop these classes

2.0 Goals

  1. Queue and PriorityQueue
  2. SkipListMap and SkipListSet
  3. More documentation and examples

MultiMaps and MultiSets

MultiMaps and MultiSets are the next implementable piece once the core Set and Map implementations are completed

ImmutableMap and ImmutableSet

Okay, this is a new feature and partially a rant.

Have you ever passed in a map or a set or something into a method and when the method is done your map has been messed with and it causes a bug in your application? And you're justing staring incredulously at your screen wondering why somebody felt it necessary to mess with your map just because you passed it to a method? Causing you a bug that you had to hunt down because somebody felt it was okay to unannounced mess with your collection?

Yeah, me too.

Thus the ImmutableSet and ImmutableMap were born. I couldn't add these to the Java collections framework because Set and Map extend them, but now I can :)

Now you can define a method as taking in an ImmutableSet that only shows the read only methods and know confidently that when you call that method your Set or Map will not be cleared out by the method.

Okay, it doesnt solve the problem of somebody changing state on the objects in the Set or Map, but it's an improvement and I'll take it :)

Allergic to Jasmine 3+

For some odd reason, Jasmine 3.x.x causes random test failures. I rolled back the code to 2.9.x and will take a look. I would greatly appreciate the help of some very smart person who would love to become an open source contributor :)

An in-range update of @types/jasmine is breaking the build 🚨

The devDependency @types/jasmine was updated from 3.3.16 to 3.4.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

@types/jasmine is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Version 10 of node.js has been released

Version 10 of Node.js (code name Dubnium) has been released! 🎊

To see what happens to your code in Node.js 10, Greenkeeper has created a branch with the following changes:

  • Added the new Node.js version to your .travis.yml

If you’re interested in upgrading this repo to Node.js 10, you can open a PR with these changes. Please note that this issue is just intended as a friendly reminder and the PR as a possible starting point for getting your code running on Node.js 10.

More information on this issue

Greenkeeper has checked the engines key in any package.json file, the .nvmrc file, and the .travis.yml file, if present.

  • engines was only updated if it defined a single version, not a range.
  • .nvmrc was updated to Node.js 10
  • .travis.yml was only changed if there was a root-level node_js that didn’t already include Node.js 10, such as node or lts/*. In this case, the new version was appended to the list. We didn’t touch job or matrix configurations because these tend to be quite specific and complex, and it’s difficult to infer what the intentions were.

For many simpler .travis.yml configurations, this PR should suffice as-is, but depending on what you’re doing it may require additional work or may not be applicable at all. We’re also aware that you may have good reasons to not update to Node.js 10, which is why this was sent as an issue and not a pull request. Feel free to delete it without comment, I’m a humble robot and won’t feel rejected 🤖


FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Node 10 and Gulp 3 are not friends

If you've got Node 10, you're been made very sad if you try to build this framework - it won't work.

I've never been a great fan of gulp, it works but I never got it building without deploying the tests and putting the test code into the code coverage tool.

Or should I say it worked until I moved to Node 10. Now it makes me sad. Gulp 4 has been in development for 2 years and doesnt appear that it will ever complete.

Please replace the build process with something that works on both macs and pcs and works on node 10. Gulp not required.

Version 5 goals

Priority Queue - done
Ease of Use for the entire framework

Rename Map and Set in advance of ES6

They are defining their own Map and Set classes, so I'm going to rename in advance to prevent problems later.

The ones in this library will become JMap and JSet.

I will also add some of their methods into JMap and JSet so JS & TS developers can use these classes and feel at home too.

Queue and PriorityQueue

A very talented volunteer reached out to me and volunteered to write the Queue interface and the PriorityQueue class.

I've opened this issue to make sure he gets appropriately thanked and very clearly recognized as being a great programmer.

NavigableHashMap & Set

Possibly a version 5 or 6 deliverable.

This class would combine the Navigable features of a SkipListMap/Set with the raw get performance of a HashMap to make a class that the Java Collections Framework never had.

Create a github pages tutorial site

Something that does a good long explanation of what we're all about here with demos for each class and some example code for people to lift.

EvictingQueue

Have you considered porting the EvictingQueue class from Guava?

Improve npm build process to not package test classes to distribution

This is a request for any would be contributors to improve my build process.
It works, but isn't perfect.
It packages the testing code in with the distributions.
As a side effect, my code coverage numbers are off since it's examining test code as well as source code.

Thank you in advance for fixing the build process!

TreeSet add return value is false instead of true...

In TreeSet.ts:

/**

  • Adds the specified element to this set if it is not already present.

  • @param {K} element element to be added to this set

  • @return {boolean} true if this set did not already contain the specified element
    */
    public add (element:K) : boolean {
    const tmp:number = this.datastore.put(element, 1);
    if (tmp === null) {
    return false;
    }

    return true;
    }

“true if this set did not already contain the specified element”

This add() function always returns false when the element is added successfully except when it returns number 1 if the element existed in the map and the older element replaced which means add() function returns true in this case.

What to feed as an argument to TreeMap for custom Classes?

Hi, first of all, I would like to thank you for your great effort to bring together such a nice collection.

However, I am trying to use TreeMap as follows:

public filterMap: TreeMap<FieldDescription, LinkedList<FieldFilter>> = new TreeMap<FieldDescription, LinkedList<FieldFilter>>(???);

but I don't know what to pass in instead of ???

I looked at the demo, since they were both strings, you have passed in: Collections.getStringComparator()

but that gives an error in my case since they are custom classes.

Logo request for the project

This is a great contribution request for a creative person with good graphics skills.

This project needs a logo.

Please add more tests

Okay, I realize that as I write this the framework has 90% code coverage, and I'm asking for contributors to add more unit tests. I realize that most people would be beyond glad with 90% code coverage. This framework is intended to be embedded into many many other projects, and I would appreciate any pull requests that would capture additional conditions not currently tested.

Unfortunately, tests just show that a line of code was tested, they don't prove that the code does what you really wanted it to do in the first place.

Any assistance would be greatly appreciated.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.