Advertisement
jasperlow

ArrayListWithInterfaceDemo

Aug 28th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.88 KB | None | 0 0
  1.  
  2.  
  3.     public static final class ArrayListWithInterfaceDemo {
  4.  
  5.         public interface FileExplorerElement {
  6.  
  7.             ArrayList<FileExplorerElement> subElements = new ArrayList<>();
  8.  
  9.             String getExt();
  10.  
  11.             void add(FileExplorerElement subElement);
  12.         }
  13.  
  14.         public static class FileMP3 implements FileExplorerElement {
  15.             @Override
  16.             public String getExt() {
  17.                 return ".mp3";
  18.             }
  19.  
  20.             @Override
  21.             public void add(FileExplorerElement subElement) {
  22.             }
  23.         }
  24.  
  25.         public static class FileJPEG implements FileExplorerElement {
  26.             @Override
  27.             public String getExt() {
  28.                 return ".zip";
  29.             }
  30.  
  31.             @Override
  32.             public void add(FileExplorerElement subElement) {
  33.             }
  34.         }
  35.  
  36.         public static class FolderMedia implements FileExplorerElement {
  37.             @Override
  38.             public String getExt() {
  39.                 return ".zip";
  40.             }
  41.  
  42.             @Override
  43.             public void add(FileExplorerElement subElement) {
  44.                 subElements.add(subElement);
  45.             }
  46.         }
  47.  
  48.         public static class FolderDCIM implements FileExplorerElement {
  49.             @Override
  50.             public String getExt() {
  51.                 return "";
  52.             }
  53.  
  54.             @Override
  55.             public void add(FileExplorerElement subElement) {
  56.                 subElements.add(subElement);
  57.             }
  58.         }
  59.  
  60.         public static class FileZip {
  61.             public String getExt() {
  62.                 return ".zip";
  63.             }
  64.  
  65.             public void addElement(FileExplorerElement subElement) {
  66.             }
  67.         }
  68.  
  69.  
  70.         public static class FolderDownload {
  71.  
  72.             ArrayList<FileExplorerElement> subElements = new ArrayList<>();
  73.  
  74.             public String getExt() {
  75.                 return "";
  76.             }
  77.  
  78.             public void addElement(FileExplorerElement subElement) {
  79.                 subElements.add(subElement);
  80.             }
  81.         }
  82.  
  83.         public ArrayListWithInterfaceDemo() {
  84.             testMyCode();
  85.         }
  86.  
  87.         public void testMyCode() {
  88.             FolderDCIM dirDCIM = new FolderDCIM();
  89.             dirDCIM.add(new FileJPEG());
  90.             FolderMedia dirMedia = new FolderMedia();
  91.             dirMedia.add(new FileMP3());
  92.             dirMedia.add(new FileJPEG());
  93.             FolderDCIM dirDownload = new FolderDownload();
  94.             dirDownload.add(new FileMP3());
  95.             dirDownload.add(new FileJPEG());
  96.             dirDownload.add(new FileZip());
  97.             ArrayList<FileExplorerElement> mainDirectory = new ArrayList<>();
  98.             mainDirectory.add(new FolderDCIM());
  99.             mainDirectory.add(new FolderMedia());
  100.             mainDirectory.add(new FolderDownload());
  101.         }
  102.  
  103.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement