}
}
+ @Override
+ public void moveUp(Album album) {
+ lock.writeLock().lock();
+ try {
+ List<String> albums = albumChildren.get(album.getParent().getId());
+ int currentIndex = albums.indexOf(album.getId());
+ if (currentIndex == 0) {
+ return;
+ }
+ albums.remove(album.getId());
+ albums.add(currentIndex - 1, album.getId());
+ } finally {
+ lock.writeLock().unlock();
+ }
+ }
+
+ @Override
+ public void moveDown(Album album) {
+ lock.writeLock().lock();
+ try {
+ List<String> albums = albumChildren.get(album.getParent().getId());
+ int currentIndex = albums.indexOf(album.getId());
+ if (currentIndex == (albums.size() - 1)) {
+ return;
+ }
+ albums.remove(album.getId());
+ albums.add(currentIndex + 1, album.getId());
+ } finally {
+ lock.writeLock().unlock();
+ }
+ }
+
//
// ALBUMSTORE METHODS
//
}
}
+ @Override
+ public List<Image> getImages(Album parent) {
+ lock.readLock().lock();
+ try {
+ return from(albumImages.get(parent.getId())).transformAndConcat(getImage()).toList();
+ } finally {
+ lock.readLock().unlock();
+ }
+ }
+
+ @Override
+ public void moveUp(Image image) {
+ lock.writeLock().lock();
+ try {
+ List<String> images = albumImages.get(image.getAlbum().getId());
+ int currentIndex = images.indexOf(image.getId());
+ if (currentIndex == 0) {
+ return;
+ }
+ images.remove(image.getId());
+ images.add(currentIndex - 1, image.getId());
+ } finally {
+ lock.writeLock().unlock();
+ }
+ }
+
+ @Override
+ public void moveDown(Image image) {
+ lock.writeLock().lock();
+ try {
+ List<String> images = albumChildren.get(image.getAlbum().getId());
+ int currentIndex = images.indexOf(image.getId());
+ if (currentIndex == (images.size() - 1)) {
+ return;
+ }
+ images.remove(image.getId());
+ images.add(currentIndex + 1, image.getId());
+ } finally {
+ lock.writeLock().unlock();
+ }
+ }
+
//
// IMAGESTORE METHODS
//
}
}
- void moveUp(Album album) {
- lock.writeLock().lock();
- try {
- List<String> albums = albumChildren.get(album.getParent().getId());
- int currentIndex = albums.indexOf(album.getId());
- if (currentIndex == 0) {
- return;
- }
- albums.remove(album.getId());
- albums.add(currentIndex - 1, album.getId());
- } finally {
- lock.writeLock().unlock();
- }
- }
-
- void moveDown(Album album) {
- lock.writeLock().lock();
- try {
- List<String> albums = albumChildren.get(album.getParent().getId());
- int currentIndex = albums.indexOf(album.getId());
- if (currentIndex == (albums.size() - 1)) {
- return;
- }
- albums.remove(album.getId());
- albums.add(currentIndex + 1, album.getId());
- } finally {
- lock.writeLock().unlock();
- }
- }
-
- void moveUp(Image image) {
- lock.writeLock().lock();
- try {
- List<String> images = albumImages.get(image.getAlbum().getId());
- int currentIndex = images.indexOf(image.getId());
- if (currentIndex == 0) {
- return;
- }
- images.remove(image.getId());
- images.add(currentIndex - 1, image.getId());
- } finally {
- lock.writeLock().unlock();
- }
- }
-
- void moveDown(Image image) {
- lock.writeLock().lock();
- try {
- List<String> images = albumChildren.get(image.getAlbum().getId());
- int currentIndex = images.indexOf(image.getId());
- if (currentIndex == (images.size() - 1)) {
- return;
- }
- images.remove(image.getId());
- images.add(currentIndex + 1, image.getId());
- } finally {
- lock.writeLock().unlock();
- }
- }
-
//
// PRIVATE METHODS
//
};
}
+ private Function<String, Iterable<Image>> getImage() {
+ return new Function<String, Iterable<Image>>() {
+ @Override
+ public Iterable<Image> apply(String input) {
+ return (input == null) ? Collections.<Image>emptyList() : getImage(input).asSet();
+ }
+ };
+ }
+
}