Skip to content

Commit

Permalink
Remove use of plugin-proposal-class-properties
Browse files Browse the repository at this point in the history
  • Loading branch information
bjornharrtell committed Jun 6, 2020
1 parent 8a8b314 commit 5e013d9
Show file tree
Hide file tree
Showing 16 changed files with 138 additions and 143 deletions.
3 changes: 0 additions & 3 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,5 @@ module.exports = {
node: ['10']
}
}]
],
plugins: [
'@babel/plugin-proposal-class-properties'
]
}
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"license": "(EDL-1.0 OR EPL-1.0)",
"devDependencies": {
"@babel/core": "7.10.2",
"@babel/plugin-proposal-class-properties": "7.10.1",
"@babel/preset-env": "7.10.2",
"babel-eslint": "10.1.0",
"chai": "4.2.0",
Expand Down
1 change: 0 additions & 1 deletion src/java/lang/Exception.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export default class Exception {
message
constructor(message) {
this.message = message
}
Expand Down
9 changes: 4 additions & 5 deletions src/java/lang/Integer.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
export default class Integer {
#value
constructor(value) {
this.#value = value
this.value = value
}

intValue() {
return this.#value
return this.value
}

compareTo(o) {
if (this.#value < o)
if (this.value < o)
return -1
if (this.#value > o)
if (this.value > o)
return 1
return 0
}
Expand Down
6 changes: 2 additions & 4 deletions src/java/lang/Long.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
export default class Long {
high = 0
low = 0
constructor(high, low) {
this.low = low
this.high = high
this.low = low || 0
this.high = high || 0
}

static toBinaryString(i) {
Expand Down
9 changes: 4 additions & 5 deletions src/java/lang/StringBuffer.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
export default class StringBuffer {
#str
constructor(str) {
this.#str = str
this.str = str
}
append(e) {
this.#str += e
this.str += e
}
setCharAt(i, c) {
this.#str = this.#str.substr(0, i) + c + this.#str.substr(i + 1)
this.str = this.str.substr(0, i) + c + this.str.substr(i + 1)
}
toString() {
return this.#str
return this.str
}
}
29 changes: 14 additions & 15 deletions src/java/lang/StringBuilder.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
export default function StringBuilder(str) {
this.str = str
}

StringBuilder.prototype.append = function(e) {
this.str += e
}

StringBuilder.prototype.setCharAt = function(i, c) {
this.str = this.str.substr(0, i) + c + this.str.substr(i + 1)
}

StringBuilder.prototype.toString = function() {
return this.str
}
export default class StringBuilder {
constructor(str) {
this.str = str
}
append(e) {
this.str += e
}
setCharAt(i, c) {
this.str = this.str.substr(0, i) + c + this.str.substr(i + 1)
}
toString() {
return this.str
}
}
55 changes: 28 additions & 27 deletions src/java/util/ArrayList.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,39 @@ import NoSuchElementException from './NoSuchElementException'
* @see http://download.oracle.com/javase/6/docs/api/java/util/ArrayList.html
*/
export default class ArrayList extends List {
interfaces_ = [List, Collection]
#array = []

constructor(o) {
super()
this.array = []
if (o instanceof Collection) this.addAll(o)
}

get interfaces_() {
return [List, Collection]
}

ensureCapacity() { }

add(e) {
if (arguments.length === 1)
this.#array.push(e)
this.array.push(e)
else
this.#array.splice(arguments[0], 0, arguments[1])
this.array.splice(arguments[0], 0, arguments[1])
return true
}

clear() {
this.#array = []
this.array = []
}

addAll(c) {
for (const e of c)
this.#array.push(e)
this.array.push(e)
}

set(index, element) {
const oldElement = this.#array[index]
this.#array[index] = element
const oldElement = this.array[index]
this.array[index] = element
return oldElement
}

Expand All @@ -47,62 +50,60 @@ export default class ArrayList extends List {
get(index) {
if (index < 0 || index >= this.size())
throw new IndexOutOfBoundsException()
return this.#array[index]
return this.array[index]
}

isEmpty() {
return this.#array.length === 0
return this.array.length === 0
}

sort(comparator) {
if (comparator)
this.#array.sort((a, b) => comparator.compare(a, b))
else this.#array.sort()
this.array.sort((a, b) => comparator.compare(a, b))
else this.array.sort()
}

size() {
return this.#array.length
return this.array.length
}

toArray() {
return this.#array.slice()
return this.array.slice()
}

remove(o) {
for (let i = 0, len = this.#array.length; i < len; i++)
if (this.#array[i] === o)
return !!this.#array.splice(i, 1)
for (let i = 0, len = this.array.length; i < len; i++)
if (this.array[i] === o)
return !!this.array.splice(i, 1)
return false
}

[Symbol.iterator]() {
return this.#array.values()
return this.array.values()
}
}

class Iterator {
#arrayList
#position = 0

constructor(arrayList) {
this.#arrayList = arrayList
this.arrayList = arrayList
this.position = 0
}

next() {
if (this.#position === this.#arrayList.size())
if (this.position === this.arrayList.size())
throw new NoSuchElementException()
return this.#arrayList.get(this.#position++)
return this.arrayList.get(this.position++)
}

hasNext() {
return this.#position < this.#arrayList.size()
return this.position < this.arrayList.size()
}

set(element) {
return this.#arrayList.set(this.#position - 1, element)
return this.arrayList.set(this.position - 1, element)
}

remove() {
this.#arrayList.remove(this.#arrayList.get(this.#position))
this.arrayList.remove(this.arrayList.get(this.position))
}
}
15 changes: 9 additions & 6 deletions src/java/util/HashMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,23 @@ import HashSet from './HashSet'
* @see http://download.oracle.com/javase/6/docs/api/java/util/HashMap.html
*/
export default class HashMap extends MapInterface {
#map = new Map()
constructor() {
super()
this.map = new Map()
}

get(key) {
return this.#map.get(key) || null
return this.map.get(key) || null
}

put(key, value) {
this.#map.set(key, value)
this.map.set(key, value)
return value
}

values() {
const arrayList = new ArrayList()
const it = this.#map.values()
const it = this.map.values()
let o = it.next()
while (!o.done) {
arrayList.add(o.value)
Expand All @@ -30,11 +33,11 @@ export default class HashMap extends MapInterface {

entrySet() {
const hashSet = new HashSet()
this.#map.entries().forEach(entry => hashSet.add(entry))
this.map.entries().forEach(entry => hashSet.add(entry))
return hashSet
}

size() {
return this.#map.size()
return this.map.size()
}
}
42 changes: 19 additions & 23 deletions src/java/util/HashSet.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,25 @@ import Set from './Set'
* @see http://docs.oracle.com/javase/6/docs/api/java/util/HashSet.html
*/
export default class HashSet extends Set {
#map = new Map()
constructor(o) {
super()
this.map = new Map()
if (o instanceof Collection)
this.addAll(o)
}

contains(o) {
const hashCode = o.hashCode ? o.hashCode() : o
if (this.#map.has(hashCode))
if (this.map.has(hashCode))
return true
return false
}

add(o) {
const hashCode = o.hashCode ? o.hashCode() : o
if (this.#map.has(hashCode))
if (this.map.has(hashCode))
return false
return !!this.#map.set(hashCode, o)
return !!this.map.set(hashCode, o)
}

addAll(c) {
Expand All @@ -39,50 +39,46 @@ export default class HashSet extends Set {
}

size() {
return this.#map.size
return this.map.size
}

isEmpty() {
return this.#map.size === 0
return this.map.size === 0
}

toArray() {
return Array.from(this.#map.values())
return Array.from(this.map.values())
}

iterator() {
return new Iterator(this.#map)
return new Iterator(this.map)
}

[Symbol.iterator]() {
return this.#map
return this.map
}
}

class Iterator {
#iterator
#done
#value

constructor(map) {
this.#iterator = map.values()
const { done, value } = this.#iterator.next()
this.#done = done
this.#value = value
this.iterator = map.values()
const { done, value } = this.iterator.next()
this.done = done
this.value = value
}

next() {
if (this.#done)
if (this.done)
throw new NoSuchElementException()
const current = this.#value
const { done, value } = this.#iterator.next()
this.#done = done
this.#value = value
const current = this.value
const { done, value } = this.iterator.next()
this.done = done
this.value = value
return current
}

hasNext() {
return !this.#done
return !this.done
}

remove() {
Expand Down
11 changes: 7 additions & 4 deletions src/java/util/LinkedList.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
export default class LinkedList {
#array = []
constructor() {
this.array = []
}

addLast(e) {
this.#array.push(e)
this.array.push(e)
}

removeFirst() {
return this.#array.shift()
return this.array.shift()
}

isEmpty() {
return this.#array.length === 0
return this.array.length === 0
}
}
Loading

0 comments on commit 5e013d9

Please sign in to comment.