Есть следующие классы: Код |
package questions;
import java.util.Iterator;
/** * SimpleList implements some methods of List interface * * * */ public class SimpleArrayList { //array to store elements of the list Object[] data;
/** * Specified by: the same method of java.util.List * @param index * @return */ public Object get(int index){ //todo: implement
}
/** * Specified by: the same method of java.util.List * @param index * @param obj */ public Object set(int index, Object obj){ //todo: implement
}
/** * Specified by: the same method of java.util.List * @param index * @param element */ public void add(int index, Object element){ //todo: implement
}
/** * Specified by: the same method of java.util.List * @return */ public Iterator iterator(){ return new Iterator(){ //todo: implement }; }
/** * Specified by: the same method of java.util.List * @return */ public int hashCode(){ //todo: implement }
/** * Specified by: the same method of java.util.List * @return */ public boolean equals(Object obj) { //todo: impelment
}
/** * Specified by: the same method of java.util.List * @return */ public int indexOf(Object o){ ////todo: impelment } }
package questions;
import java.util.List;
/** * Test task */
public class ReverseList { /** * reverse the list given as the param * !!! don't change the signature of the method * @param list to be reversed */ public static void reverseList(List list) { //todo: impelment }
}
|
В соотвецтвии нужно выполнить следующее задание : Implement SimpleArrayList (see SimpleArrayList.java attached) and Write unit tests for the class Implement ReverseList.reverseList(List list) method (see ReverseList.java attached) and write unit tests for the class Use JUnit to create tests Насколько, я понимаю, нужно дописать функционал описанных функций классов и по ним провести тест в JUnit. Я начал дописывать функционал: Код | package questions;
import java.util.Iterator;
/** * SimpleList implements some methods of List interface * * * */ public class SimpleArrayList { //array to store elements of the list Object[] data;
/** * Specified by: the same method of java.util.List * @param index * @return */ public Object get(int index){ //todo: implement
return data[index];
}
/** * Specified by: the same method of java.util.List * @param index * @param obj */ public Object set(int index, Object obj){ //todo: implement
Object i=data[index]; data[index]=obj; return i;
}
/** * Specified by: the same method of java.util.List * @param index * @param element */ public void add(int index, Object element){ //todo: implement
data[index]=element;
}
/** * Specified by: the same method of java.util.List * @return */ public Iterator iterator(){ return new Iterator(){ //todo: implement }; }
/** * Specified by: the same method of java.util.List * @return */ public int hashCode(){ //todo: implement }
/** * Specified by: the same method of java.util.List * @return */ public boolean equals(Object obj) { //todo: impelment
if (data==obj) return true else return false;
}
/** * Specified by: the same method of java.util.List * @return */ public int indexOf(Object o){ ////todo: impelment
for(int i=0;i<data.length();i++) if ( data[i]==o ) { return i; } return -1; } }
|
и столкнулся с проблемой Итератора и хешКода - что туда дописать я не знаю...собственно хотелось бы узнать, а так же хотелось бы узнать, все ли я правильно делаю?)
|