Skip to content

Commit 74931a3

Browse files
committed
remove pointer, create comment and refactor structure also
1 parent 083222c commit 74931a3

12 files changed

Lines changed: 365 additions & 150 deletions

File tree

java/io/Serializable/Serializable.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
namespace Java {
3131
namespace IO {
3232
class Serializable {
33+
protected:
34+
Serializable() {};
35+
virtual ~Serializable() {};
3336
};
3437
}
3538
}

java/lang/Cloneable/Cloneable.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030
namespace Java {
3131
namespace Lang {
3232
class Cloneable {
33+
34+
protected:
35+
Cloneable() {};
36+
virtual ~Cloneable() {};
3337
};
3438
}
3539
}

java/lang/Object/Object.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ namespace Java {
157157
* @param obj
158158
* @return
159159
*/
160-
virtual boolean equals(const Object &obj) const {
161-
if (this->hashCode() == obj.hashCode()) {
160+
virtual boolean equals(const Object &o) const {
161+
if (this->hashCode() == o.hashCode()) {
162162
return true;
163163
}
164164
return false;
@@ -173,7 +173,7 @@ namespace Java {
173173
* A hash code value for this object.
174174
* @return int
175175
*/
176-
int hashCode() const {
176+
virtual int hashCode() const {
177177
long element = (intptr_t) std::addressof(*this);
178178
int elementHash = (int)(element ^ (element >> 32));
179179

java/util/AbstractCollection/AbstractCollection.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@
1616
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1717
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
1818
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19-
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
19+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU DING, BUT NOT
2020
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2121
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2222
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2323
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2424
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2525
*/
2626

27+
#include "AbstractCollection.hpp"

java/util/AbstractCollection/AbstractCollection.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ namespace Java {
3636
namespace Util {
3737
template <typename E>
3838
class AbstractCollection : public Object, public virtual Collection<E> {
39+
40+
protected:
41+
AbstractCollection() {}
42+
virtual ~AbstractCollection() {}
43+
3944
};
4045
}
4146
}

java/util/AbstractList/AbstractList.hpp

Lines changed: 8 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2222
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2323
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24-
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25-
*/
24+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25+
*/
2626

2727
#ifndef NATIVE_JAVA_UTIL_ABSTRACT_LIST_HPP
2828
#define NATIVE_JAVA_UTIL_ABSTRACT_LIST_HPP
@@ -35,67 +35,12 @@
3535
namespace Java {
3636
namespace Util {
3737
template <class E>
38-
class AbstractList : public virtual AbstractCollection<E> {
39-
protected:
40-
AbstractList() {
41-
}
42-
public:
43-
boolean add(E e) {
44-
// TODO
45-
return true;
46-
}
47-
void add(int index, E element) {
48-
// TODO
49-
}
50-
boolean addAll(int index, Collection<E> &c) {
51-
// TODO
52-
return true;
53-
}
54-
void clear() {
55-
// TODO
56-
}
57-
boolean equals(Object &o) const {
58-
return true;
59-
}
60-
virtual E &get(int index) const = 0;
61-
int hashCode() const {
62-
// TODO
63-
return 0;
64-
}
65-
int indexOf(Object &o) const {
66-
return 0;
67-
}
68-
Iterator<E> iterator() {
69-
Iterator<E> *it = new Iterator<E>();
70-
}
71-
int lastIndexOf(Object &o) {
72-
// TODO
73-
return 0;
74-
}
75-
ListIterator<E> listIterator() {
76-
// TODO
77-
ListIterator<E> *listIterator = new ListIterator<E>();
78-
return *listIterator;
79-
}
80-
ListIterator<E> listIterator(int index) {
81-
// TODO
82-
ListIterator<E> *listIterator = new ListIterator<E>();
83-
return *listIterator;
84-
}
85-
E remove(int index) {
86-
// TODO
87-
E *e = new E();
88-
return *e;
89-
}
90-
E set(int index, E element) const {
91-
// TODO
92-
E *e = new E();
93-
return e;
94-
}
95-
// List<E> &subList(int fromIndex, int toIndex) const {
96-
//
97-
// }
98-
};
38+
class AbstractList : public AbstractCollection<E>, public virtual List<E> {
39+
40+
protected:
41+
AbstractList() {}
42+
virtual ~AbstractList() {}
43+
};
9944
}
10045
}
10146

java/util/AbstractMap/AbstractMap.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ using namespace Java::Lang;
3333

3434
namespace Java {
3535
namespace Util {
36-
class AbstractMap : public virtual Object {
36+
class AbstractMap : public Object, public virtual Map {
37+
38+
protected:
39+
AbstractMap() {}
40+
virtual ~AbstractMap() {}
3741

3842
};
3943
}

java/util/ArrayList/ArrayList.hpp

Lines changed: 43 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,13 @@ namespace Java {
7474
int _pos;
7575
const ArrayList<E> *_p_vec;
7676
};
77-
template <typename E>
78-
class ArrayList :
79-
public virtual AbstractList<E>,
80-
public virtual Serializable,
81-
public virtual Cloneable,
82-
// public virtual List<E>,
83-
public virtual RandomAccess {
77+
78+
template <typename E>
79+
class ArrayList: public AbstractList<E>,
80+
public virtual List<E>,
81+
public virtual Serializable,
82+
public virtual Cloneable,
83+
public virtual RandomAccess {
8484
private:
8585
std::vector<E> original;
8686

@@ -89,7 +89,6 @@ namespace Java {
8989
* Constructs an empty list
9090
*/
9191
ArrayList() {
92-
9392
}
9493

9594
/**
@@ -98,7 +97,6 @@ namespace Java {
9897
* @param c
9998
*/
10099
ArrayList(Collection<E> &c) {
101-
102100
}
103101

104102
/**
@@ -197,7 +195,7 @@ namespace Java {
197195
*
198196
* @return Object
199197
*/
200-
Object &clone() {
198+
Object clone() {
201199
// TODO
202200
Object c;
203201
return c;
@@ -214,6 +212,15 @@ namespace Java {
214212
return true;
215213
}
216214

215+
/**
216+
*
217+
* @param c
218+
* @return
219+
*/
220+
virtual boolean containsAll(Collection<Object> &c) const {
221+
//TODO
222+
}
223+
217224
/**
218225
* Increases the capacity of this ArrayList instance, if necessary,
219226
* to ensure that it can hold at least the number of elements specified by
@@ -241,10 +248,10 @@ namespace Java {
241248
* @param index
242249
* @return
243250
*/
244-
E &get(int index) const {
251+
E get(int index) const {
245252
if (index < 0) return (E&)this->original.at(0);
246253
if (index > this->size() - 1) return (E&)this->original.at(this->size() - 1);
247-
return (E&) original.at(index);
254+
return original.at(index);
248255
}
249256

250257
/**
@@ -296,7 +303,6 @@ namespace Java {
296303
* @return Address of ListIterator<E>
297304
*/
298305
ListIterator<E> &listIterator() const {
299-
// TODO
300306
ListIterator<E> *listIterator = new ListIterator<E>();
301307
return *listIterator;
302308
}
@@ -309,7 +315,6 @@ namespace Java {
309315
* @return Address of ListIterator<E>
310316
*/
311317
ListIterator<E> &listIterator(int index) const {
312-
// TODO
313318
ListIterator<E> *listIterator = new ListIterator<E>();
314319
return *listIterator;
315320
}
@@ -320,10 +325,11 @@ namespace Java {
320325
* @param index
321326
* @return Address of element
322327
*/
323-
E &remove(int index) {
324-
// TODO
325-
E *e = new E();
326-
return *e;
328+
E remove(int index) {
329+
if (index < 0 || index >= this->size()) {
330+
//FIXME: throw exception
331+
}
332+
327333
}
328334

329335
/**
@@ -391,10 +397,9 @@ namespace Java {
391397
* @param element
392398
* @return Adress of E
393399
*/
394-
E &set(int index, E &element) {
395-
// TODO
396-
E *e = new E();
397-
return *e;
400+
E set(int index, E &element) {
401+
E e;
402+
return e;
398403
}
399404

400405
/**
@@ -426,19 +431,19 @@ namespace Java {
426431
return *spliterator;
427432
}
428433

429-
// List<E> &subList(int fromIndex, int toIndex) const {
430-
// // TODO
431-
// List<E> *list = new ArrayList<E>();
432-
// return *list;
433-
// }
434+
// List<E> &subList(int fromIndex, int toIndex) const {
435+
// // TODO
436+
// List<E> *list = new ArrayList<E>();
437+
// return *list;
438+
// }
434439

435440
/**
436441
* Returns an array containing all of the elements in this
437442
* list in proper sequence (from first to last element).
438443
*
439444
* @return Array<Object>
440445
*/
441-
Array<Object> &toArray() {
446+
Array<Object> toArray() {
442447
// TODO
443448
Array<Object> objects;
444449
return objects;
@@ -476,7 +481,15 @@ namespace Java {
476481
return (string) "" ;
477482
}
478483

479-
protected:
484+
int hashCode() const {
485+
//TODO
486+
}
487+
488+
boolean equals(const Object &o) const {
489+
//TODO
490+
}
491+
492+
protected:
480493
/**
481494
* Removes from this list all of the elements
482495
* whose index is between fromIndex, inclusive, and toIndex, exclusive.
@@ -489,9 +502,8 @@ namespace Java {
489502
// TODO
490503
}
491504
};
492-
493-
template <typename E>
494505

506+
template <typename E>
495507
class SubList : public virtual AbstractList<E> {
496508
private:
497509
AbstractList<E> l;

java/util/Collection/Collection.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ namespace Java {
8484
* @param o
8585
* @return boolean
8686
*/
87-
virtual boolean equals(Object &o) const = 0;
87+
virtual boolean equals(const Object &o) const = 0;
8888

8989
/**
9090
* Make a hashcode through this virtual address on memory

0 commit comments

Comments
 (0)