Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package by.epam.dzianis.dao;
- import java.util.List;
- import java.util.concurrent.CopyOnWriteArrayList;
- import org.springframework.stereotype.Repository;
- import by.epam.dzianis.data.MyImage;
- @Repository(value = "dao")
- public class Dao implements IDao {
- private static final long serialVersionUID = 1L;
- // private static List<MyImage> imList = Collections.synchronizedList(new ArrayList<MyImage>());
- private static List<MyImage> imList = new CopyOnWriteArrayList<MyImage>();
- private MyImage myImage = new MyImage();
- /**
- *
- */
- public Dao() {
- super();
- }
- /**
- *
- */
- public Dao(List<MyImage> imList, MyImage myImage) {
- this.imList = imList;
- this.myImage = myImage;
- }
- /**
- *
- */
- public void create(MyImage image) {
- imList.add(image);
- setId();
- }
- /**
- *
- */
- public MyImage read(int id) {
- return imList.get(id);
- }
- /**
- *
- */
- public List<MyImage> read() {
- return imList;
- }
- /**
- *
- */
- public void update(MyImage image) {
- int id = (image.getId());
- imList.set(id, image);
- }
- /**
- *
- */
- public void delete(int id) {
- imList.remove(id);
- setId();
- }
- /**
- *
- */
- public void delete() {
- imList.clear();
- }
- /**
- * инкрементация Id
- */
- private void setId() {
- for (int i = 0; i < imList.size(); i++) {
- myImage = imList.get(i);
- myImage.setId(i);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement