javasetmap.ts
Advanced tools
Comparing version 1.1.0 to 1.1.1
@@ -1,7 +0,5 @@ | ||
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
typeof define === 'function' && define.amd ? define(['exports'], factory) : | ||
(factory((global.javasetmap_ts = {}))); | ||
}(this, (function (exports) { 'use strict'; | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
/** | ||
@@ -12,3 +10,3 @@ * Java style map. | ||
constructor() { | ||
this[Symbol.toStringTag] = 'Map'; | ||
this[Symbol.toStringTag] = "Map"; | ||
this._map = new Map(); | ||
@@ -18,3 +16,7 @@ this._size = 0; | ||
toString() { | ||
return '{' + Array.from(this.entries2()).map(({ key, value }) => key + ':' + value).join(', ') + '}'; | ||
return ("{" + | ||
Array.from(this.entries2()) | ||
.map(({ key, value }) => key + ":" + value) | ||
.join(", ") + | ||
"}"); | ||
} | ||
@@ -57,3 +59,3 @@ forEach(callbackfn, thisArg) { | ||
if (bucket) { | ||
const pairIndex = bucket.findIndex(pair => pair.key.equals(key)); | ||
const pairIndex = bucket.findIndex((pair) => pair.key.equals(key)); | ||
if (-1 == pairIndex) { | ||
@@ -76,6 +78,6 @@ bucket.push({ key: key, value: val }); | ||
//assert(hashCode === (hashCode | 0)) | ||
return undefined !== bucket && bucket.some(pair => pair.key.equals(key)); | ||
return undefined !== bucket && bucket.some((pair) => pair.key.equals(key)); | ||
} | ||
get(key) { | ||
const hashCode = key.hashCode(), bucket = this._map.get(hashCode), pair = bucket && bucket.find(pair => pair.key.equals(key)); | ||
const hashCode = key.hashCode(), bucket = this._map.get(hashCode), pair = bucket && bucket.find((pair) => pair.key.equals(key)); | ||
return pair && pair.value; | ||
@@ -86,3 +88,3 @@ } | ||
const bucket = this._map.get(hashCode); | ||
const canonVal = bucket && bucket.find(x => x.key.like(key)); | ||
const canonVal = bucket && bucket.find((x) => x.key.like(key)); | ||
if (canonVal) | ||
@@ -95,6 +97,6 @@ return canonVal; | ||
} | ||
'delete'(key) { | ||
delete(key) { | ||
const hashCode = key.hashCode(), bucket = this._map.get(hashCode); | ||
if (bucket) { | ||
const index = bucket.findIndex(x => x.key.equals(key)); | ||
const index = bucket.findIndex((x) => x.key.equals(key)); | ||
if (-1 != index) { | ||
@@ -117,3 +119,3 @@ if (1 == bucket.length) { | ||
if (bucket) { | ||
const index = bucket.findIndex(x => x.key.like(key)); | ||
const index = bucket.findIndex((x) => x.key.like(key)); | ||
if (-1 != index) { | ||
@@ -156,3 +158,3 @@ const deleted = bucket[index]; | ||
constructor(iterable) { | ||
this[Symbol.toStringTag] = 'Set'; | ||
this[Symbol.toStringTag] = "Set"; | ||
this[Symbol.iterator] = JavaSet.prototype.values; | ||
@@ -167,3 +169,3 @@ this.keys = JavaSet.prototype.values; | ||
forEach(callbackfn, thisArg) { | ||
for (const value of this.entries()) { | ||
for (const [value] of this.entries()) { | ||
callbackfn.call(thisArg, value, value, this); | ||
@@ -181,3 +183,3 @@ } | ||
if (bucket) { | ||
if (bucket.some(x => x.equals(val))) { | ||
if (bucket.some((x) => x.equals(val))) { | ||
return false; | ||
@@ -202,3 +204,3 @@ } | ||
if (bucket) { | ||
const existing = bucket.find(x => x.equals(val)); | ||
const existing = bucket.find((x) => x.equals(val)); | ||
if (existing) { | ||
@@ -217,3 +219,3 @@ return existing; | ||
const hashCode = val.hashCode(), bucket = this._map.get(hashCode); | ||
return undefined !== bucket && bucket.some(x => x.equals(val)); | ||
return undefined !== bucket && bucket.some((x) => x.equals(val)); | ||
} | ||
@@ -223,3 +225,3 @@ getLike(val) { | ||
const bucket = this._map.get(hashCode); | ||
const canonVal = bucket && bucket.find(x => x.like(val)); | ||
const canonVal = bucket && bucket.find((x) => x.like(val)); | ||
if (canonVal) | ||
@@ -236,6 +238,6 @@ return canonVal; | ||
} | ||
'delete'(val) { | ||
delete(val) { | ||
const hashCode = val.hashCode(), bucket = this._map.get(hashCode); | ||
if (bucket) { | ||
const index = bucket.findIndex(x => x.equals(val)); | ||
const index = bucket.findIndex((x) => x.equals(val)); | ||
if (-1 != index) { | ||
@@ -258,3 +260,3 @@ if (1 == bucket.length) { | ||
if (bucket) { | ||
const index = bucket.findIndex(x => x.like(val)); | ||
const index = bucket.findIndex((x) => x.like(val)); | ||
if (-1 != index) { | ||
@@ -294,3 +296,3 @@ const deleted = bucket[index]; | ||
toString() { | ||
return '{' + Array.from(this.values()).join(', ') + '}'; | ||
return "{" + Array.from(this.values()).join(", ") + "}"; | ||
} | ||
@@ -307,9 +309,16 @@ } | ||
equals(other) { | ||
return this == other || Object.getPrototypeOf(other) == Pair.prototype && this.left.equals(other.left) && this.right.equals(other.right); | ||
return (this == other || | ||
(Object.getPrototypeOf(other) == Pair.prototype && | ||
this.left.equals(other.left) && | ||
this.right.equals(other.right))); | ||
} | ||
toString() { | ||
return '(' + this.left.toString() + ', ' + this.right.toString() + ')'; | ||
return "(" + this.left.toString() + ", " + this.right.toString() + ")"; | ||
} | ||
toSource() { | ||
return 'new Pair(' + this.left.toSource() + ', ' + this.right.toSource() + ')'; | ||
return ("new Pair(" + | ||
this.left.toSource() + | ||
", " + | ||
this.right.toSource() + | ||
")"); | ||
} | ||
@@ -321,6 +330,2 @@ } | ||
exports.Pair = Pair; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
}))); | ||
//# sourceMappingURL=bundle.js.map |
@@ -6,3 +6,3 @@ /** | ||
constructor() { | ||
this[Symbol.toStringTag] = 'Map'; | ||
this[Symbol.toStringTag] = "Map"; | ||
this._map = new Map(); | ||
@@ -12,3 +12,7 @@ this._size = 0; | ||
toString() { | ||
return '{' + Array.from(this.entries2()).map(({ key, value }) => key + ':' + value).join(', ') + '}'; | ||
return ("{" + | ||
Array.from(this.entries2()) | ||
.map(({ key, value }) => key + ":" + value) | ||
.join(", ") + | ||
"}"); | ||
} | ||
@@ -51,3 +55,3 @@ forEach(callbackfn, thisArg) { | ||
if (bucket) { | ||
const pairIndex = bucket.findIndex(pair => pair.key.equals(key)); | ||
const pairIndex = bucket.findIndex((pair) => pair.key.equals(key)); | ||
if (-1 == pairIndex) { | ||
@@ -70,6 +74,6 @@ bucket.push({ key: key, value: val }); | ||
//assert(hashCode === (hashCode | 0)) | ||
return undefined !== bucket && bucket.some(pair => pair.key.equals(key)); | ||
return undefined !== bucket && bucket.some((pair) => pair.key.equals(key)); | ||
} | ||
get(key) { | ||
const hashCode = key.hashCode(), bucket = this._map.get(hashCode), pair = bucket && bucket.find(pair => pair.key.equals(key)); | ||
const hashCode = key.hashCode(), bucket = this._map.get(hashCode), pair = bucket && bucket.find((pair) => pair.key.equals(key)); | ||
return pair && pair.value; | ||
@@ -80,3 +84,3 @@ } | ||
const bucket = this._map.get(hashCode); | ||
const canonVal = bucket && bucket.find(x => x.key.like(key)); | ||
const canonVal = bucket && bucket.find((x) => x.key.like(key)); | ||
if (canonVal) | ||
@@ -89,6 +93,6 @@ return canonVal; | ||
} | ||
'delete'(key) { | ||
delete(key) { | ||
const hashCode = key.hashCode(), bucket = this._map.get(hashCode); | ||
if (bucket) { | ||
const index = bucket.findIndex(x => x.key.equals(key)); | ||
const index = bucket.findIndex((x) => x.key.equals(key)); | ||
if (-1 != index) { | ||
@@ -111,3 +115,3 @@ if (1 == bucket.length) { | ||
if (bucket) { | ||
const index = bucket.findIndex(x => x.key.like(key)); | ||
const index = bucket.findIndex((x) => x.key.like(key)); | ||
if (-1 != index) { | ||
@@ -150,3 +154,3 @@ const deleted = bucket[index]; | ||
constructor(iterable) { | ||
this[Symbol.toStringTag] = 'Set'; | ||
this[Symbol.toStringTag] = "Set"; | ||
this[Symbol.iterator] = JavaSet.prototype.values; | ||
@@ -161,3 +165,3 @@ this.keys = JavaSet.prototype.values; | ||
forEach(callbackfn, thisArg) { | ||
for (const value of this.entries()) { | ||
for (const [value] of this.entries()) { | ||
callbackfn.call(thisArg, value, value, this); | ||
@@ -175,3 +179,3 @@ } | ||
if (bucket) { | ||
if (bucket.some(x => x.equals(val))) { | ||
if (bucket.some((x) => x.equals(val))) { | ||
return false; | ||
@@ -196,3 +200,3 @@ } | ||
if (bucket) { | ||
const existing = bucket.find(x => x.equals(val)); | ||
const existing = bucket.find((x) => x.equals(val)); | ||
if (existing) { | ||
@@ -211,3 +215,3 @@ return existing; | ||
const hashCode = val.hashCode(), bucket = this._map.get(hashCode); | ||
return undefined !== bucket && bucket.some(x => x.equals(val)); | ||
return undefined !== bucket && bucket.some((x) => x.equals(val)); | ||
} | ||
@@ -217,3 +221,3 @@ getLike(val) { | ||
const bucket = this._map.get(hashCode); | ||
const canonVal = bucket && bucket.find(x => x.like(val)); | ||
const canonVal = bucket && bucket.find((x) => x.like(val)); | ||
if (canonVal) | ||
@@ -230,6 +234,6 @@ return canonVal; | ||
} | ||
'delete'(val) { | ||
delete(val) { | ||
const hashCode = val.hashCode(), bucket = this._map.get(hashCode); | ||
if (bucket) { | ||
const index = bucket.findIndex(x => x.equals(val)); | ||
const index = bucket.findIndex((x) => x.equals(val)); | ||
if (-1 != index) { | ||
@@ -252,3 +256,3 @@ if (1 == bucket.length) { | ||
if (bucket) { | ||
const index = bucket.findIndex(x => x.like(val)); | ||
const index = bucket.findIndex((x) => x.like(val)); | ||
if (-1 != index) { | ||
@@ -288,3 +292,3 @@ const deleted = bucket[index]; | ||
toString() { | ||
return '{' + Array.from(this.values()).join(', ') + '}'; | ||
return "{" + Array.from(this.values()).join(", ") + "}"; | ||
} | ||
@@ -301,9 +305,16 @@ } | ||
equals(other) { | ||
return this == other || Object.getPrototypeOf(other) == Pair.prototype && this.left.equals(other.left) && this.right.equals(other.right); | ||
return (this == other || | ||
(Object.getPrototypeOf(other) == Pair.prototype && | ||
this.left.equals(other.left) && | ||
this.right.equals(other.right))); | ||
} | ||
toString() { | ||
return '(' + this.left.toString() + ', ' + this.right.toString() + ')'; | ||
return "(" + this.left.toString() + ", " + this.right.toString() + ")"; | ||
} | ||
toSource() { | ||
return 'new Pair(' + this.left.toSource() + ', ' + this.right.toSource() + ')'; | ||
return ("new Pair(" + | ||
this.left.toSource() + | ||
", " + | ||
this.right.toSource() + | ||
")"); | ||
} | ||
@@ -310,0 +321,0 @@ } |
@@ -1,3 +0,3 @@ | ||
export * from './JavaMap'; | ||
export * from './JavaSet'; | ||
export * from './Equalable'; | ||
export * from "./JavaMap"; | ||
export * from "./JavaSet"; | ||
export * from "./Equalable"; |
@@ -1,3 +0,4 @@ | ||
export * from './JavaMap'; | ||
export * from './JavaSet'; | ||
export * from "./JavaMap"; | ||
export * from "./JavaSet"; | ||
export * from "./Equalable"; | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
import { Equalable, int } from './Equalable'; | ||
import { Equalable, int } from "./Equalable"; | ||
/** | ||
@@ -9,3 +9,3 @@ * Java style map. | ||
}, V> implements Map<K, V> { | ||
[Symbol.toStringTag]: 'Map'; | ||
[Symbol.toStringTag]: "Map"; | ||
toString(): string; | ||
@@ -35,3 +35,3 @@ forEach(callbackfn: (value: V, index: K, map: Map<K, V>) => void, thisArg?: any): void; | ||
setLike(key: K, val: V): false | this; | ||
'delete'(key: K): boolean; | ||
delete(key: K): boolean; | ||
deleteLike(key: K): { | ||
@@ -47,3 +47,3 @@ key: K; | ||
clear(): void; | ||
readonly size: number; | ||
get size(): number; | ||
} |
@@ -6,3 +6,3 @@ /** | ||
constructor() { | ||
this[Symbol.toStringTag] = 'Map'; | ||
this[Symbol.toStringTag] = "Map"; | ||
this._map = new Map(); | ||
@@ -12,3 +12,7 @@ this._size = 0; | ||
toString() { | ||
return '{' + Array.from(this.entries2()).map(({ key, value }) => key + ':' + value).join(', ') + '}'; | ||
return ("{" + | ||
Array.from(this.entries2()) | ||
.map(({ key, value }) => key + ":" + value) | ||
.join(", ") + | ||
"}"); | ||
} | ||
@@ -51,3 +55,3 @@ forEach(callbackfn, thisArg) { | ||
if (bucket) { | ||
const pairIndex = bucket.findIndex(pair => pair.key.equals(key)); | ||
const pairIndex = bucket.findIndex((pair) => pair.key.equals(key)); | ||
if (-1 == pairIndex) { | ||
@@ -70,6 +74,6 @@ bucket.push({ key: key, value: val }); | ||
//assert(hashCode === (hashCode | 0)) | ||
return undefined !== bucket && bucket.some(pair => pair.key.equals(key)); | ||
return undefined !== bucket && bucket.some((pair) => pair.key.equals(key)); | ||
} | ||
get(key) { | ||
const hashCode = key.hashCode(), bucket = this._map.get(hashCode), pair = bucket && bucket.find(pair => pair.key.equals(key)); | ||
const hashCode = key.hashCode(), bucket = this._map.get(hashCode), pair = bucket && bucket.find((pair) => pair.key.equals(key)); | ||
return pair && pair.value; | ||
@@ -80,3 +84,3 @@ } | ||
const bucket = this._map.get(hashCode); | ||
const canonVal = bucket && bucket.find(x => x.key.like(key)); | ||
const canonVal = bucket && bucket.find((x) => x.key.like(key)); | ||
if (canonVal) | ||
@@ -89,6 +93,6 @@ return canonVal; | ||
} | ||
'delete'(key) { | ||
delete(key) { | ||
const hashCode = key.hashCode(), bucket = this._map.get(hashCode); | ||
if (bucket) { | ||
const index = bucket.findIndex(x => x.key.equals(key)); | ||
const index = bucket.findIndex((x) => x.key.equals(key)); | ||
if (-1 != index) { | ||
@@ -111,3 +115,3 @@ if (1 == bucket.length) { | ||
if (bucket) { | ||
const index = bucket.findIndex(x => x.key.like(key)); | ||
const index = bucket.findIndex((x) => x.key.like(key)); | ||
if (-1 != index) { | ||
@@ -114,0 +118,0 @@ const deleted = bucket[index]; |
@@ -1,2 +0,2 @@ | ||
import { Equalable, int } from './Equalable'; | ||
import { Equalable, int } from "./Equalable"; | ||
export declare class JavaSet<T extends Equalable & { | ||
@@ -6,4 +6,4 @@ hashCodes?(): int[]; | ||
}> implements Set<T> { | ||
[Symbol.toStringTag]: 'Set'; | ||
forEach(callbackfn: (value: T, index: T, set: Set<T>) => void, thisArg?: any): void; | ||
[Symbol.toStringTag]: "Set"; | ||
forEach(callbackfn: (value: T, value2: T, set: Set<T>) => void, thisArg?: any): void; | ||
protected _map: Map<int, T[]>; | ||
@@ -20,3 +20,3 @@ protected _size: int; | ||
addLike(val: T): false | this; | ||
'delete'(val: T): boolean; | ||
delete(val: T): boolean; | ||
deleteLike(val: T): T | undefined; | ||
@@ -26,6 +26,6 @@ values(): IterableIterator<T>; | ||
clear(): void; | ||
readonly size: int; | ||
get size(): int; | ||
toString(): string; | ||
[Symbol.iterator]: () => IterableIterator<any>; | ||
keys: () => IterableIterator<any>; | ||
[Symbol.iterator]: () => IterableIterator<T>; | ||
keys: () => IterableIterator<T>; | ||
} | ||
@@ -32,0 +32,0 @@ export declare class Pair<L extends Equalable, R extends Equalable> implements Equalable { |
export class JavaSet { | ||
constructor(iterable) { | ||
this[Symbol.toStringTag] = 'Set'; | ||
this[Symbol.toStringTag] = "Set"; | ||
this[Symbol.iterator] = JavaSet.prototype.values; | ||
@@ -13,3 +13,3 @@ this.keys = JavaSet.prototype.values; | ||
forEach(callbackfn, thisArg) { | ||
for (const value of this.entries()) { | ||
for (const [value] of this.entries()) { | ||
callbackfn.call(thisArg, value, value, this); | ||
@@ -27,3 +27,3 @@ } | ||
if (bucket) { | ||
if (bucket.some(x => x.equals(val))) { | ||
if (bucket.some((x) => x.equals(val))) { | ||
return false; | ||
@@ -48,3 +48,3 @@ } | ||
if (bucket) { | ||
const existing = bucket.find(x => x.equals(val)); | ||
const existing = bucket.find((x) => x.equals(val)); | ||
if (existing) { | ||
@@ -63,3 +63,3 @@ return existing; | ||
const hashCode = val.hashCode(), bucket = this._map.get(hashCode); | ||
return undefined !== bucket && bucket.some(x => x.equals(val)); | ||
return undefined !== bucket && bucket.some((x) => x.equals(val)); | ||
} | ||
@@ -69,3 +69,3 @@ getLike(val) { | ||
const bucket = this._map.get(hashCode); | ||
const canonVal = bucket && bucket.find(x => x.like(val)); | ||
const canonVal = bucket && bucket.find((x) => x.like(val)); | ||
if (canonVal) | ||
@@ -82,6 +82,6 @@ return canonVal; | ||
} | ||
'delete'(val) { | ||
delete(val) { | ||
const hashCode = val.hashCode(), bucket = this._map.get(hashCode); | ||
if (bucket) { | ||
const index = bucket.findIndex(x => x.equals(val)); | ||
const index = bucket.findIndex((x) => x.equals(val)); | ||
if (-1 != index) { | ||
@@ -104,3 +104,3 @@ if (1 == bucket.length) { | ||
if (bucket) { | ||
const index = bucket.findIndex(x => x.like(val)); | ||
const index = bucket.findIndex((x) => x.like(val)); | ||
if (-1 != index) { | ||
@@ -140,3 +140,3 @@ const deleted = bucket[index]; | ||
toString() { | ||
return '{' + Array.from(this.values()).join(', ') + '}'; | ||
return "{" + Array.from(this.values()).join(", ") + "}"; | ||
} | ||
@@ -153,11 +153,18 @@ } | ||
equals(other) { | ||
return this == other || Object.getPrototypeOf(other) == Pair.prototype && this.left.equals(other.left) && this.right.equals(other.right); | ||
return (this == other || | ||
(Object.getPrototypeOf(other) == Pair.prototype && | ||
this.left.equals(other.left) && | ||
this.right.equals(other.right))); | ||
} | ||
toString() { | ||
return '(' + this.left.toString() + ', ' + this.right.toString() + ')'; | ||
return "(" + this.left.toString() + ", " + this.right.toString() + ")"; | ||
} | ||
toSource() { | ||
return 'new Pair(' + this.left.toSource() + ', ' + this.right.toSource() + ')'; | ||
return ("new Pair(" + | ||
this.left.toSource() + | ||
", " + | ||
this.right.toSource() + | ||
")"); | ||
} | ||
} | ||
//# sourceMappingURL=JavaSet.js.map |
@@ -9,12 +9,10 @@ { | ||
"devDependencies": { | ||
"@types/chai": "^4.0.4", | ||
"chai": "^4.1.2", | ||
"mocha": "^3.5.0", | ||
"naridal-tslib-config": "^1.0.0", | ||
"rollup": "^0.49.2", | ||
"rollup-plugin-sourcemaps": "^0.4.2", | ||
"ts-node": "^3.3.0", | ||
"tslint": "^5.7.0", | ||
"typescript": "^2.5.2", | ||
"uglify-es": "^3.0.28" | ||
"@types/chai": "^4.2.11", | ||
"chai": "^4.2.0", | ||
"mocha": "^7.2.0", | ||
"prettier": "^2.0.5", | ||
"rollup": "^2.11.2", | ||
"rollup-plugin-sourcemaps": "^0.6.2", | ||
"ts-node": "^8.10.2", | ||
"typescript": "^3.9.3" | ||
}, | ||
@@ -36,12 +34,14 @@ "homepage": "https://github.com/NaridaL/javasetmap.ts#readme", | ||
"scripts": { | ||
"build": "tsc && rollup -c && rollup -c rollup.module.config.js && npm run minify", | ||
"build": "tsc & rollup -c", | ||
"config": "node node_modules/naridal-tslib-config && npm install", | ||
"lint": "tslint --project tsconfig.json", | ||
"minify": "uglifyjs dist/bundle.js --output dist/bundle.min.js --compress --mangle && uglifyjs dist/bundle.module.js --output dist/bundle.module.min.js --compress --mangle", | ||
"test": "(cd tests && mocha --require ts-node/register ./**/*.mocha.js ./**/*.mocha.ts)", | ||
"test:ci": "npm run build && npm run lint && npm test" | ||
"test": "(cd test && mocha --require ts-node/register ./**/*.mocha.js ./**/*.mocha.ts)", | ||
"test:ci": "npm run build && npm test", | ||
"prettier": "prettier -l --write \"{src,test}/**/*.ts\"" | ||
}, | ||
"types": "index.d.ts", | ||
"umdGlobal": "javasetmap_ts", | ||
"version": "1.1.0" | ||
"version": "1.1.1", | ||
"prettier": { | ||
"semi": false | ||
} | ||
} |
@@ -1,23 +0,31 @@ | ||
import sourcemaps from 'rollup-plugin-sourcemaps' | ||
import * as fs from 'fs' | ||
import sourcemaps from "rollup-plugin-sourcemaps" | ||
import * as fs from "fs" | ||
const pkg = JSON.parse(fs.readFileSync('package.json')) | ||
const pkg = JSON.parse(fs.readFileSync("package.json")) | ||
export default { | ||
input: 'out/index.js', | ||
output: {format: 'umd', file: 'dist/bundle.js'}, | ||
name: pkg.umdGlobal, | ||
sourcemap: true, | ||
external: Object.keys(pkg.dependencies), | ||
// globals: {'javasetmap.ts': '' }, | ||
plugins: [ | ||
sourcemaps() | ||
], | ||
onwarn: function (warning) { | ||
// Suppress this error message... there are hundreds of them. Angular team says to ignore it. | ||
// https://github.com/rollup/rollup/wiki/Troubleshooting#this-is-undefined | ||
if (warning.code === 'THIS_IS_UNDEFINED') { | ||
return | ||
} | ||
console.error(warning.message) | ||
}, | ||
input: "out/index.js", | ||
output: [ | ||
{ | ||
format: "cjs", | ||
file: "dist/bundle.js", | ||
sourcemap: true, | ||
sourcemapExcludeSources: true, | ||
}, | ||
{ | ||
format: "es", | ||
sourcemap: true, | ||
file: "dist/bundle.module.js", | ||
sourcemapExcludeSources: true, | ||
}, | ||
], | ||
external: Object.keys(pkg.dependencies || {}), | ||
plugins: [sourcemaps()], | ||
onwarn: function (warning, warn) { | ||
// Suppress this error message... there are hundreds of them. Angular team says to ignore it. | ||
// https://github.com/rollup/rollup/wiki/Troubleshooting#this-is-undefined | ||
if ("THIS_IS_UNDEFINED" === warning.code) return | ||
if ("CIRCULAR_DEPENDENCY" === warning.code) return | ||
warn(warning) | ||
}, | ||
} |
export type int = number | ||
export interface Equalable { | ||
equals(o: any): boolean | ||
equals(o: any): boolean | ||
hashCode(): int | ||
} | ||
hashCode(): int | ||
} |
@@ -1,3 +0,3 @@ | ||
export * from './JavaMap' | ||
export * from './JavaSet' | ||
export * from './Equalable' | ||
export * from "./JavaMap" | ||
export * from "./JavaSet" | ||
export * from "./Equalable" |
@@ -1,2 +0,2 @@ | ||
import {Equalable, int} from './Equalable' | ||
import { Equalable, int } from "./Equalable" | ||
@@ -6,156 +6,170 @@ /** | ||
*/ | ||
export class JavaMap<K extends Equalable & {hashCodes?(): int[], like?(x: any): boolean }, V> implements Map<K, V> { | ||
[Symbol.toStringTag]: 'Map' = 'Map' | ||
export class JavaMap< | ||
K extends Equalable & { hashCodes?(): int[]; like?(x: any): boolean }, | ||
V | ||
> implements Map<K, V> { | ||
[Symbol.toStringTag]: "Map" = "Map" | ||
toString() { | ||
return '{' + Array.from(this.entries2()).map(({key, value}) => key + ':' + value).join(', ') + '}' | ||
} | ||
toString() { | ||
return ( | ||
"{" + | ||
Array.from(this.entries2()) | ||
.map(({ key, value }) => key + ":" + value) | ||
.join(", ") + | ||
"}" | ||
) | ||
} | ||
forEach(callbackfn: (value: V, index: K, map: Map<K, V>) => void, thisArg?: any): void { | ||
for (const bucket of this._map.values()) { | ||
for (const {key, value} of bucket) { | ||
callbackfn.call(thisArg, value, key, this) | ||
} | ||
} | ||
forEach( | ||
callbackfn: (value: V, index: K, map: Map<K, V>) => void, | ||
thisArg?: any | ||
): void { | ||
for (const bucket of this._map.values()) { | ||
for (const { key, value } of bucket) { | ||
callbackfn.call(thisArg, value, key, this) | ||
} | ||
} | ||
} | ||
* keys(): IterableIterator<K> { | ||
for (const bucket of this._map.values()) { | ||
for (const {key} of bucket) { | ||
yield key | ||
} | ||
} | ||
*keys(): IterableIterator<K> { | ||
for (const bucket of this._map.values()) { | ||
for (const { key } of bucket) { | ||
yield key | ||
} | ||
} | ||
} | ||
* values(): IterableIterator<V> { | ||
for (const bucket of this._map.values()) { | ||
for (const {value} of bucket) { | ||
yield value | ||
} | ||
} | ||
*values(): IterableIterator<V> { | ||
for (const bucket of this._map.values()) { | ||
for (const { value } of bucket) { | ||
yield value | ||
} | ||
} | ||
} | ||
protected _map: Map<int, { key: K, value: V }[]> | ||
protected _size: int | ||
protected _map: Map<int, { key: K; value: V }[]> | ||
protected _size: int | ||
constructor() { | ||
this._map = new Map() | ||
this._size = 0 | ||
} | ||
constructor() { | ||
this._map = new Map() | ||
this._size = 0 | ||
} | ||
[Symbol.iterator]() { | ||
return this.entries() | ||
} | ||
[Symbol.iterator]() { | ||
return this.entries() | ||
} | ||
set(key: K, value: V): this { | ||
this.set2(key, value) | ||
return this | ||
} | ||
set(key: K, value: V): this { | ||
this.set2(key, value) | ||
return this | ||
} | ||
/** | ||
* Like {@link #set} except it returns true if key was new and false if the value was only updated. | ||
* | ||
*/ | ||
set2(key: K, val: V): boolean { | ||
const hashCode = key.hashCode(), bucket = this._map.get(hashCode) | ||
//assert(hashCode === (hashCode | 0)) | ||
if (bucket) { | ||
const pairIndex = bucket.findIndex(pair => pair.key.equals(key)) | ||
if (-1 == pairIndex) { | ||
bucket.push({key: key, value: val}) | ||
} else { | ||
bucket[pairIndex].value = val | ||
return false | ||
} | ||
} else { | ||
this._map.set(hashCode, [{key: key, value: val}]) | ||
} | ||
this._size++ | ||
return true | ||
/** | ||
* Like {@link #set} except it returns true if key was new and false if the value was only updated. | ||
* | ||
*/ | ||
set2(key: K, val: V): boolean { | ||
const hashCode = key.hashCode(), | ||
bucket = this._map.get(hashCode) | ||
//assert(hashCode === (hashCode | 0)) | ||
if (bucket) { | ||
const pairIndex = bucket.findIndex((pair) => pair.key.equals(key)) | ||
if (-1 == pairIndex) { | ||
bucket.push({ key: key, value: val }) | ||
} else { | ||
bucket[pairIndex].value = val | ||
return false | ||
} | ||
} else { | ||
this._map.set(hashCode, [{ key: key, value: val }]) | ||
} | ||
this._size++ | ||
return true | ||
} | ||
has(key: K): boolean { | ||
const hashCode = key.hashCode(), bucket = this._map.get(hashCode) | ||
//assert(hashCode === (hashCode | 0)) | ||
return undefined !== bucket && bucket.some(pair => pair.key.equals(key)) | ||
} | ||
has(key: K): boolean { | ||
const hashCode = key.hashCode(), | ||
bucket = this._map.get(hashCode) | ||
//assert(hashCode === (hashCode | 0)) | ||
return undefined !== bucket && bucket.some((pair) => pair.key.equals(key)) | ||
} | ||
get(key: K): V | undefined { | ||
const | ||
hashCode = key.hashCode(), | ||
bucket = this._map.get(hashCode), | ||
pair = bucket && bucket.find(pair => pair.key.equals(key)) | ||
return pair && pair.value | ||
} | ||
get(key: K): V | undefined { | ||
const hashCode = key.hashCode(), | ||
bucket = this._map.get(hashCode), | ||
pair = bucket && bucket.find((pair) => pair.key.equals(key)) | ||
return pair && pair.value | ||
} | ||
getLike(key: K) { | ||
for (const hashCode of key.hashCodes!()) { | ||
const bucket = this._map.get(hashCode) | ||
const canonVal = bucket && bucket.find(x => x.key.like!(key)) | ||
if (canonVal) return canonVal | ||
} | ||
getLike(key: K) { | ||
for (const hashCode of key.hashCodes!()) { | ||
const bucket = this._map.get(hashCode) | ||
const canonVal = bucket && bucket.find((x) => x.key.like!(key)) | ||
if (canonVal) return canonVal | ||
} | ||
} | ||
setLike(key: K, val: V) { | ||
return !this.getLike(key) && this.set(key, val) | ||
} | ||
setLike(key: K, val: V) { | ||
return !this.getLike(key) && this.set(key, val) | ||
} | ||
'delete'(key: K) { | ||
const hashCode = key.hashCode(), bucket = this._map.get(hashCode) | ||
if (bucket) { | ||
const index = bucket.findIndex(x => x.key.equals(key)) | ||
if (-1 != index) { | ||
if (1 == bucket.length) { | ||
this._map.delete(hashCode) | ||
} else { | ||
bucket.splice(index, 1) | ||
} | ||
this._size-- | ||
return true | ||
} | ||
delete(key: K) { | ||
const hashCode = key.hashCode(), | ||
bucket = this._map.get(hashCode) | ||
if (bucket) { | ||
const index = bucket.findIndex((x) => x.key.equals(key)) | ||
if (-1 != index) { | ||
if (1 == bucket.length) { | ||
this._map.delete(hashCode) | ||
} else { | ||
bucket.splice(index, 1) | ||
} | ||
return false | ||
this._size-- | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
deleteLike(key: K) { | ||
for (const hashCode of key.hashCodes!()) { | ||
const bucket = this._map.get(hashCode) | ||
if (bucket) { | ||
const index = bucket.findIndex(x => x.key.like!(key)) | ||
if (-1 != index) { | ||
const deleted = bucket[index] | ||
if (1 == bucket.length) { | ||
this._map.delete(hashCode) | ||
} else { | ||
bucket.splice(index, 1) | ||
} | ||
this._size-- | ||
return deleted | ||
} | ||
} | ||
deleteLike(key: K) { | ||
for (const hashCode of key.hashCodes!()) { | ||
const bucket = this._map.get(hashCode) | ||
if (bucket) { | ||
const index = bucket.findIndex((x) => x.key.like!(key)) | ||
if (-1 != index) { | ||
const deleted = bucket[index] | ||
if (1 == bucket.length) { | ||
this._map.delete(hashCode) | ||
} else { | ||
bucket.splice(index, 1) | ||
} | ||
this._size-- | ||
return deleted | ||
} | ||
} | ||
} | ||
} | ||
* entries2(): IterableIterator<{ key: K, value: V }> { | ||
for (const bucket of this._map.values()) { | ||
yield* bucket | ||
} | ||
*entries2(): IterableIterator<{ key: K; value: V }> { | ||
for (const bucket of this._map.values()) { | ||
yield* bucket | ||
} | ||
} | ||
* entries(): IterableIterator<[K, V]> { | ||
for (const bucket of this._map.values()) { | ||
for (const {key, value} of bucket) { | ||
yield [key, value] | ||
} | ||
} | ||
*entries(): IterableIterator<[K, V]> { | ||
for (const bucket of this._map.values()) { | ||
for (const { key, value } of bucket) { | ||
yield [key, value] | ||
} | ||
} | ||
} | ||
clear() { | ||
this._map.clear() | ||
this._size = 0 | ||
} | ||
clear() { | ||
this._map.clear() | ||
this._size = 0 | ||
} | ||
get size() { | ||
return this._size | ||
} | ||
get size() { | ||
return this._size | ||
} | ||
} |
@@ -1,172 +0,192 @@ | ||
import {Equalable, int} from './Equalable' | ||
import { Equalable, int } from "./Equalable" | ||
export class JavaSet<T extends Equalable & {hashCodes?(): int[], like?(x: any): boolean }> implements Set<T> { | ||
[Symbol.toStringTag]: 'Set' = 'Set' | ||
export class JavaSet< | ||
T extends Equalable & { hashCodes?(): int[]; like?(x: any): boolean } | ||
> implements Set<T> { | ||
[Symbol.toStringTag]: "Set" = "Set" | ||
forEach(callbackfn: (value: T, index: T, set: Set<T>)=>void, thisArg?: any): void { | ||
for (const value of this.entries()) { | ||
callbackfn.call(thisArg, value, value, this) | ||
} | ||
} | ||
protected _map: Map<int, T[]> | ||
protected _size: int | ||
forEach( | ||
callbackfn: (value: T, value2: T, set: Set<T>) => void, | ||
thisArg?: any | ||
): void { | ||
for (const [value] of this.entries()) { | ||
callbackfn.call(thisArg, value, value, this) | ||
} | ||
} | ||
protected _map: Map<int, T[]> | ||
protected _size: int | ||
constructor(iterable?: Iterable<T>) { | ||
this._map = new Map() | ||
this._size = 0 | ||
if (iterable) { | ||
this.addAll(iterable) | ||
} | ||
} | ||
constructor(iterable?: Iterable<T>) { | ||
this._map = new Map() | ||
this._size = 0 | ||
if (iterable) { | ||
this.addAll(iterable) | ||
} | ||
} | ||
add(val: T): this { | ||
this.add2(val) | ||
return this | ||
} | ||
add(val: T): this { | ||
this.add2(val) | ||
return this | ||
} | ||
add2(val: T): boolean { | ||
// you can't use this.canonicalize here, as there is no way to differentiate if val | ||
// is new or if val was === the exisitng value (not only .equals) | ||
const hashCode = val.hashCode(), bucket = this._map.get(hashCode) | ||
if (bucket) { | ||
if (bucket.some(x => x.equals(val))) { | ||
return false | ||
} | ||
bucket.push(val) | ||
} else { | ||
this._map.set(hashCode, [val]) | ||
} | ||
this._size++ | ||
return true | ||
} | ||
add2(val: T): boolean { | ||
// you can't use this.canonicalize here, as there is no way to differentiate if val | ||
// is new or if val was === the exisitng value (not only .equals) | ||
const hashCode = val.hashCode(), | ||
bucket = this._map.get(hashCode) | ||
if (bucket) { | ||
if (bucket.some((x) => x.equals(val))) { | ||
return false | ||
} | ||
bucket.push(val) | ||
} else { | ||
this._map.set(hashCode, [val]) | ||
} | ||
this._size++ | ||
return true | ||
} | ||
addAll(iterable: Iterable<T>): this { | ||
for (const val of iterable) { | ||
this.add(val) | ||
} | ||
return this | ||
} | ||
addAll(iterable: Iterable<T>): this { | ||
for (const val of iterable) { | ||
this.add(val) | ||
} | ||
return this | ||
} | ||
canonicalize(val: T): T { | ||
const hashCode = val.hashCode(), bucket = this._map.get(hashCode) | ||
if (bucket) { | ||
const existing = bucket.find(x => x.equals(val)) | ||
if (existing) { | ||
return existing | ||
} | ||
bucket.push(val) | ||
} else { | ||
this._map.set(hashCode, [val]) | ||
} | ||
this._size++ | ||
return val | ||
} | ||
canonicalize(val: T): T { | ||
const hashCode = val.hashCode(), | ||
bucket = this._map.get(hashCode) | ||
if (bucket) { | ||
const existing = bucket.find((x) => x.equals(val)) | ||
if (existing) { | ||
return existing | ||
} | ||
bucket.push(val) | ||
} else { | ||
this._map.set(hashCode, [val]) | ||
} | ||
this._size++ | ||
return val | ||
} | ||
has(val: T): boolean { | ||
const hashCode = val.hashCode(), bucket = this._map.get(hashCode) | ||
return undefined !== bucket && bucket.some(x => x.equals(val)) | ||
} | ||
has(val: T): boolean { | ||
const hashCode = val.hashCode(), | ||
bucket = this._map.get(hashCode) | ||
return undefined !== bucket && bucket.some((x) => x.equals(val)) | ||
} | ||
getLike(val: T) { | ||
for (const hashCode of val.hashCodes!()) { | ||
const bucket = this._map.get(hashCode) | ||
const canonVal = bucket && bucket.find(x => x.like!(val)) | ||
if (canonVal) return canonVal | ||
} | ||
} | ||
getLike(val: T) { | ||
for (const hashCode of val.hashCodes!()) { | ||
const bucket = this._map.get(hashCode) | ||
const canonVal = bucket && bucket.find((x) => x.like!(val)) | ||
if (canonVal) return canonVal | ||
} | ||
} | ||
canonicalizeLike(val: T) { | ||
// if this.getLike(val) is defined, return it, otherwise add val and return val | ||
return this.getLike(val) || this.canonicalize(val) | ||
} | ||
canonicalizeLike(val: T) { | ||
// if this.getLike(val) is defined, return it, otherwise add val and return val | ||
return this.getLike(val) || this.canonicalize(val) | ||
} | ||
addLike(val: T) { | ||
return !this.getLike(val) && this.add(val) | ||
} | ||
addLike(val: T) { | ||
return !this.getLike(val) && this.add(val) | ||
} | ||
'delete'(val: T) { | ||
const hashCode = val.hashCode(), bucket = this._map.get(hashCode) | ||
if (bucket) { | ||
const index = bucket.findIndex(x => x.equals(val)) | ||
if (-1 != index) { | ||
if (1 == bucket.length) { | ||
this._map.delete(hashCode) | ||
} else { | ||
bucket.splice(index, 1) | ||
} | ||
this._size-- | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
delete(val: T) { | ||
const hashCode = val.hashCode(), | ||
bucket = this._map.get(hashCode) | ||
if (bucket) { | ||
const index = bucket.findIndex((x) => x.equals(val)) | ||
if (-1 != index) { | ||
if (1 == bucket.length) { | ||
this._map.delete(hashCode) | ||
} else { | ||
bucket.splice(index, 1) | ||
} | ||
this._size-- | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
deleteLike(val: T) { | ||
for (const hashCode of val.hashCodes!()) { | ||
const bucket = this._map.get(hashCode) | ||
if (bucket) { | ||
const index = bucket.findIndex(x => x.like!(val)) | ||
if (-1 != index) { | ||
const deleted = bucket[index] | ||
if (1 == bucket.length) { | ||
this._map.delete(hashCode) | ||
} else { | ||
bucket.splice(index, 1) | ||
} | ||
this._size-- | ||
return deleted | ||
} | ||
} | ||
} | ||
} | ||
deleteLike(val: T) { | ||
for (const hashCode of val.hashCodes!()) { | ||
const bucket = this._map.get(hashCode) | ||
if (bucket) { | ||
const index = bucket.findIndex((x) => x.like!(val)) | ||
if (-1 != index) { | ||
const deleted = bucket[index] | ||
if (1 == bucket.length) { | ||
this._map.delete(hashCode) | ||
} else { | ||
bucket.splice(index, 1) | ||
} | ||
this._size-- | ||
return deleted | ||
} | ||
} | ||
} | ||
} | ||
*values(): IterableIterator<T> { | ||
for (const bucket of this._map.values()) { | ||
yield* bucket | ||
} | ||
} | ||
*entries(): IterableIterator<[T, T]> { | ||
for (const bucket of this._map.values()) { | ||
for (const value of bucket) { | ||
yield [value, value] | ||
} | ||
} | ||
} | ||
*values(): IterableIterator<T> { | ||
for (const bucket of this._map.values()) { | ||
yield* bucket | ||
} | ||
} | ||
*entries(): IterableIterator<[T, T]> { | ||
for (const bucket of this._map.values()) { | ||
for (const value of bucket) { | ||
yield [value, value] | ||
} | ||
} | ||
} | ||
clear(): void { | ||
this._map.clear() | ||
this._size = 0 | ||
} | ||
clear(): void { | ||
this._map.clear() | ||
this._size = 0 | ||
} | ||
get size(): int { | ||
return this._size | ||
} | ||
get size(): int { | ||
return this._size | ||
} | ||
toString() { | ||
return '{' + Array.from(this.values()).join(', ') + '}' | ||
} | ||
toString() { | ||
return "{" + Array.from(this.values()).join(", ") + "}" | ||
} | ||
[Symbol.iterator] = JavaSet.prototype.values | ||
keys = JavaSet.prototype.values | ||
[Symbol.iterator] = JavaSet.prototype.values | ||
keys = JavaSet.prototype.values | ||
} | ||
export class Pair<L extends Equalable, R extends Equalable> implements Equalable { | ||
export class Pair<L extends Equalable, R extends Equalable> | ||
implements Equalable { | ||
constructor(public left: L, public right: R) {} | ||
constructor(public left: L, public right: R) {} | ||
hashCode() { | ||
return this.left.hashCode() * 31 + this.right.hashCode() | ||
} | ||
hashCode() { | ||
return this.left.hashCode() * 31 + this.right.hashCode() | ||
} | ||
equals(other: any) { | ||
return ( | ||
this == other || | ||
(Object.getPrototypeOf(other) == Pair.prototype && | ||
this.left.equals(other.left) && | ||
this.right.equals(other.right)) | ||
) | ||
} | ||
equals(other: any) { | ||
return this == other || Object.getPrototypeOf(other) == Pair.prototype && this.left.equals(other.left) && this.right.equals(other.right) | ||
} | ||
toString() { | ||
return "(" + this.left.toString() + ", " + this.right.toString() + ")" | ||
} | ||
toString() { | ||
return '(' + this.left.toString() + ', ' + this.right.toString() + ')' | ||
} | ||
toSource() { | ||
return 'new Pair(' + (this.left as any).toSource() + ', ' + (this.right as any).toSource() + ')' | ||
} | ||
} | ||
toSource() { | ||
return ( | ||
"new Pair(" + | ||
(this.left as any).toSource() + | ||
", " + | ||
(this.right as any).toSource() + | ||
")" | ||
) | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
8
1
75048
30
1469