EDIT: I believe the problem is in adding nodes. When I start the fetch the nodes they come back null. I believe it is because head is not get setting as the impl.getHeadNode() == null never occurs.
Constructor:
public CashDonationLinkedListImpl() {
iterNode = headNode = new CashDonationNode(null);
}
Add Method:
public void add(Object obj) {
CashDonation cashDonation = (CashDonation)obj;
CashDonationLinkedListImpl impl = new CashDonationLinkedListImpl();
CashDonationNode node = new CashDonationNode();
node.setCashDonation(cashDonation);
//node.setNext(null);
if(impl.getHeadNode() == null){
System.out.println("Head node");
impl.setHeadNode(node);
}
else{
//node.setCashDonation(cashDonation);
//node.setNext(null);
for (CashDonationNode cashNode = headNode;cashNode.getNext() != null;cashNode = cashNode.getNext()) {
// currNode.setNext(null);
}
//cashNode.setCashDonation(cashDonation);
cashNode.setNext(node);
}
Original: The getter returns two zeros while the setter takes in 100, 100, and 10000. I'm sure I'm forgetting to do something but can't put my finger on it. Why isn't the getter returning the values from the setter?
public class CashDonationNode {
CashDonation cashDonation;
CashDonationNode next;
public CashDonationNode() {
cashDonation = new CashDonation();
next = null;
}
public CashDonationNode(CashDonation cashDonation, CashDonationNode next) {
this.cashDonation = cashDonation;
this.next = next;
}
public CashDonationNode getNext(){
return next;
}
public void setNext(CashDonationNode nextValue){
this.next = nextValue;
}
public void setCashDonation(CashDonation cashDonation){
this.cashDonation = cashDonation;
System.out.print("node storage");
System.out.println(this.cashDonation.getDonationAmount());
}
public CashDonation getCashDonation(){
System.out.println("node retrieval " + cashDonation.getDonationAmount());
return this.cashDonation;
}
}
Snippets from the Linked List below. Returns the same zeros:
CashDonationNode iterNode = new CashDonationNode(); //declared in class
public void iterator() {
iterNode = headNode;
}
@Override
public CashDonation next() {
CashDonation cashDonation = iterNode.getCashDonation();
System.out.println("Impl: " + cashDonation.getDonationAmount());
iterNode = iterNode.getNext();
return cashDonation;
}