@Test public void organizeAlbumsHierarchy() throws Exception { Map<Integer, G2Album> albums = new HashMap<Integer, G2Album>(); G2Album album = new G2Album(); album.setName(6); album.setId(600); album.setParentName(20); albums.put(album.getId(), album); album = new G2Album(); album.setName(3); album.setId(300); album.setParentName(10); albums.put(album.getId(), album); album = new G2Album(); album.setName(4); album.setId(400); album.setParentName(10); albums.put(album.getId(), album); album = new G2Album(); album.setName(10); album.setId(100); album.setParentName(0); albums.put(album.getId(), album); album = new G2Album(); album.setName(5); album.setId(500); album.setParentName(20); albums.put(album.getId(), album); album = new G2Album(); album.setName(20); album.setId(200); album.setParentName(10); albums.put(album.getId(), album); Album finalAlbum = g2ConnectionUtils.organizeAlbumsHierarchy(albums); Collections.sort(finalAlbum.getSubAlbums(), new Comparator<Album>() { public int compare(final Album albumA, final Album albumB) { return Integer.valueOf(albumA.getName()).compareTo(Integer.valueOf(albumB.getName())); } }); assertEquals(10, finalAlbum.getName()); assertEquals(3, finalAlbum.getSubAlbums().get(0).getName()); assertEquals(4, finalAlbum.getSubAlbums().get(1).getName()); assertEquals(20, finalAlbum.getSubAlbums().get(2).getName()); assertEquals(5, finalAlbum.getSubAlbums().get(2).getSubAlbums().get(0).getName()); assertEquals(6, finalAlbum.getSubAlbums().get(2).getSubAlbums().get(1).getName()); }
public Album organizeAlbumsHierarchy(Map<Integer, G2Album> albums) { Album rootAlbum = null; Map<Integer, Album> albumss = new HashMap<Integer, Album>(); for (Integer key : albums.keySet()) { albumss.put(key, G2ConvertUtils.g2AlbumToAlbum(albums.get(key))); } for (Album album : albumss.values()) { if (album.getParentName() == 0) { rootAlbum = album; } int parentName = album.getParentName(); int parentId = 0; for (Album album2 : albumss.values()) { if (album2.getName() == parentName) { parentId = album2.getId(); break; } } Album parent = albumss.get(parentId); album.setParent(parent); if (parent != null) { parent.getSubAlbums().add(album); } } return rootAlbum; }
G2Client { public Album organizeAlbumsHierarchy(Map<Integer, G2Album> albums) { Album rootAlbum = null; Map<Integer, Album> albumss = new HashMap<Integer, Album>(); for (Integer key : albums.keySet()) { albumss.put(key, G2ConvertUtils.g2AlbumToAlbum(albums.get(key))); } for (Album album : albumss.values()) { if (album.getParentName() == 0) { rootAlbum = album; } int parentName = album.getParentName(); int parentId = 0; for (Album album2 : albumss.values()) { if (album2.getName() == parentName) { parentId = album2.getId(); break; } } Album parent = albumss.get(parentId); album.setParent(parent); if (parent != null) { parent.getSubAlbums().add(album); } } return rootAlbum; } }
G2Client { public Album organizeAlbumsHierarchy(Map<Integer, G2Album> albums) { Album rootAlbum = null; Map<Integer, Album> albumss = new HashMap<Integer, Album>(); for (Integer key : albums.keySet()) { albumss.put(key, G2ConvertUtils.g2AlbumToAlbum(albums.get(key))); } for (Album album : albumss.values()) { if (album.getParentName() == 0) { rootAlbum = album; } int parentName = album.getParentName(); int parentId = 0; for (Album album2 : albumss.values()) { if (album2.getName() == parentName) { parentId = album2.getId(); break; } } Album parent = albumss.get(parentId); album.setParent(parent); if (parent != null) { parent.getSubAlbums().add(album); } } return rootAlbum; } G2Client(String userAgent); }
G2Client { public Album organizeAlbumsHierarchy(Map<Integer, G2Album> albums) { Album rootAlbum = null; Map<Integer, Album> albumss = new HashMap<Integer, Album>(); for (Integer key : albums.keySet()) { albumss.put(key, G2ConvertUtils.g2AlbumToAlbum(albums.get(key))); } for (Album album : albumss.values()) { if (album.getParentName() == 0) { rootAlbum = album; } int parentName = album.getParentName(); int parentId = 0; for (Album album2 : albumss.values()) { if (album2.getName() == parentName) { parentId = album2.getId(); break; } } Album parent = albumss.get(parentId); album.setParent(parent); if (parent != null) { parent.getSubAlbums().add(album); } } return rootAlbum; } G2Client(String userAgent); HashMap<String, String> fetchImages(String galleryUrl, int albumName); HashMap<String, String> fetchAlbums(String galleryUrl); void loginToGallery(String galleryUrl, String user, String password); InputStream getInputStreamFromUrl(String url); int createNewAlbum(String galleryUrl, int parentAlbumName,
			String albumName, String albumTitle, String albumDescription); int sendImageToGallery(String galleryUrl, int albumName,
			File imageFile, String imageName, String summary, String description); String getAuthToken(); void setAuthToken(String authToken); List<Cookie> getSessionCookies(); Collection<G2Picture> extractG2PicturesFromProperties(
			HashMap<String, String> fetchImages); Map<Integer, Album> getAllAlbums(String galleryUrl); Map<Integer, G2Album> extractAlbumFromProperties(
			HashMap<String, String> albumsProperties); Album organizeAlbumsHierarchy(Map<Integer, G2Album> albums); void setRootAlbum(G2Album rootAlbum); G2Album getRootAlbum(); }
G2Client { public Album organizeAlbumsHierarchy(Map<Integer, G2Album> albums) { Album rootAlbum = null; Map<Integer, Album> albumss = new HashMap<Integer, Album>(); for (Integer key : albums.keySet()) { albumss.put(key, G2ConvertUtils.g2AlbumToAlbum(albums.get(key))); } for (Album album : albumss.values()) { if (album.getParentName() == 0) { rootAlbum = album; } int parentName = album.getParentName(); int parentId = 0; for (Album album2 : albumss.values()) { if (album2.getName() == parentName) { parentId = album2.getId(); break; } } Album parent = albumss.get(parentId); album.setParent(parent); if (parent != null) { parent.getSubAlbums().add(album); } } return rootAlbum; } G2Client(String userAgent); HashMap<String, String> fetchImages(String galleryUrl, int albumName); HashMap<String, String> fetchAlbums(String galleryUrl); void loginToGallery(String galleryUrl, String user, String password); InputStream getInputStreamFromUrl(String url); int createNewAlbum(String galleryUrl, int parentAlbumName,
			String albumName, String albumTitle, String albumDescription); int sendImageToGallery(String galleryUrl, int albumName,
			File imageFile, String imageName, String summary, String description); String getAuthToken(); void setAuthToken(String authToken); List<Cookie> getSessionCookies(); Collection<G2Picture> extractG2PicturesFromProperties(
			HashMap<String, String> fetchImages); Map<Integer, Album> getAllAlbums(String galleryUrl); Map<Integer, G2Album> extractAlbumFromProperties(
			HashMap<String, String> albumsProperties); Album organizeAlbumsHierarchy(Map<Integer, G2Album> albums); void setRootAlbum(G2Album rootAlbum); G2Album getRootAlbum();  }