Defend
8 years ago
7 changed files with 178 additions and 33 deletions
@ -0,0 +1,93 @@ |
|||
package ru.defend.defdevteam.tstu; |
|||
|
|||
import java.util.ArrayList; |
|||
import java.util.Iterator; |
|||
import java.util.ListIterator; |
|||
import java.util.NoSuchElementException; |
|||
|
|||
/** |
|||
* Created by itsmy on 13.02.2017. |
|||
*/ |
|||
|
|||
public class NewsItemList implements Iterable<NewsItemList.Group> { |
|||
|
|||
private ArrayList<Group> list; |
|||
|
|||
NewsItemList() { |
|||
list = new ArrayList<>(); |
|||
} |
|||
|
|||
public int size() { |
|||
return list.size(); |
|||
} |
|||
|
|||
public Group get(int index) { |
|||
return list.get(index); |
|||
} |
|||
|
|||
public void add(Group group) { |
|||
this.list.add(group); |
|||
} |
|||
|
|||
@Override |
|||
public Iterator<Group> iterator() { |
|||
return new NewsIterator(); |
|||
} |
|||
|
|||
private class NewsIterator implements Iterator<Group> { |
|||
private int cursor; |
|||
|
|||
public NewsIterator() { |
|||
this.cursor = 0; |
|||
} |
|||
|
|||
public boolean hasNext() { |
|||
return this.cursor < size(); |
|||
} |
|||
|
|||
public Group next() { |
|||
if(this.hasNext()) { |
|||
Group current = get(cursor); |
|||
cursor ++; |
|||
return current; |
|||
} |
|||
throw new NoSuchElementException(); |
|||
} |
|||
|
|||
public void remove() { |
|||
throw new UnsupportedOperationException(); |
|||
} |
|||
} |
|||
|
|||
public class Group { |
|||
private String title; |
|||
private String text; |
|||
private String link; |
|||
|
|||
Group() { |
|||
|
|||
} |
|||
|
|||
public void set(String title, String text, String link) { |
|||
this.title = title; |
|||
this.text = text; |
|||
this.link = link; |
|||
} |
|||
|
|||
public String getTitle() { |
|||
return this.title; |
|||
} |
|||
|
|||
public String getText() { |
|||
return this.text; |
|||
} |
|||
|
|||
public String getLink() { |
|||
return this.link; |
|||
} |
|||
|
|||
} |
|||
|
|||
|
|||
|
|||
} |
Loading…
Reference in new issue