{"id":18886202,"url":"https://github.com/lieutenantpeacock/javacollections4js","last_synced_at":"2026-02-23T13:30:18.413Z","repository":{"id":65281296,"uuid":"383629043","full_name":"LieutenantPeacock/JavaCollections4JS","owner":"LieutenantPeacock","description":"Implementations of some commonly-used Java collections in JavaScript.","archived":false,"fork":false,"pushed_at":"2023-01-14T03:24:37.000Z","size":50,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-01T11:15:58.343Z","etag":null,"topics":["arraylist","collections","hashmap","hashset","javascript"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LieutenantPeacock.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-07-07T00:18:41.000Z","updated_at":"2024-10-13T06:25:04.000Z","dependencies_parsed_at":"2023-01-16T05:45:37.319Z","dependency_job_id":null,"html_url":"https://github.com/LieutenantPeacock/JavaCollections4JS","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LieutenantPeacock%2FJavaCollections4JS","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LieutenantPeacock%2FJavaCollections4JS/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LieutenantPeacock%2FJavaCollections4JS/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LieutenantPeacock%2FJavaCollections4JS/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LieutenantPeacock","download_url":"https://codeload.github.com/LieutenantPeacock/JavaCollections4JS/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239859527,"owners_count":19708861,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["arraylist","collections","hashmap","hashset","javascript"],"created_at":"2024-11-08T07:25:43.704Z","updated_at":"2026-02-23T13:30:18.350Z","avatar_url":"https://github.com/LieutenantPeacock.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Java Collections For JavaScript\r\n\r\n[![NPM Version](https://img.shields.io/npm/v/java-collections4js.svg?style=flat-square)](https://www.npmjs.com/package/java-collections4js)\r\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg?style=flat-square)](LICENSE.txt)\r\n\r\nThis repository contains implementations of some commonly-used Java collections in JavaScript.\r\n\r\n## HashMap\r\nAlthough JavaScript has a native \u003ccode\u003eMap\u003c/code\u003e object, key equality is determined by the \u003ccode\u003esameValueZero\u003c/code\u003e algorithm, so objects with the exact same properties are not considered equal unless they are the same reference (\u003ccode\u003e{a: 1, b: 2} !== {a: 1, b: 2}\u003c/code\u003e). This cannot be customized. \u003cbr\u003e\r\n[HashMap.js](src/HashMap.js) provides fine-grained control over what objects are considered equal, so both primitives and user-defined objects may be used as keys.\r\nIt implements a [Hash Table/Map](https://en.wikipedia.org/wiki/Hash_table) with similar methods to [Java's HashMap](https://docs.oracle.com/javase/8/docs/api/java/util/HashMap.html). \r\nAll objects (except primitives) used as keys must implement a \u003ccode\u003ehashCode\u003c/code\u003e method to return an integer hash code as well as an \u003ccode\u003eequals\u003c/code\u003e method that accepts another object as a parameter and returns whether or not the value of the current object is equal to parameter. Objects that are considered equal must have the same hash code, but the converse is not true. \u003cbr\u003e\r\nNote that \u003ccode\u003eHashMap\u003c/code\u003e instances are iterable, so \u003ccode\u003e[...myHashMap]\u003c/code\u003e will return an array of arrays, where each inner array consists of the key and value for a mapping (in that order). \u003cbr\u003e\r\nAn example of usage can be found [here](examples/HashMapExample.html).\r\n\r\n### Usage\r\nInclude the script before code that uses \u003ccode\u003eHashMap\u003c/code\u003e. The script can be loaded via CDN or a local downloaded copy.\r\n\r\n```html\r\n\u003cscript src=\"https://cdn.jsdelivr.net/npm/java-collections4js@1.4.2\"\u003e\u003c/script\u003e\r\n\u003c!-- old version --\u003e\r\n\u003cscript src=\"https://cdn.jsdelivr.net/gh/LieutenantPeacock/JavaCollections4JS@1.3.0/src/HashMap.js\" integrity=\"sha384-AD+fe06BloScT8iK5vgKw2FW3imLYjVLP6P9OS+zKpI8vIaNrBTKnQ4TCa4poj2F\" crossorigin=\"anonymous\"\u003e\u003c/script\u003e\r\n```\r\n\r\nOr for Node.js, run `npm i java-collections4js` to install the package, then use it like so:\r\n\r\n```js\r\nconst { HashMap } = require(\"java-collections4js\");\r\n\r\n// or with ECMAScript Module imports\r\nimport JavaCollections from \"java-collections4js\"; // use JavaCollections.HashMap\r\nimport HashMap from \"java-collections4js/dist/HashMap.js\";\r\n```\r\n\r\n### Constructor\r\n\r\nThe constructor accepts an optional \u003ccode\u003eHashMap\u003c/code\u003e, which will copy the contents. Alternately, it will create an empty \u003ccode\u003eHashMap\u003c/code\u003e.\r\n\r\n```js\r\nconst myMap = new HashMap(); // create empty HashMap\r\nconst myMap2 = new HashMap(myMap); // create HashMap from other HashMap\r\n```\r\n\r\n### Instance Methods\r\n\r\n\u003ctable\u003e\r\n\t\u003ctr\u003e\u003cth\u003eMethod Signature\u003c/th\u003e\u003cth\u003eDescription\u003c/th\u003e\u003c/tr\u003e\r\n\t\u003ctr\u003e\r\n\t\t\u003ctd\u003e\u003ccode\u003eput(key, value)\u003c/code\u003e\u003c/td\u003e\u003ctd\u003eAssociates the given \u003ccode\u003ekey\u003c/code\u003e with the \u003ccode\u003evalue\u003c/code\u003e. Returns the previous value associated with the key, or \u003ccode\u003eundefined\u003c/code\u003e if there was no value before.\u003c/td\u003e\r\n\t\u003c/tr\u003e\r\n\t\u003ctr\u003e\r\n\t\t\u003ctd\u003e\u003ccode\u003eputIfAbsent(key, value)\u003c/code\u003e\u003c/td\u003e\u003ctd\u003eAssociates the given \u003ccode\u003ekey\u003c/code\u003e with the \u003ccode\u003evalue\u003c/code\u003e only if there was no value previously associated with the key.\u003c/td\u003e\r\n\t\u003c/tr\u003e\r\n\t\u003ctr\u003e\r\n\t\t\u003ctd\u003e\u003ccode\u003eget(key)\u003c/code\u003e\u003c/td\u003e\u003ctd\u003eReturns the value associated with the given \u003ccode\u003ekey\u003c/code\u003e or \u003ccode\u003eundefined\u003c/code\u003e if there was no value.\u003c/td\u003e\r\n\t\u003c/tr\u003e\r\n\t\u003ctr\u003e\r\n\t\t\u003ctd\u003e\u003ccode\u003egetOrDefault(key, defaultValue)\u003c/code\u003e\u003c/td\u003e\u003ctd\u003eReturns the value associated with the given \u003ccode\u003ekey\u003c/code\u003e if there is one or \u003ccode\u003edefaultValue\u003c/code\u003e if not.\u003c/td\u003e\r\n\t\u003c/tr\u003e\r\n\t\u003ctr\u003e\r\n\t\t\u003ctd\u003e\u003ccode\u003econtainsKey(key)\u003c/code\u003e\u003c/td\u003e\u003ctd\u003eReturns \u003ccode\u003etrue\u003c/code\u003e if the \u003ccode\u003eHashMap\u003c/code\u003e contains a mapping for the given \u003ccode\u003ekey\u003c/code\u003e.\u003c/td\u003e\r\n\t\u003c/tr\u003e\r\n\t\u003ctr\u003e\r\n\t\t\u003ctd\u003e\u003ccode\u003econtainsValue(value)\u003c/code\u003e\u003c/td\u003e\u003ctd\u003eReturns \u003ccode\u003etrue\u003c/code\u003e if there is at least one key mapped to the given \u003ccode\u003evalue\u003c/code\u003e.\u003c/td\u003e\r\n\t\u003c/tr\u003e\r\n\t\u003ctr\u003e\r\n\t\t\u003ctd\u003e\u003ccode\u003eclear()\u003c/code\u003e\u003c/td\u003e\u003ctd\u003eRemoves all mappings in the \u003ccode\u003eHashMap\u003c/code\u003e.\u003c/td\u003e\r\n\t\u003c/tr\u003e\r\n\t\u003ctr\u003e\r\n\t\t\u003ctd\u003e\u003ccode\u003eremove(key)\u003c/code\u003e\u003c/td\u003e\u003ctd\u003eRemoves the mapping for the given \u003ccode\u003ekey\u003c/code\u003e and returns its value.\u003c/td\u003e\r\n\t\u003c/tr\u003e\r\n\t\u003ctr\u003e\r\n\t\t\u003ctd\u003e\u003ccode\u003eforEach(consumer)\u003c/code\u003e\u003c/td\u003e\u003ctd\u003eIterates over each key-value mapping in the \u003ccode\u003eHashMap\u003c/code\u003e and passes the key and value of each one as arguments to the \u003ccode\u003econsumer\u003c/code\u003e callback function.\u003c/td\u003e\r\n\t\u003c/tr\u003e\r\n\t\u003ctr\u003e\r\n\t\t\u003ctd\u003e\u003ccode\u003eisEmpty()\u003c/code\u003e\u003c/td\u003e\u003ctd\u003eReturns \u003ccode\u003etrue\u003c/code\u003e if there are no mappings in the \u003ccode\u003eHashMap\u003c/code\u003e\u003c/td\u003e\r\n\t\u003c/tr\u003e\r\n\t\u003ctr\u003e\r\n\t\t\u003ctd\u003e\u003ccode\u003esize()\u003c/code\u003e\u003c/td\u003e\u003ctd\u003eReturns the number of mappings in the \u003ccode\u003eHashMap\u003c/code\u003e.\u003c/td\u003e\r\n\t\u003c/tr\u003e\r\n\t\u003ctr\u003e\r\n\t\t\u003ctd\u003e\u003ccode\u003ehashCode()\u003c/code\u003e\u003c/td\u003e\u003ctd\u003eReturns an integer hash code for this instance.\u003c/td\u003e\r\n\t\u003c/tr\u003e\r\n\t\u003ctr\u003e\r\n\t\t\u003ctd\u003e\u003ccode\u003eequals(obj)\u003c/code\u003e\u003c/td\u003e\u003ctd\u003eReturns \u003ccode\u003etrue\u003c/code\u003e if the value of \u003ccode\u003eobj\u003c/code\u003e is equal to the value of this instance.\u003c/td\u003e\r\n\t\u003c/tr\u003e\r\n\u003c/table\u003e\r\n\r\n## HashSet\r\nAlthough JavaScript has a native \u003ccode\u003eSet\u003c/code\u003e object, elements are considered equal only if they are primitives with the same value or the same reference of an object. Thus, objects with the same properties and values can be duplicated many times. \u003cbr\u003e\r\n[HashSet.js](src/HashSet.js) provides fine-grained control over what objects are considered equal, so both primitives and user-defined objects may be inserted with uniqueness guaranteed.\r\nIt implements an unordered collection with unique elements. Similar to \u003ccode\u003eHashMap\u003c/code\u003e, each element (except primitives) stored in a \u003ccode\u003eHashSet\u003c/code\u003e must implement a \u003ccode\u003ehashCode\u003c/code\u003e and \u003ccode\u003eequals\u003c/code\u003e method. To use \u003ccode\u003eHashSet\u003c/code\u003e, \u003ccode\u003eHashMap\u003c/code\u003e must be included first. \u003cbr\u003e\r\nNote that \u003ccode\u003eHashSet\u003c/code\u003e instances are iterable, so \u003ccode\u003e[...myHashSet]\u003c/code\u003e will return an array containing the elements in the \u003ccode\u003eHashSet\u003c/code\u003e.\r\n\r\n### Usage\r\nInclude HashMap.js and HashSet.js before code that uses \u003ccode\u003eHashSet\u003c/code\u003e. The scripts can be loaded via CDN or local downloaded copies.\r\n\r\n```html\r\n\u003cscript src=\"https://cdn.jsdelivr.net/gh/LieutenantPeacock/JavaCollections4JS@1.3.0/src/HashMap.js\" integrity=\"sha384-AD+fe06BloScT8iK5vgKw2FW3imLYjVLP6P9OS+zKpI8vIaNrBTKnQ4TCa4poj2F\" crossorigin=\"anonymous\"\u003e\u003c/script\u003e\r\n\u003cscript src=\"https://cdn.jsdelivr.net/gh/LieutenantPeacock/JavaCollections4JS@1.3.0/src/HashSet.js\" integrity=\"sha384-eEGZyLlAVNsmA+/PWbSLgZR1wO9z2AWkHyVtLzr1vCenlCZ2wb9wLxNKY7Ib5lK5\" crossorigin=\"anonymous\"\u003e\u003c/script\u003e\r\n```\r\n\r\n### Constructor\r\nThe constructor accepts an optional iterable object, all elements of which will be initially added to the \u003ccode\u003eHashSet\u003c/code\u003e. If the first parameter is not provided, it constructs an empty \u003ccode\u003eHashSet\u003c/code\u003e.\r\n\r\n```js\r\nconst mySet = new HashSet(); // creates empty HashSet\r\nconst mySet2 = new HashSet([1, 2, 3]); // creates a HashSet containing the elements of the array\r\n```\r\n\r\n### Instance methods\r\n\r\n\u003ctable\u003e\r\n\t\u003ctr\u003e\u003cth\u003eMethod Signature\u003c/th\u003e\u003cth\u003eDescription\u003c/th\u003e\u003c/tr\u003e\r\n\t\u003ctr\u003e\u003ctd\u003e\u003ccode\u003eadd(obj)\u003c/code\u003e\u003c/td\u003e\u003ctd\u003eAdds \u003ccode\u003eobj\u003c/code\u003e to the \u003ccode\u003eHashSet\u003c/code\u003e, if it is not already present. Returns \u003ccode\u003etrue\u003c/code\u003e if the object was added, i.e. it was not already present.\u003c/td\u003e\u003c/tr\u003e\r\n\t\u003ctr\u003e\r\n\t\t\u003ctd\u003e\u003ccode\u003econtains(obj)\u003c/code\u003e\u003c/td\u003e\r\n\t\t\u003ctd\u003eReturns \u003ccode\u003etrue\u003c/code\u003e if the \u003ccode\u003eHashSet\u003c/code\u003e contains \u003ccode\u003eobj\u003c/code\u003e.\u003c/td\u003e\r\n\t\u003c/tr\u003e\r\n\t\u003ctr\u003e\r\n\t\t\u003ctd\u003e\u003ccode\u003eremove(obj)\u003c/code\u003e\u003c/td\u003e\u003ctd\u003eRemoves \u003ccode\u003eobj\u003c/code\u003e from the \u003ccode\u003eHashSet\u003c/code\u003e.\u003c/td\u003e\r\n\t\u003c/tr\u003e\r\n\t\u003ctr\u003e\r\n\t\t\u003ctd\u003e\u003ccode\u003eclear()\u003c/code\u003e\u003c/td\u003e\u003ctd\u003eRemoves all elements from the \u003ccode\u003eHashSet\u003c/code\u003e.\u003c/td\u003e\r\n\t\u003c/tr\u003e\r\n\t\u003ctr\u003e\r\n\t\t\u003ctd\u003e\u003ccode\u003esize()\u003c/code\u003e\u003c/td\u003e\u003ctd\u003eReturns the number of elements in the \u003ccode\u003eHashSet\u003c/code\u003e.\u003c/td\u003e\r\n\t\u003c/tr\u003e\r\n\t\u003ctr\u003e\r\n\t\t\u003ctd\u003e\u003ccode\u003eisEmpty()\u003c/code\u003e\u003c/td\u003e\u003ctd\u003eReturns \u003ccode\u003etrue\u003c/code\u003e if there are no elements in the \u003ccode\u003eHashSet\u003c/code\u003e\u003c/td\u003e\r\n\t\u003c/tr\u003e\r\n\t\u003ctr\u003e\r\n\t\t\u003ctd\u003e\u003ccode\u003ehashCode()\u003c/code\u003e\u003c/td\u003e\u003ctd\u003eReturns an integer hash code for this instance.\u003c/td\u003e\r\n\t\u003c/tr\u003e\r\n\t\u003ctr\u003e\r\n\t\t\u003ctd\u003e\u003ccode\u003eequals(obj)\u003c/code\u003e\u003c/td\u003e\u003ctd\u003eReturns \u003ccode\u003etrue\u003c/code\u003e if the value of \u003ccode\u003eobj\u003c/code\u003e is equal to the value of this instance.\u003c/td\u003e\r\n\t\u003c/tr\u003e\r\n\u003c/table\u003e\r\n\r\n## ArrayList\r\n\r\n[ArrayList.js](src/ArrayList.js) implements an dynamically-sized list with a \u003ccode\u003ehashCode\u003c/code\u003e and \u003ccode\u003eequals\u003c/code\u003e method. \u003cbr\u003e\r\nNote that \u003ccode\u003eArrayList\u003c/code\u003e instances are iterable, so \u003ccode\u003e[...myArrayList]\u003c/code\u003e will return an array containing the elements in the \u003ccode\u003eArrayList\u003c/code\u003e (in order).\r\n\r\n### Usage\r\nInclude the script before code that uses \u003ccode\u003eArrayList\u003c/code\u003e. The script can be loaded via CDN or a local downloaded copy.\r\n\r\n```html\r\n\u003cscript src=\"https://cdn.jsdelivr.net/gh/LieutenantPeacock/JavaCollections4JS@1.3.0/src/ArrayList.js\" integrity=\"sha384-Uz+oGp/Q3Lfeq6ESB4bvbOAHw0hF1RjSBPHQqjpikrVrFjF6SDx6JMV9rI3mBBFr\" crossorigin=\"anonymous\"\u003e\u003c/script\u003e\r\n```\r\n\r\n### Constructor\r\nThe constructor accepts an optional iterable object to use to fill the list initially. If not specified, an empty \u003ccode\u003eArrayList\u003c/code\u003e is constructed.\r\n\r\n```js\r\nconst myList = new ArrayList(); // creates an empty ArrayList\r\nconst myList2 = new ArrayList([1, 2, 3]); // creates an ArrayList containing the numbers 1, 2, 3\r\n```\r\n\r\n### Instance Methods\r\n\u003ctable\u003e\r\n\t\u003ctr\u003e\r\n\t\t\u003cth\u003eMethod Signature\u003c/th\u003e\u003cth\u003eDescription\u003c/th\u003e\r\n\t\u003c/tr\u003e\r\n\t\u003ctr\u003e\r\n\t\t\u003ctd\u003e\u003ccode\u003eadd(...elems)\u003c/code\u003e\u003c/td\u003e\u003ctd\u003eAdds all of the arguments passed in to the \u003ccode\u003eArrayList\u003c/code\u003e.\u003c/td\u003e\r\n\t\u003c/tr\u003e\r\n\t\u003ctr\u003e\r\n\t\t\u003ctd\u003e\u003ccode\u003eaddAll(obj)\u003c/code\u003e\u003c/td\u003e\u003ctd\u003eAdds all the elements of the iterable \u003ccode\u003eobj\u003c/code\u003e to the \u003ccode\u003eArrayList\u003c/code\u003e.\u003c/td\u003e\r\n\t\u003c/tr\u003e\r\n\t\u003ctr\u003e\r\n\t\t\u003ctd\u003e\u003ccode\u003eremoveAtIndex(idx)\u003c/code\u003e\u003c/td\u003e\u003ctd\u003eRemoves the element at the specified index.\u003c/td\u003e\r\n\t\u003c/tr\u003e\r\n\t\u003ctr\u003e\r\n\t\t\u003ctd\u003e\u003ccode\u003eget(idx)\u003c/code\u003e\u003c/td\u003e\u003ctd\u003eReturns the element at the specified index.\u003c/td\u003e\r\n\t\u003c/tr\u003e\r\n\t\u003ctr\u003e\r\n\t\t\u003ctd\u003e\u003ccode\u003eaddAtIndex(idx, ...elems)\u003c/code\u003e\u003c/td\u003e\r\n\t\t\u003ctd\u003eAdds the given elements to the \u003ccode\u003eArrayList\u003c/code\u003e starting at the specified index.\u003c/td\u003e\r\n\t\u003c/tr\u003e\r\n\t\u003ctr\u003e\r\n\t\t\u003ctd\u003e\u003ccode\u003eset(idx, elem)\u003c/code\u003e\u003c/td\u003e\u003ctd\u003eSets the element at the specified index to be \u003ccode\u003eelem\u003c/code\u003e.\u003c/td\u003e\r\n\t\u003c/tr\u003e\r\n\t\u003ctr\u003e\r\n\t\t\u003ctd\u003e\u003ccode\u003eremoveIf(predicate)\u003c/code\u003e\u003c/td\u003e\r\n\t\t\u003ctd\u003eRemoves all elements in the \u003ccode\u003eArrayList\u003c/code\u003e that match a predicate (that accepts an element as the only parameter and returns \u003ccode\u003etrue\u003c/code\u003e if it should be removed).\u003c/td\u003e\r\n\t\u003c/tr\u003e\r\n\t\u003ctr\u003e\r\n\t\t\u003ctd\u003e\u003ccode\u003eremove(obj)\u003c/code\u003e\u003c/td\u003e\r\n\t\t\u003ctd\u003eRemoves the first occurrence of \u003ccode\u003eobj\u003c/code\u003e from the \u003ccode\u003eArrayList\u003c/code\u003e.\u003c/td\u003e\r\n\t\u003c/tr\u003e\r\n\t\u003ctr\u003e\r\n\t\t\u003ctd\u003e\u003ccode\u003eindexOf(obj)\u003c/code\u003e\u003c/td\u003e\r\n\t\t\u003ctd\u003eReturns the first index at which \u003ccode\u003eobj\u003c/code\u003e is found in the \u003ccode\u003eArrayList\u003c/code\u003e.\u003c/td\u003e\r\n\t\u003c/tr\u003e\r\n\t\u003ctr\u003e\r\n\t\t\u003ctd\u003e\u003ccode\u003esize()\u003c/code\u003e\u003c/td\u003e\r\n\t\t\u003ctd\u003eReturns the number of elements in the \u003ccode\u003eArrayList\u003c/code\u003e.\u003c/td\u003e\r\n\t\u003c/tr\u003e\r\n\t\u003ctr\u003e\r\n\t\t\u003ctd\u003e\u003ccode\u003eisEmpty()\u003c/code\u003e\u003c/td\u003e\r\n\t\t\u003ctd\u003eReturns \u003ccode\u003etrue\u003c/code\u003e if there are no elements in the \u003ccode\u003eArrayList\u003c/code\u003e.\u003c/td\u003e\r\n\t\u003c/tr\u003e\r\n\t\u003ctr\u003e\r\n\t\t\u003ctd\u003e\u003ccode\u003ehashCode()\u003c/code\u003e\u003c/td\u003e\u003ctd\u003eReturns an integer hash code for this instance.\u003c/td\u003e\r\n\t\u003c/tr\u003e\r\n\t\u003ctr\u003e\r\n\t\t\u003ctd\u003e\u003ccode\u003eequals(obj)\u003c/code\u003e\u003c/td\u003e\u003ctd\u003eReturns \u003ccode\u003etrue\u003c/code\u003e if the value of \u003ccode\u003eobj\u003c/code\u003e is equal to the value of this instance.\u003c/td\u003e\r\n\t\u003c/tr\u003e\r\n\u003c/table\u003e\r\n\r\n## Equals and HashCode for Objects You Cannot Modify\r\n\r\n[HashedObject.js](src/HashedObject.js) provides a wrapper for an object that allows specifying an \u003ccode\u003eequals\u003c/code\u003e and \u003ccode\u003ehashCode\u003c/code\u003e function. This wrapped object can then be used as a key in a \u003ccode\u003eHashMap\u003c/code\u003e or stored \r\nin a \u003ccode\u003eHashSet\u003c/code\u003e.\u003cbr\u003e\r\n\r\n### Usage\r\nInclude the script before code that uses \u003ccode\u003eHashedObject\u003c/code\u003e. The script can be loaded via CDN or a local downloaded copy.\r\n\r\n```html\r\n\u003cscript src=\"https://cdn.jsdelivr.net/gh/LieutenantPeacock/JavaCollections4JS@1.3.0/src/HashedObject.js\" integrity=\"sha384-RBqyEB5bCB2ci4e3ZKiBp4W87K7LYay1qXMFO/9cUq7TndRlQKLSZ4/iFN1bMbRl\" crossorigin=\"anonymous\"\u003e\u003c/script\u003e\r\n```\r\n\r\n### Constructor\r\nThe constructor takes the object to wrap, the hash function, and the equals function as arguments. \u003cbr\u003e\r\nThe \u003ccode\u003eequals\u003c/code\u003e function must take two objects as parameters and return a boolean indicating whether they are equal. If not equals function is specified, the default is strict equality comparison.\u003cbr\u003e\r\nThe \u003ccode\u003ehashCode\u003c/code\u003e function must take one object as input and return its hash code.\r\n\r\n```js\r\nlet wrapped = new HashedObject(myObj, hashFn, equalsFn);\r\n```\r\n\r\n### Instance Methods\r\n\r\n\u003ctable\u003e\r\n\t\u003ctr\u003e\u003cth\u003eMethod Signature\u003c/th\u003e\u003cth\u003eDescription\u003c/th\u003e\u003c/tr\u003e\r\n\t\u003ctr\u003e\r\n\t\t\u003ctd\u003e\u003ccode\u003ehashCode()\u003c/code\u003e\u003c/td\u003e\u003ctd\u003eReturns the hash code of the wrapped object obtained with the hashCode function passed in through the constructor.\u003c/td\u003e\r\n\t\u003c/tr\u003e\r\n\t\u003ctr\u003e\r\n\t\t\u003ctd\u003e\u003ccode\u003eequals(obj)\u003c/code\u003e\u003c/td\u003e\u003ctd\u003eReturns the result of calling the equals function provided in the constructor, passing the underlying object and \u003ccode\u003eobj\u003c/code\u003e as arguments.\u003c/td\u003e\r\n\t\u003c/tr\u003e\r\n\t\u003ctr\u003e\r\n\t\t\u003ctd\u003e\u003ccode\u003egetValue()\u003c/code\u003e\u003c/td\u003e\u003ctd\u003eReturns the underlying object that was wrapped.\u003c/td\u003e\r\n\t\u003c/tr\u003e\r\n\u003c/table\u003e\r\n\r\n### Static Methods and Properties\r\n\r\nThere are some static methods and properties provided for convenience that implement common equals or hash code functions.\r\n\r\n\u003ctable\u003e\r\n\t\u003ctr\u003e\u003cth\u003eName\u003c/th\u003e\u003cth\u003eDescription\u003c/th\u003e\u003c/tr\u003e\r\n\t\u003ctr\u003e\r\n\t\t\u003ctd\u003e\u003ccode\u003eDEFAULT_EQUALS\u003c/code\u003e\u003c/td\u003e\u003ctd\u003eA function implementing an equals function using strict equality.\u003c/td\u003e\r\n\t\u003c/tr\u003e\r\n\t\u003ctr\u003e\r\n\t\t\u003ctd\u003e\u003ccode\u003eITERABLE_HASHCODE\u003c/code\u003e\u003c/td\u003e\u003ctd\u003eA function implementing a hash code function for an iterable object.\u003c/td\u003e\r\n\t\u003c/tr\u003e\r\n\t\u003ctr\u003e\r\n\t\t\u003ctd\u003e\u003ccode\u003eSTRING_HASHCODE\u003c/code\u003e\u003c/td\u003e\u003ctd\u003eA function implementing a hash code function for a string.\u003c/td\u003e\r\n\t\u003c/tr\u003e\r\n\t\u003ctr\u003e\r\n\t\t\u003ctd\u003e\u003ccode\u003eITERABLE_EQUALS\u003c/code\u003e\u003c/td\u003e\u003ctd\u003eA function implementing an equals function for iterable objects by comparing elements at corresponding indexes.\u003c/td\u003e\r\n\t\u003c/tr\u003e\r\n\t\u003ctr\u003e\r\n\t\t\u003ctd\u003e\u003ccode\u003efactory(hashCodeFn, equalsFn)\u003c/code\u003e\u003c/td\u003e\u003ctd\u003eReturns a factory function from the given hash code and equals functions. The factory function accepts a single object parameter and returns a \u003ccode\u003eHashedObject\u003c/code\u003e from the parameter and the hash code and equals functions (provided when creating the factory).\u003c/td\u003e\r\n\t\u003c/tr\u003e\r\n\u003c/table\u003e\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flieutenantpeacock%2Fjavacollections4js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flieutenantpeacock%2Fjavacollections4js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flieutenantpeacock%2Fjavacollections4js/lists"}