|
|
|
@ -9,16 +9,49 @@ package ru.molokoin;
@@ -9,16 +9,49 @@ package ru.molokoin;
|
|
|
|
|
*/ |
|
|
|
|
public class Pearl { |
|
|
|
|
private Object gem; |
|
|
|
|
private Pearl next = null; |
|
|
|
|
private Pearl next; |
|
|
|
|
|
|
|
|
|
public Pearl(){ |
|
|
|
|
this(null, null); |
|
|
|
|
} |
|
|
|
|
public Pearl(Object gem){ |
|
|
|
|
this(gem, null); |
|
|
|
|
} |
|
|
|
|
public Pearl(Object gem, Pearl next){ |
|
|
|
|
setGem(gem); |
|
|
|
|
setNext(next); |
|
|
|
|
} |
|
|
|
|
/** |
|
|
|
|
* Рекурсивно печатает данные, пока не упрется в next = null |
|
|
|
|
*/ |
|
|
|
|
public void print(){ |
|
|
|
|
System.out.println((int)gem); |
|
|
|
|
System.out.println(gem); |
|
|
|
|
if (next != null){ |
|
|
|
|
getNext().print(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
/** |
|
|
|
|
* перебирает жемчужины до конца, последней присваивет в next новую жемчужину |
|
|
|
|
* @param gem |
|
|
|
|
*/ |
|
|
|
|
public void add(Object gem){ |
|
|
|
|
next.setGem(gem); |
|
|
|
|
if(this.gem == null){setGem(gem);} |
|
|
|
|
else { |
|
|
|
|
Pearl pearl = new Pearl(gem); |
|
|
|
|
Pearl current = this; |
|
|
|
|
while (current.next != null){ |
|
|
|
|
current = current.next; |
|
|
|
|
} |
|
|
|
|
current.next = pearl; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public Pearl getLast(){ |
|
|
|
|
Pearl current = this; |
|
|
|
|
while (current.next != null){ |
|
|
|
|
current = current.next; |
|
|
|
|
} |
|
|
|
|
return current; |
|
|
|
|
} |
|
|
|
|
/** |
|
|
|
|
* @param gem the gem to set |
|
|
|
|