You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
95 lines
1.9 KiB
95 lines
1.9 KiB
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(String title, String text, String link) {
|
|
this.title = title;
|
|
this.text = text;
|
|
this.link = link;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|