Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static final class ArrayListWithInterfaceDemo {
- public interface FileExplorerElement {
- ArrayList<FileExplorerElement> subElements = new ArrayList<>();
- String getExt();
- void add(FileExplorerElement subElement);
- }
- public static class FileMP3 implements FileExplorerElement {
- @Override
- public String getExt() {
- return ".mp3";
- }
- @Override
- public void add(FileExplorerElement subElement) {
- }
- }
- public static class FileJPEG implements FileExplorerElement {
- @Override
- public String getExt() {
- return ".zip";
- }
- @Override
- public void add(FileExplorerElement subElement) {
- }
- }
- public static class FolderMedia implements FileExplorerElement {
- @Override
- public String getExt() {
- return ".zip";
- }
- @Override
- public void add(FileExplorerElement subElement) {
- subElements.add(subElement);
- }
- }
- public static class FolderDCIM implements FileExplorerElement {
- @Override
- public String getExt() {
- return "";
- }
- @Override
- public void add(FileExplorerElement subElement) {
- subElements.add(subElement);
- }
- }
- public static class FileZip {
- public String getExt() {
- return ".zip";
- }
- public void addElement(FileExplorerElement subElement) {
- }
- }
- public static class FolderDownload {
- ArrayList<FileExplorerElement> subElements = new ArrayList<>();
- public String getExt() {
- return "";
- }
- public void addElement(FileExplorerElement subElement) {
- subElements.add(subElement);
- }
- }
- public ArrayListWithInterfaceDemo() {
- testMyCode();
- }
- public void testMyCode() {
- FolderDCIM dirDCIM = new FolderDCIM();
- dirDCIM.add(new FileJPEG());
- FolderMedia dirMedia = new FolderMedia();
- dirMedia.add(new FileMP3());
- dirMedia.add(new FileJPEG());
- FolderDCIM dirDownload = new FolderDownload();
- dirDownload.add(new FileMP3());
- dirDownload.add(new FileJPEG());
- dirDownload.add(new FileZip());
- ArrayList<FileExplorerElement> mainDirectory = new ArrayList<>();
- mainDirectory.add(new FolderDCIM());
- mainDirectory.add(new FolderMedia());
- mainDirectory.add(new FolderDownload());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement